ffmpeg snippets @ r6

Contents hide

Extract single frame as image

bash
# extract image from a video at timestamp 1:16
# use -q:v <num> for jpeg quality control
ffmpeg -i video.mp4 -ss 01:16 -frames:v 1 image.jpeg

See this Super User answer for quality details, apparently the values of -qscale are between 1 and 31 for jpegs. PNG is lossless so won't be affected by quality. The v in q:v refers to the video stream. From the man page:

Use fixed quality scale (VBR). The meaning of q/qscale is codec-dependent. If qscale is used without a stream_specifier then it applies only to the video stream, this is to maintain compatibility with previous behavior and as specifying the same codec specific value to 2 different codecs that is audio and video generally is not what is intended when no stream_specifier is used.

Fixing Firefox's "corrupt MP4" issue

Firefox can't handle something about yuv444 chroma sampling (it will probably say something in the console about being unable to decode it).

Decoder may not have the capability to handle the requested video format with YUV444 chroma subsampling

Fix it by using the -pix_fmt option, e.g.

bash
ffmpeg \
  -i input.mp4 \
  -pix_fmt yuv420p \
  -c:a copy \
  output.mp4

Fade out video and/or audio

Add a 2-second fade-in from the beginning and a 2-second fade-out from the end of an 81 second video:

bash
ffmpeg -i input.mp4 \
  -filter:a afade=t=in:d=2:st=0,afade=t=out:d=2:st=79 \
  -filter:v fade=t=in:d=2:st=0,fade=t=out:d=2:st=79 \
  output.mp4