Used FFmpeg Commands

Basics

# 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:
#     -f        uses lafvi, FFmpeg’s virtual input device
#     -i        choses the Mandelbrot pattern as input «file»
#     -t        duration in seconds
#     -c:v      choses rawvideo as codec, i.e. 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 -f lavfi -i 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) gives an audio file.
#
#     Parameters:
#     -f  uses lavfi, FFmpeg’s virtual input device
#     -i  evaluates a sinus function
#     -t  duration in seconds
#         path, name and extension of the output file [no -o is needed]

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

#     Play the file.

ffplay A.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
#         path, name and extension of the output file [no -o is needed]

ffmpeg -i mandelbrot.avi -i A.wav 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 checksum

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

Help

# 7.  Internal resources


ffmpeg -h

ffmpeg -h full

ffmpeg -h decoder=mp3

ffmpeg -h decoder=mp3 -loglevel quiet

ffmpeg -h encoder=libx264

x264 --fullhelp

ffmpeg -h muxer=matroska

ffmpeg -h demuxer=mov

ffmpeg -h filter=crop

Transformations

# 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.
#                 The command must of course match the naming convention
#                 actually used.

ffplay DUFAY_TIFF/Dufay_%06d.tif

#     See also: avpres.net/FFmpeg/play_sq


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


# 9.  Make a mezzanine file ProRes 422 HQ from the conservation files TIFF.
#
#     Parameters:
#     -f image2   forces the image file de-muxer for single image files
#                 NOTE: this parameter must be before the input file
#     -framerate  sets the frame rate to 24
#     -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        we chose the ProRes codec
#     -profile:v  ProRes 422 HQ has the video profile 3
#     -filter:v   we filter 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 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


# 10. Make an access file H.264 directly form the conservation files TIFF.
#
#     Parameters:
#     -c:v      we chose the libx264 codec
#     -preset   we chose veryslow 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


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

#     See also: avpres.net/FFmpeg/im_H264

Advanced

# 12. Difference file

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

  • 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

2018-05-21