How to include input file name in output file name in ffmpeg

8,485

$filename is handled as a shell variable.

What about

ffmpeg -i clip.mp4 fr1/clip_%d.jpg -hide_banner

or

$mp4filename=clip
ffmpeg -i ${mp4filename}.mp4 fr1/${mp4filename}_%d.jpg -hide_banner

?

Update: For use with gnu parallel, you can use parallel's -i option:

-i
Normally the command is passed the argument at the end of its command line. With this option, any instances of "{}" in the command are replaced with the argument.

The resulting command line could be as simple as

parallel -i ffmpeg -i {} fr1/{}_%d.jpg -hide_banner -- *.mp4

if you can live with the extension in the output files.

Be aware that you may not actually want to run this in parallel on a traditional hard-disk as the concurrent i/o will slow it down.

Edit: Fixed variable reference as pointed out by @DonHolgo.

Share:
8,485

Related videos on Youtube

mark
Author by

mark

Updated on September 18, 2022

Comments

  • mark
    mark almost 2 years

    I want to extract frames as images from video and I want each image to be named as InputFileName_number.bmp.  How can I do this?

    I tried the following command:

    ffmpeg -i clip.mp4 fr1/$filename%d.jpg -hide_banner
    

    but it is not working as I want.  I want to get, for example, clip_1.bmp, but what I get is 1.bmp.

    I am trying to use it with GNU parallel to extract images of multiple videos and I am new to both so I want some king of dynamic file naming input -> input_number.bmp.

  • mark
    mark about 5 years
    I am trying to use it with gnu parallel to extract images of multiple videos and I am new to both so I want some king of dynamic file naming inpu -> input_number.bmp
  • DonHolgo
    DonHolgo about 5 years
    That should be fr1/${mp4filename}_%d.jpg in the second example so that the underscore is not considered part of the variable name.
  • Hermann
    Hermann about 5 years
    @mark I extended my answer. In the future, please mention the full details in your question right from the beginning.