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 mandelaaa.avi

#     Play the file.

ffplay mandelaaa.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 mandelaaa.avi

ffprobe -show_format mandelaaa.avi

ffprobe -show_streams mandelaaa.avi

ffprobe -show_format -show_streams mandelaaa.avi

ffprobe -show_format -show_streams -print_format flat mandelaaa.avi

ffprobe -show_format -show_streams -print_format json mandelaaa.avi

ffprobe -show_format -show_streams -print_format xml mandelaaa.avi

#     See also: avpres.net/FFmpeg/probe_json


# 5.  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

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


# 6.  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


# 7.  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

Intermediate

#     NOTE: The backward slash \ escapes the newline. This way you can split a
#     command into more lines for readability.


# 8.  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.
#     -c:v        choses the ProRes video codec
#     -profile:v  the flavour ProRes 422 HQ has the video profile 3
#     -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

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

#     See also: avpres.net/FFmpeg/sq_ProRes


# 9.  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 \
    -c:v libx264 \
    -preset veryslow \
    -qp 18 \
    -filter:v "scale=1440:1080:flags=lanczos, pad=1920:1080:240:0" \
    -pix_fmt yuv420p \
    Dufay_H264_1.mp4

#     See also: avpres.net/FFmpeg/sq_H264


# 10. 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 \
    -c:v libx264 \
    -preset veryslow \
    -qp 18 \
    -pix_fmt yuv420p \
    -an \
    Dufay_H264_2.mp4

#     See also: avpres.net/FFmpeg/im_H264

Advanced

# 11. 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


# 12. 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

  • create an other H.264 file using the parameter -qp 40 from the excercise file Dufay_ProRes.mov
  • use -crf 18 (constant rate factor) instead of -qp 18 (quantisation parameter)

Intermediate

  • create a split screen between the files with -qp 18 and -qp 40 (or -crf 18 and -crf 40)
  • create a difference file between the files with -qp 18 and -qp 40 (or -crf 18 and -crf 40)

Advanced

  • horizontal split screen
  • split screen with a tiny black line between the two sectors

2019-10-17