ffmpeg concat:"不安全的文件名"

ser*_*ers 63 concat ffmpeg

试图将一堆mts文件转换为一个大的mp4文件:

stephan@rechenmonster:/mnt/backupsystem/archive2/Videos/20151222/PRIVATE/AVCHD/BDMV$ ~/bin/ffmpeg-git-20160817-64bit-static/ffmpeg -v info -f concat -i <(find STREAM -name '*' -printf "file '$PWD/%p'\n") -deinterlace -r 25 -s hd720 -c:v libx264 -crf 23 -acodec copy -strict -2 ~/tmp/Videos/20151222.mp4
ffmpeg version N-81364-gf85842b-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.1 (Debian 5.4.1-1) 20160803
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr --enable-frei0r --enable-libfribidi --disable-indev=sndio --disable-outdev=sndio --enable-librtmp --enable-libmfx --enable-libzimg --cc=gcc-5
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 53.100 / 57. 53.100
  libavformat    57. 46.101 / 57. 46.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 51.100 /  6. 51.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[concat @ 0x56054a0] Unsafe file name '/mnt/backupsystem/archive2/Videos/20151222/PRIVATE/AVCHD/BDMV/STREAM'
/dev/fd/63: Operation not permitted
Run Code Online (Sandbox Code Playgroud)

任何想法在这里出了什么问题?在这种情况下,术语"不安全文件"是什么意思?

谢谢,斯蒂芬

ser*_*ers 58

@Mulvya所说的答案(谢谢!)有效:" -safe 0之前添加-i".然后出现另一个问题,find STREAM -name '*' -printf "file '$PWD/%p'\n"其返回空路径作为第一个条目.改为此for f in ./*.wav; do echo "file '$PWD/$f'"; done(请参阅https://trac.ffmpeg.org/wiki/Concatenate),现在它似乎有效.欢呼!

  • 您还可以将 `find` 子命令更改为 `find STREAM -type f -name '*' -printf "file '$PWD/%p'\n"` (并且不要忘记添加 `-safe 0`到 ffmpeg 命令)。 (2认同)

林果皞*_*林果皞 20

就我而言,双引号会导致错误。

我使用ffmpeg -f concat -i concat.txt -c copy output.m4a命令,其中concat.txt包含要连接的输入文件列表。

不安全的文件名(双引号视为文件名的一部分,-safe 0无法修复):

file "song1.m4a"
file "song2.m4a"
Run Code Online (Sandbox Code Playgroud)

安全文件名(单引号):

file 'song1.m4a'
file 'song2.m4a'
Run Code Online (Sandbox Code Playgroud)

安全文件名(不带引号):

file song1.m4a
file song2.m4a
Run Code Online (Sandbox Code Playgroud)

上面的单引号不带引号的只有在它只包含"字母、数字、句点(前缀除外)、下划线和连字符"时才安全。因此以下通用文件名将不起作用:

  • 空间
  • 字形
  • / (小路)
  • 前缀句点(隐藏文件)

你仍然需要-safe 0那些情况。

[关于引用和转义的注意事项]

您总是需要'在 filename 部分进行转义。原因是因为file Im' .avi将自动添加结束引号到Im' .avi',这与file Im' .avi'. 中的最后一个奇数引号file Im' .avi''''''也将添加结束引号成为file Im' .avi''''''',因此它没有No such file or directory错误。我弄清楚了这种现象,因为空间不再需要\用单引号后前缀转义,而不必添加结束引号。

尽管以上(必须逃避'\与无法逃脱"),逃避风格类似于shell。如果文件名包含单引号,您可以使用I\'m\ .m4a(NOT 用单引号括起来)样式或'I'\''m .m4a'OR 'I'\''m'\ '.m4a'(用单引号括起来)样式对其进行转义,但既不是 of'I\'m\ .m4a'也不是'I'm .m4a'.

当您测试 ffmpeg 时,请注意第一行错误消息Impossible to open可能会产生误导(文件确实存在),您需要检查第二行No such file or directory(文件不存在)或Invalid data found when processing input(无效媒体文件)。

  • 在每个文件名前面添加 **file** 解决了使用文本文件中的文件时的问题。 (2认同)

qwr*_*qwr 10

要回答原因,请从https://ffmpeg.org/ffmpeg-all.html#Options-35进行

此解复用器接受以下选项:

safe如果设置为1,则拒绝不安全的文件路径。如果文件路径不包含协议规范并且是相对的,并且所有组件仅包含来自可移植字符集的字符(字母,数字,句点,下划线和连字符),并且在组件的开头没有句点,则认为该文件路径是安全的。

如果设置为0,则接受任何文件名。

预设值为1。

如果自动探测格式,-1等于1,否则等于0。

原来,在文件的前面find .放了一个./。请参见如何在Unix“ find”中去除前导“ ./”?如果您不想使用解决方案-safe 0


Man*_*tel 6

关于答案是完全正确的,我只是向您显示命令,所以您不要在其他任何地方放置-safe 0。

ffmpeg.exe -f concat -safe 0 -i "clips.txt" -c copy "video.mp4"
Run Code Online (Sandbox Code Playgroud)