Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transcode and generate thumbnails with ffmpeg

Tags:

ffmpeg

Using ffmpeg, and assuming it's doable, how can I transform input video from one format to another (e.g. MPEG-2 to MPEG-4) and generate thumbnails every n seconds at the same time?

Regards, Matt

like image 583
Matt Avatar asked Mar 15 '26 01:03

Matt


1 Answers

This command will take in.flv and transcode to .webm and .mp4 while simultaneously generating a single thumbnail.

ffmpeg -y -threads '1' -i 'in.flv' \
  -map '0:v' -map '0:a' -c:v 'libx264' -c:a 'libvo_aacenc' out.mp4 \
  -map '0:v' -map '0:a' -c:v 'libvpx' -c:a 'libvorbis' out.webm \
  -map '0:v' -r '1' -t '1' 'out.png'

To generate a thumbnail every n seconds, change -r (the frame-rate) to the inverse of n and remove -t (so that thumbnails are taken until the end of the video). For example, to generate a thumbnail every 4 seconds, you want a framerate of 1/4.

ffmpeg -y -threads '1' -i 'in.flv' \
  -map '0:v' -map '0:a' -c:v 'libx264' -c:a 'libvo_aacenc' out.mp4 \
  -map '0:v' -map '0:a' -c:v 'libvpx' -c:a 'libvorbis' out.webm \
  -map '0:v' -r '1/4' 'out-%d.png'
like image 52
d2vid Avatar answered Mar 16 '26 13:03

d2vid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!