Ubuntu FFMPEG动态映像文件名

时间:2018-07-31 16:30:10

标签: linux ffmpeg

我目前有一个目录,里面充满了各种mp4文件,而且我现在能够每隔五秒钟循环浏览整个目录和屏幕截图。当前,该命令以“ 00000001.png”开始命名,并在下一个屏幕截图处递增,但是我希望它使用文件名以及附加的数字。我试图重用“ $ file”变量,但是从运行循环中得到了一个奇怪的错误。

命令:

for file in /datadrive/video_repo/ffmpeg_tmp/*.mp4; do /usr/bin/ffmpeg -i "$file" -r 0.5 /datadrive/image_repo/"${file%.}".%8d.png; done

但是在运行时出现以下错误:

Could not open file : /datadrive/image_repo//datadrive/video_repo/ffmpeg_tmp/testvideo00000001.png
av_interleaved_write_frame(): Input/output error

由于某种原因,输出位置似乎与输入混淆了。但是,如果我删除"${file%.}",它将运行正常。 (我之所以使用“ $ {file%。}”,是因为它使用了文件名,并省略了扩展名。)

任何对此的帮助将非常感激。

1 个答案:

答案 0 :(得分:2)

此处: / datadrive / image_repo / /datadrive/video_repo/ffmpeg_tmp/testvideo00000001.png

您使用的是TWICE路径,因此他找到了该路径并在此处再次添加: / datadrive / image_repo /“ $ {file%。}”。%8d.png 但您的$ { file%。}已经 / datadrive / image_repo /

for file in /datadrive/video_repo/ffmpeg_tmp/*.mp4; 
    do /usr/bin/ffmpeg -i "$file" -r 0.5 "${file%.}".%8d.png; 
done