Here are a number of ffmpeg commands that I think are less common and therefore worth noting. They solve very specific requirements, but you can also use them as inspiration or source for other combinations or variations.
Mask a video with a transparent PNG
ffmpeg -framerate 50 -pattern_type glob -i 'frame-*.png' -i mask.png -filter_complex [0]overlay=x=0:y=0[out] -map [out] -c:v libx264 -pix_fmt yuv420p output.mp4
- Set the framerate to 50.
- Get individual PNG frames for the video
- Load a PNG mask
- Use a filter to overlay the PNG mask over the video
- Output a MP4 File
Add a visual timestamp to a video file
The video filter places the timestamp hours:minutes:seconds:milliseconds with a white yellow font.ttf on a black background a the bottom center of the frame
drawtext=text='timestamp: %{pts \: hms}': x=(w-tw)/2 : y=h-(2*lh) : fontsize=32 : fontcolor=yellow@1 : fontfile=font.ttf : box=1 : boxcolor=black@0.8
The entire ffmpeg command
ffmpeg -i input.mp4 -vf "drawtext=text='timestamp: %{pts \: hms}': x=(w-tw)/2 : y=h-(2*lh) : fontsize=32 : fontcolor=yellow@1 : fontfile=font.ttf : box=1 : boxcolor=black@0.8" -c:a copy output.mp4
- Takes a video file input.mp4
- Takes a font file font.ttf
- Write the timecode in the frame, yellow font (height 32) on a black background at the bottom center of the frame
- Keep the audio track
- Output to video file output.mp4
Add a visual timecode to a video file
The video filter places the timecode hours:minutes:seconds:frames with a white yellow font.ttf on a black background a the bottom center of the frame
drawtext=timecode='00\\:00\\:00\\:00': r=25 : x=(w-tw)/2 : y=h-(2*lh) : fontsize=32 : fontcolor=yellow@1 : box=1 : boxcolor=black@0.8 : fontfile=font.ttf
The entire ffmpeg command
ffmpeg -i input.mp4 -vf "drawtext=timecode='00\\:00\\:00\\:00': r=25 : x=(w-tw)/2 : y=h-(2*lh) : fontsize=32 : fontcolor=yellow@1 : box=1 : boxcolor=black@0.8 : fontfile=m5x7.ttf" -c:a copy output.mp4
- Takes a video file input.mp4
- Takes a font file font.ttf
- Assume a framerate of 25 fps. This value must be set and is not read from the input file.
- Write the timecode in the frame, yellow font (height 32) on a black background at the bottom center of the frame
- Keep the audio track
- Output to video file output.mp4
Get the framerate of a file
Return the framerate of a given video file
ffprobe -v error -select_streams v -of "default=noprint_wrappers=1:nokey=1" -show_entries stream=r_frame_rate input.mp4
If your file has 30 fps the return value will be
30/1