带空格的ffmpeg目录和'

时间:2018-03-21 04:39:47

标签: batch-file ffmpeg

我想使用FFMEG合并目录E:\ Videos \ Ryan' s视频\ 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

似乎正在绊倒'在从文本文件中读取目录时,我尝试使用" "而不是' '但它并没有解决问题。

1 个答案:

答案 0 :(得分: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
相关问题