Used FFmpeg Commands

Beginner

# 0.  Set the desktop as working space
#
#     In order to find the generated files easier.
#     * on macOS and Linux:

cd ~/Desktop

#     * on Windows:

cd Desktop

#     Generate the working files


# 1.  The Mandelbrot pattern is a fractal curve that allows to notice errors
#     quickly. This gives a video file.
#
#     Parameters:
#     -lafvi    uses FFmpeg’s virtual input device and choses the Mandelbrot
#               pattern
#     -t        duration in seconds
#     -c:v      choses rawvideo as video codec, e.g. uncompressed 8-bit
#     -pix_fmt  choses the YUV 4:2:2 pixel encoding [Y’CBCR would be the
#               accurate writing]
#               path, name and extension of the output file [no -o is needed]

ffmpeg -lavfi mandelbrot -t 10 -c:v rawvideo -pix_fmt uyvy422 mandelbrot.avi

#     Play the file.

ffplay mandelbrot.avi


# 2.  The musical note A (aka 440 Hz, "la" in Italian) gives an audio file.
#
#     Parameters:
#     -lafvi  uses FFmpeg’s virtual input device and evaluates a sinus function
#     -t      duration in seconds
#             path, name and extension of the output file [no -o is needed]

ffmpeg -lavfi aevalsrc="sin(440*2*PI*t)" -t 10 la.wav

#     Play the file.

ffplay la.wav


# 3.  Join the generated video and audio files
#
#     Parameters:
#     -i    path, name and extension of the first input file
#     -i    path, name and extension of the second input file
#     -c:v  copy the video codec
#           path, name and extension of the output file [no -o is needed]

ffmpeg -i mandelbrot.avi -i la.wav -c:v copy mandela.avi

#     Play the file.

ffplay mandela.avi


# 4.  Extract the technical metadata
#
#     Parameters:
#     -show_format   shows the container’s metadata
#     -show_streams  shows the codec’s metadata
#     -print_format  choses the output format

ffprobe mandela.avi

ffprobe -show_format mandela.avi

ffprobe -show_streams mandela.avi

ffprobe -show_format -show_streams mandela.avi

ffprobe -show_format -show_streams -print_format flat mandela.avi

ffprobe -show_format -show_streams -print_format json mandela.avi

ffprobe -show_format -show_streams -print_format xml mandela.avi

#     Save the technical metadata to a text file

ffprobe -show_format -show_streams -print_format json mandela.avi > mandela.txt

#     See also: avpres.net/FFmpeg/probe_json


# 5.  Use the internal documentation
#
#     FFmpeg comes with a comprehensive internal documentation.

ffmpeg -h

ffmpeg -codecs

ffmpeg -decoders

ffmpeg -h decoder=aac

ffmpeg -encoders

ffmpeg -h encoder=ffv1

ffmpeg -filters

ffmpeg -pix_fmts

#     See also: ffmpeg.org/documentation.html


# 6.  Transform the container
#
#     Consists on demultiplex the container given as input, copy the data
#     without decoding and encoding, and multiplex into the output container.
#
#     Parameters:
#     -c  in this example we chose to copy the codec, in order to keep the same
#         quality

ffmpeg -i mandelbrot.avi -c copy mandelbrot.mov


# 7.  MD5 hash values for each frame in the video stream
#
#     Parameters:
#     -f  library framemd5 is used to calculate the MD5 checksums

ffmpeg -i mandelbrot.avi -f framemd5 mandelbrot_avi_framesmd5.txt

ffmpeg -i mandelbrot.mov -f framemd5 mandelbrot_mov_framesmd5.txt

#     Verify that the files are identical.
#     * on macOS and Linux:

diff mandelbrot_avi_framesmd5.txt mandelbrot_mov_framesmd5.txt

#     * on Windows:

fc mandelbrot_avi_framesmd5.txt mandelbrot_mov_framesmd5.txt

Intermediate

# 8.  Play a scan.
#
#     The regex %06d matches six digits long numbers, possibly with leading
#     zeroes. This allows to read in ascending order, one image after the other,
#     the full sequence inside one folder. Of course, the command must match the
#     naming convention actually used.

ffplay DUFAY_TIFF/Dufay_%06d.tif

#     See also: avpres.net/FFmpeg/play_sq


