ffmpeg - Tipps and Tricks

Main Documentation Site

  • -framerate 30 Set framerate for image import
  • -r[:stream_specifier] fps (*input/output,per-stream*) Set resample framerate (Hz value, fraction or abbreviation).
  • -s[:stream_specifier] size (*input/output,per-stream*) Set frame size. The format is ‘wxh’ (default - same as source).
  • -f format (*input/output*) Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases. Format Docs

  • -vn (*input/output*) As an input option, blocks all video streams of a file from being filtered or being automatically selected or mapped for any output.

Image Sequence

You need the Image2 demuxer, the format for images.

This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

from here

APNG

Animated PNGs are created via

ffmpeg -i input.mp4 -f apng output.png

Check output options with

ffmpeg -h muxer=apng

APNG muxer AVOptions:

  • plays (int): Number of times to play the output: 0 - infinite loop, 1 - no loop (from 0 to 65535) (default 1)
  • final_delay (rational): Force delay after the last frame (from 0 to 65535) (default 0/1)

Fetch frame count with ffmpeg

ffprobe -v error -select_streams v:0 -count_packets \
    -show_entries stream=nb_read_packets -of csv=p=0 input.mp4

from here

Write timecode onto video

ffmpeg -i input -vf "drawtext=fontfile=Arial.ttf: text='%{frame_num}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=black: fontsize=20: box=1: boxcolor=white: boxborderw=5" -c:a copy output

from here

Glossary

  • tbn = the time base in AVStream that has come from the container
  • tbc = the time base in AVCodecContext for the codec used for a particular stream
  • tbr = tbr is guessed from the video stream and is the value users want to see when they look for the video frame rate