ffmpeg snippets[source]

    <title>ffmpeg snippets</title>
    <description>Scripts for doing stuff with ffmpeg</description>
    <category>Code snippets</category>
<h2>Extract single frame as image</h2>
<glacius:code lang="bash"><![CDATA[
# 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 <a href="https://superuser.com/a/324596">this Super User answer</a> for
    quality details, apparently the values of <code>-qscale</code> are between 1 and 31
    for jpegs. PNG is lossless so won't be affected by quality. The <code>v</code>
    in <code>q:v</code> 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.
<h2>Fixing Firefox's "corrupt MP4" issue</h2>
    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 <code>-pix_fmt</code> option, e.g.
<glacius:code lang="bash"><![CDATA[
ffmpeg \
  -i input.mp4 \
  -pix_fmt yuv420p \
  -c:a copy \
<h2>Fade out video and/or audio</h2>
    Add a 2-second fade-in from the beginning and a 2-second fade-out
    from the end of an 81 second video:
<glacius:code lang="bash"><![CDATA[
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 \