To convert the extension of a file to the different directory by a ffmpeg command

社会主义新天地 提交于 2019-12-24 22:41:24

问题


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


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


回答1:


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

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

Other relevant questions:

  • How do you convert an entire directory with ffmpeg?
  • Use ffmpeg to get middle frame of a video?
  • How can I extract a good quality JPEG image from an H264 video file with ffmpeg?


来源:https://stackoverflow.com/questions/49213477/to-convert-the-extension-of-a-file-to-the-different-directory-by-a-ffmpeg-comman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!