通过ffmpeg命令将文件的扩展名转换为其他目录 [英] To convert the extension of a file to the different directory by a ffmpeg command
问题描述
下面的命令是将mp4文件转换为在同一目录.../httpdocs/save/中具有相同文件名的jpg文件.
The command below is to convert from mp4 file to jpg file with the same file name in the same directory, .../httpdocs/save/.
[root@server-xxxxx-x ~]# for i in `find /var/www/vhosts/xxxxxx.com/httpdocs/save/ -type f -name "*.mp4"`; do ffmpeg -i $i `echo $i | sed -En "s/.mp4$/.jpg/p"`; done
现在,我需要从.../httpdocs/save/转换到其他目录.../httpdocs/file/,如何更改上面的命令?如果有人可以帮助我,我将不胜感激.
ffmpeg版本2.2.2
Now, I need to convert from, .../httpdocs/save/ to the different directory, .../httpdocs/file/, how should I change the command above? I'd appreciate if anyone could help me out.
ffmpeg version 2.2.2
推荐答案
简单方法是从包含输入文件的目录中执行命令:
Simple method is to execute the command from the directory containing the input files:
cd "/path/to/inputs" && for i in *.mp4; do ffmpeg -i "$i" -frames:v 1 "/path/to/outputs/${i%.*}.jpg"; done
或者,如果要将完整路径放在 for循环中,则可以使用 basename
:
Or you could use basename
if you want to put the full path in the for loop:
for i in /path/to/inputs/*.mp4; do ffmpeg -i "$i" -frames:v 1 "/path/to/outputs/$(basename "$i" .mp4).jpg"; done
...但是它的效率不如仅使用参数扩展:
...but it is less efficient than only using parameter expansion:
for i in /path/to/inputs/*.mp4; do filepath="${i##*/}"; ffmpeg -i "$i" -frames:v 1 "/path/to/outputs/${filepath%.*}.jpg"; done
其他相关问题:
这篇关于通过ffmpeg命令将文件的扩展名转换为其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!