【问题标题】:ffmpeg directory with spaces and '带有空格和'的ffmpeg目录
【发布时间】:2018-03-21 04:39:46
【问题描述】:

我想使用 FFMEG 合并目录 E:\Videos\Ryan's Videos\1.mp4 和 2.mp4 中的两个视频文件 我的批处理脚本是:

(for %%i in (%*) do @echo file '%%~i') > mylist.txt
C:\ffmpeg\bin\ffmpeg.exe -f concat -safe 0 -i "%cd%\mylist.txt" -c copy "%cd%\output.mp4"
pause

这会产生 mylist.txt:

file 'E:\Videos\Ryan's Videos\2.mp4'
file 'E:\Videos\Ryan's Videos\1.mp4'

它试图读取但返回错误

[concat @ 00000000026224a0] Impossible to open 'E:\Videos\Ryans'
E:\Videos\Ryan's Videos\mylist.txt: No such file or directory

从文本文件中读取时,目录中的 ' 似乎被绊倒了,我尝试使用 " " 而不是 ' ' 包含路径,但它不能解决问题。

【问题讨论】:

  • 如果我是你,我会重命名文件夹名称以避免特殊字符和空格。
  • 撇号'cmd 没有什么特别之处,因此这个字符不会引起任何问题。空格构成标记分隔符,因此在文件路径/名称周围加上双引号 "

标签: batch-file ffmpeg


【解决方案1】:

哇——ffmpeg 有unusual quote/escape rules

我不确定如何解释规则,但我认为一种选择是放弃引号,然后您需要将 \ 转义为 \\' 转义为 \'

file E:\\Videos\\Ryan\'s Videos\\2.mp4

下面的批处理脚本应该会给你这个结果

@echo off
setlocal disableDelayedExpansion
>mylist.txt (
  for %%F in (%*) do (
    set "file=%%~F"
    setlocal enableDelayedExpansion
    set "file=!file:\=\\!"
    set "file=!file:'='\!"
    echo file !file!
    endlocal
  )
)
C:\ffmpeg\bin\ffmpeg.exe -f concat -safe 0 -i "%cd%\mylist.txt" -c copy "%cd%\output.mp4"
pause

我将file 变量设置为关闭延迟扩展,然后在循环中打开和关闭延迟扩展,以保护文件路径中可能存在的任何!

我保留了你的 ffmpeg 命令,但我很确定 ffmpeg 默认为当前目录,在这种情况下,该行可以简化为

C:\ffmpeg\bin\ffmpeg.exe -f concat -safe 0 -i mylist.txt -c copy output.mp4

我更有信心的另一个选择是保留外部引号,但是必须关闭引号,转义撇号,然后恢复引号,如下所示:

file 'E:\Videos\Ryan'\''s Videos\2.mp4'

以下批处理脚本应给出上述结果:

@echo off
setlocal disableDelayedExpansion
>mylist.txt (
  for %%F in (%*) do (
    set "file=%%~F"
    setlocal enableDelayedExpansion
    set "file=!file:'='\''!"
    echo file '!file!'
    endlocal
  )
)
C:\ffmpeg\bin\ffmpeg.exe -f concat -safe 0 -i "%cd%\mylist.txt" -c copy "%cd%\output.mp4"
pause

【讨论】:

  • 谢谢你,因为@Raptor 说我可以从路径中删除 ' 但是我没有从中学到任何东西。当在我的 PC 的不同目录中使用它时,这也使它更加通用。再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-04
  • 2021-08-03
  • 1970-01-01
  • 2015-06-18
  • 2019-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多