# 9.  Make a ProRes 422 HQ mezzanine file from the TIFF conservation files.
#
#     Parameters:
#     -f image2   forces the image file de-muxer for single image files
#     -framerate  sets the frame rate to 24
#                 NOTE: The previous two parameters must be before the input
#                 file, because they are applied to the input file.
#     -i          path, name and extension of the input file
#                 The regex %06d matches six digits long numbers, possibly with
#                 leading zeroes. This allows to read in ascending order, one
#                 image after the other, the full sequence inside one folder.
#                 The command must of course match the naming convention
#                 actually used.
#     -filter:v   filters the video stream:
#                 * scaling to the correct size
#                   [we use the Lanczos scaling algorithm which is slower but
#                   better than the default bilinear algorithm]
#                 * padding the 4:3 format into the 16:9 HD format with pillar-
#                   box
#     -c:v        choses the ProRes video codec
#     -profile:v  the flavour ProRes 422 HQ has the video profile 3
#
#     NOTE: The backward slash \ escapes the newline. This way you can split a
#     command into more lines for readability.

ffmpeg \
    -f image2 \
    -framerate 24 \
    -i DUFAY_TIFF/Dufay_%06d.tif \
    -filter:v "scale=1440:1080:flags=lanczos, pad=1920:1080:240:0" \
    -c:v prores_ks \
    -profile:v 3 \
    Dufay_ProRes.mov

#     See also: avpres.net/FFmpeg/sq_ProRes


# 10. Make an access file H.264 directly form the conservation files TIFF.
#
#     Parameters:
#     -c:v     choses the H.264 codec by using the libx264 library
#     -preset  choses the veryslow preset which gives the best result
#     -qp      a quantisation parameter of 18 means “visually lossless”

ffmpeg \
    -f image2 \
    -framerate 24 \
    -i DUFAY_TIFF/Dufay_%06d.tif \
    -filter:v "scale=1440:1080:flags=lanczos, pad=1920:1080:240:0" \
    -pix_fmt yuv420p \
    -c:v libx264 \
    -preset veryslow \
    -qp 18 \
    Dufay_H264_1.mp4

#     See also: avpres.net/FFmpeg/sq_H264


# 11. Make an access file H.264 from the mezzanine file ProRes 422 HQ.
#
#     -an  prevents an empty audio track [audio no]

ffmpeg \
    -i Dufay_ProRes.mov \
    -pix_fmt yuv420p \
    -c:v libx264 \
    -preset veryslow \
    -qp 18 \
    -an \
    Dufay_H264_2.mp4

#     See also: avpres.net/FFmpeg/im_H264

Advanced

# 12. Difference file
#
#     uses a chain of filters (called “complex filter”):
#     * input files are numbered from zero on
#     * different filters are separated by a semicolon
#     * components of a same filter are separated by a comma
#     * input and output elements of the filter are into square brackets

ffmpeg \
    -i Dufay_H264_1.mp4 \
    -i Dufay_H264_2.mp4 \
    -filter_complex \
        "[1]format=yuva444p, \
            lut=c3=128, \
            negate[1_with_alpha_channel]; \
        [0][1_with_alpha_channel]overlay" \
    Dufay_H264_delta.mp4

#     See also: avpres.net/FFmpeg/delta


# 13. Split screen

ffmpeg \
    -i Dufay_H264_1.mp4 \
    -i Dufay_H264_2.mp4 \
    -filter_complex \
        "[0]crop=iw/2:ih:0:0, \
            pad=iw*2:ih*1[left]; \
        [1]crop=iw/2:ih:iw/2:0[right]; \
        [left][right]overlay=w" \
    Dufay_H264_split.mp4

#     See also: avpres.net/FFmpeg/split

Exercises

Beginner

Use the excercise file Dufay_ProRes.mov to:

  • generate an other MP4/H.264 access file using -crf 18 (constant rate factor) rather than -qp 18 (quantisation parameter)
  • generate an another access file with -qp 30
  • generate an another access file with -crf 30

Intermediate

  • create a split screen between the MP4/H.264 access files with -qp 18 and -crf 18
  • create a difference file between the files with -qp 18 and -crt 18
  • create a split screen between the files with -qp 18 and -qp 30
  • create a difference file between the files with -crt 18 and -crt 30
  • create a split screen between the files with -qp 30 and -crf 30
  • create a difference file between the files with -qp 30 and -crf 30
  • create a split screen between the ProRes mezzanine file and the MP4/H.264 access files with -qp 18 (or -crf 18)
  • create a difference file between the ProRes mezzanine file and the MP4/H.264 access files with -qp 18 (or -crf 18)

Advanced

  • create horizontal split screen rather than a vertical one
  • create a split screen with a tiny black line between the two sectors

2020-01-12