### Check for Fast Start (moov atom position) Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Verifies if the 'moov' atom (metadata) is located at the beginning of the MP4 file, which is essential for 'fast start' playback on the web. This command uses `ffprobe` with trace output and filters the output to find lines containing 'type:'moov''. A 'moov' atom at the beginning indicates the file is optimized for streaming. ```sh ffprobe -v trace -i your_video.mp4 | grep "type:'moov'" ``` -------------------------------- ### Overlay Multiple Timed Text Messages with Fade and Background Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command overlays three distinct text messages onto a video. Each text element has a specific start time, a fade-in alpha effect controlled by the 'alpha' parameter, and a semi-transparent background box specified by 'box' and 'boxcolor'. The 'enable' parameter dictates the visibility timeline for each text overlay. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "drawtext=text='Get ready':x=50:y=100:fontsize=80:fontcolor=black:alpha='if(gte(t,1)*lte(t,3),(t-1)/2,1)':box=1:boxcolor=#6bb666@0.6:boxborderw=7:enable='gte(t,1)', drawtext=text='Set':x=50:y=200:fontsize=80:fontcolor=black:alpha='if(gte(t,6)*lte(t,10),(t-6)/4,1)':box=1:boxcolor=#6bb666@0.6:boxborderw=7:enable='gte(t,6)', drawtext=text='BOOM!':x=50:y=300:fontsize=80:fontcolor=black:alpha='if(gte(t,10)*lte(t,15),(t-10)/5,1)':box=1:boxcolor=#6bb666@0.6:boxborderw=7:enable='gte(t,10)'" -c:v libx264 output_text_overlay.mp4 ``` -------------------------------- ### Handle Out-of-Bounds Cropping with Padding in FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This FFmpeg command enhances the previous example by adding padding to handle cases where cropping might go outside the frame boundaries. The `pad` filter is used to fill any gaps with black color before scaling, ensuring the output maintains the desired aspect ratio and dimensions. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "split=3[1][2][3];[1]trim=0.0:4.5,setpts=PTS-STARTPTS,crop=min(in_w-1200\,480):min(in_h-0\,720):1200:0,pad=480:720:(ow-iw)/2:(oh-ih)/2:color=black,scale=720:1080,setsar=1:1[1];[2]trim=4.5:8.5,setpts=PTS-STARTPTS,crop=min(in_w-500\,480):min(in_h-0\,720):500:0,pad=480:720:(ow-iw)/2:(oh-ih)/2:color=black,scale=720:1080,setsar=1:1[2];[3]trim=8.5,setpts=PTS-STARTPTS,crop=min(in_w-400\,480):min(in_h-0\,720):400:0,pad=480:720:(ow-iw)/2:(oh-ih)/2:color=black,scale=720:1080,setsar=1:1[3];[1][2][3]concat=n=3:v=1" -c:v libx264 -c:a copy output_cropped.mp4 ``` -------------------------------- ### Combine Two MP3 Tracks with Fade FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Combines two MP3 audio tracks with a fade-in and fade-out effect for a seamless transition. The first audio track fades out over 3 seconds starting from its 2nd second, and the second audio track fades in over 3 seconds from its start. The tracks are then concatenated, and the output is encoded using libmp3lame with high quality. ```sh ffmpeg -i https://storage.rendi.dev/sample/Neon_Lights_5sec.mp3 -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -filter_complex "[0:a]afade=t=out:st=2:d=3[a0];[1:a]afade=t=in:st=0:d=3[a1];[a0][a1]concat=n=2:v=0:a=1" -c:a libmp3lame -q:a 2 output_gapless_fade.mp3 ``` -------------------------------- ### Verify Faststart Metadata with ffprobe (ffmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command uses ffprobe to trace the metadata of a video file, allowing verification that the 'moov' atom is located at the beginning of the file, indicating successful application of the faststart option. ```sh ffprobe -v trace -i your_video.mp4 ``` -------------------------------- ### Trim Video by Time with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Extracts a specific segment from a video file based on start and end timestamps. The `-ss` option specifies the starting position, and the `-to` option specifies the ending position. This method is generally accurate but might be slower than other trimming techniques. ```shell ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -ss 00:00:10 -to 00:00:25 output_trimmed.mp4 ``` -------------------------------- ### Create Video Storyboard from Scenes Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Creates a storyboard from a video by selecting frames based on scene changes. The `tile=2X2` option arranges the selected scenes into a 2x2 grid in the output image 'scene_storyboard.jpg'. ```shell ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "select='gt(scene,0.4)',scale=640:480,tile=2X2" -frames:v 1 scene_storyboard.jpg ``` -------------------------------- ### Encode Video to H.265 with Faststart Optimization (ffmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command encodes a video to H.265 (HEVC) using libx265 and optimizes it for web playback with the `-movflags +faststart` option. It copies the audio stream without re-encoding, ensuring faster loading times online. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -c:v libx265 -c:a copy -movflags +faststart big_buck_bunny_720p_16sec_h265_faststart.mp4 ``` -------------------------------- ### Optimize Video for Web Playback with Faststart (ffmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command re-encodes a video to optimize it for faster web playback by moving metadata to the beginning of the file using the `-movflags +faststart` option. It copies both video and audio streams without re-encoding. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -c copy -movflags +faststart big_buck_bunny_720p_16sec_faststart.mp4 ``` -------------------------------- ### Trim Video by Time Range using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Extracts a specific time segment from a video file with frame-accurate precision. This command uses the `-ss` flag to specify the start time and the `-to` flag to specify the end time of the segment to be extracted. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -ss 00:00:10 \ -to 00:00:25 \ output_trimmed.mp4 ``` -------------------------------- ### Create Thumbnail Overlay Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates a thumbnail by overlaying multiple input images. This command takes three input images and composites them into a single output thumbnail file named 'thumbnail_overlayed.png'. ```shell ffmpeg -i https://storage.rendi.dev/sample/bbb-splash.png -i https://storage.rendi.dev/sample/rodents.png -i https://storage.rendi.dev/sample/evil-frank.png -filter_complex "[1]scale=640:360,pad=648:368:4:4:black[overlay1];[2]scale=640:360,pad=648:368:4:4:black[overlay2];[0][overlay1]overlay=0:main_h-overlay_h[tmp1];[tmp1][overlay2]overlay=main_w-overlay_w:main_h-overlay_h" -frames:v 1 thumbnail_overlayed.png ``` -------------------------------- ### Create Tiled Storyboard from Keyframes Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates a tiled storyboard from a video's keyframes. This command uses `-skip_frame nokey` to process only keyframes and `tile=4x4` to arrange them into a 4x4 grid in the output PNG files. ```shell ffmpeg -skip_frame nokey -i https://storage.rendi.dev/sample/big_buck_bunny_720p.mp4 -vf 'scale=640:480,tile=4x4' -an -vsync 0 keyframes%03d.png ``` -------------------------------- ### Create Jump Cuts (Remove Segments) using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Removes specified segments from a video to create jump cuts, often used for silence removal or content shortening. This command uses `select` and `aselect` filters with `between(t,start,end)` conditions to choose which parts to keep, along with `setpts` and `asetpts` to reset timestamps. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -vf "select='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',setpts=N/FRAME_RATE/TB" \ -af "aselect='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',asetpts=N/SR/TB" \ popeye_jumpcuts.mp4 ``` -------------------------------- ### FFmpeg List Supported Formats Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Lists all the multimedia formats (containers and codecs) that the current FFmpeg build supports, including input and output capabilities. ```shell ffmpeg -formats ``` -------------------------------- ### GPU-Accelerated Encoding (Intel Quick Sync Video) Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Leverages Intel's integrated graphics hardware for accelerated video transcoding using Quick Sync Video (QSV). The command initializes the hardware device (`qsv`) and sets the filter hardware device, then uses the `h264_qsv` encoder for H.264 encoding. This offers faster encoding times compared to CPU-based methods. The output is an MP4 file. ```sh ffmpeg -init_hw_device qsv=hw \ -filter_hw_device hw \ -i https://storage.rendi.dev/sample/big_buck_bunny_720p_stereo.avi \ -c:v h264_qsv \ output_gpu_qsv.mp4 ``` -------------------------------- ### Create Slideshow Video with Fades (FFmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Creates a video slideshow where each of the two input images is displayed for 5 seconds, with a 0.5-second fade transition between them. Background audio is included, and the output video duration is 9.5 seconds due to the overlap. Dependencies: ffmpeg. ```sh ffmpeg -loop 1 -t 5 -i https://storage.rendi.dev/sample/rodents.png -loop 1 -t 5 -i https://storage.rendi.dev/sample/evil-frank.png -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -filter_complex "[0:v]format=yuv420p,fade=t=in:st=0:d=0.5,setpts=PTS-STARTPTS[v0];[1:v]format=yuv420p,fade=t=out:st=4.5:d=0.5,setpts=PTS-STARTPTS[v1];[v0][v1]xfade=transition=fade:duration=0.5:offset=4.5,format=yuv420p[v]" -map "[v]" -map 2:a -c:v libx264 -c:a aac -shortest slideshow_with_fade.mp4 ``` -------------------------------- ### FFmpeg Transcode AVI to H264 with Intel GPU (QSV) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Transcodes an AVI video to H.264 using Intel's Quick Sync Video (QSV) hardware acceleration. This requires initializing the QSV device. ```shell ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -i https://storage.rendi.dev/sample/big_buck_bunny_720p_stereo.avi -c:v h264_qsv output_gpu_qsv.mp4 ``` -------------------------------- ### Place Video on Background Image with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command places a video on top of a background image, creating a new video with a specified resolution and aspect ratio. The video is centered on the background image. It takes the video and background image as input and outputs a combined video file. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -i https://storage.rendi.dev/sample/evil-frank.png -filter_complex "[1:v][0:v]overlay=(W-w)/2:(H-h)/2" -c:v libx264 -c:a copy output_bg.mp4 ``` -------------------------------- ### Combine Videos, Add Music, and Mix Audio with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This complex FFmpeg command concatenates multiple video and audio segments (intro, main, outro) into a single video and mixes it with a background music track. It handles audio formatting, fading, and duration control to ensure a smooth playback experience. The output is a single video file with combined content and background music. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_5sec_intro.mp4 -i https://storage.rendi.dev/sample/popeye_talking.mp4 -i https://storage.rendi.dev/sample/big_buck_bunny_720p_5sec_outro.mp4 -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -filter_complex "[0:v]fps=30,format=yuv420p,setsar=1[intro_v];[1:v]scale=-2:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2:black,fps=30,format=yuv420p,setsar=1[main_v];[2:v]fps=30,format=yuv420p,setsar=1[outro_v];[0:a]aformat=sample_fmts=fltp:channel_layouts=stereo[intro_a];[1:a]aformat=sample_fmts=fltp:channel_layouts=stereo[main_a];[2:a]aformat=sample_fmts=fltp:channel_layouts=stereo[outro_a];[intro_v][intro_a][main_v][main_a][outro_v][outro_a]concat=n=3:v=1:a=1[combined_video][combined_audio];[3:a]volume=0.1,aformat=sample_fmts=fltp,afade=t=in:ss=0:d=1.5,afade=t=out:st=20:d=2[bgm_faded];[combined_audio][bgm_faded]amix=inputs=2:duration=first:dropout_transition=2[final_audio]" -map "[combined_video]" -map "[final_audio]" -c:v libx264 -c:a aac -shortest intro_main_outro.mp4 ``` -------------------------------- ### Create Tiled Storyboard from Nth Frame Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Creates tiled image files from every 10th frame of a video. The `tile=4x2` option arranges frames into a 4x2 grid. Removing the `tile` option would create individual images per frame. ```shell ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "select=not(mod(n\,10)),scale=640:480,tile=4x2" -vsync 0 tile_4_2_frames_10_%03d.png ``` -------------------------------- ### Generate Video Storyboard (Contact Sheet) Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Creates a storyboard image by tiling multiple frames from a video into a grid. This command first selects frames based on scene changes (scene threshold 0.4), then scales them to 640x480, and finally arranges them into a 2x2 tile layout. The output is a single JPG image. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -vf "select='gt(scene,0.4)',scale=640:480,tile=2X2" \ -frames:v 1 \ scene_storyboard.jpg ``` -------------------------------- ### Create Thumbnail from Video Frame Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Extracts a single video frame at a specified timestamp to create a thumbnail image. The `-frames:v 1` option ensures only one frame is output. The `-q:v` option controls the output quality, with lower values indicating better quality. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -ss 00:00:07 -frames:v 1 output_thumbnail.png ``` ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -ss 00:00:07 -frames:v 1 -q:v 2 output_thumbnail.jpg ``` -------------------------------- ### Overlay Text from File with Specific Font and Background Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This FFmpeg command overlays text read from a 'textfile' onto a video, using a specified 'fontfile'. It includes parameters for positioning, font size, color, a fade-in effect, and a background box. Note that FFmpeg does not download these files; they must be present locally. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "drawtext=textfile=sample_text.txt:fontfile=Poppins-Regular.ttf:x=50:y=100:fontsize=40:fontcolor=black:alpha='if(gte(t,1)*lte(t,5),t-1,1)':box=1:boxcolor=#6bb666@0.6:boxborderw=7:enable='gte(t,1)'" -c:v libx264 output_text_font_file.mp4 ``` -------------------------------- ### Create GIF from Video Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates a GIF from a video file. It selects frames, adjusts playback speed, resizes the video to a width of 320px while maintaining aspect ratio, and pads it. The `-loop 0` option ensures indefinite looping, which is the default and can be omitted. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "select='gt(trunc(t/2),trunc(prev_t/2))',setpts='PTS*0.1',scale=trunc(oh*a/2)*2:320:force_original_aspect_ratio=decrease,pad=trunc(oh*a/2)*2:320:-1:-1" -loop 0 -an output.gif ``` -------------------------------- ### Mix Audio Tracks with FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Combines the original audio from a video with a separate audio track (e.g., background music). The `-filter_complex` applies a volume adjustment to the background music (`volume=0.2`) and then mixes it with the original audio using `amix`. `-shortest` ensures the output duration matches the shorter input. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -i https://storage.rendi.dev/sample/Neon_Lights_5sec.mp3 \ -filter_complex "[1:a]volume=0.2[a1];[0:a][a1]amix=inputs=2:duration=shortest" \ -shortest -map 0:v -c:v copy -c:a aac \ output_mix_audio.mp4 ``` -------------------------------- ### FFmpeg List Supported Codecs Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Displays a comprehensive list of all audio and video codecs that the FFmpeg build can encode and decode. ```shell ffmpeg -codecs ``` -------------------------------- ### Create Multiple Thumbnails from Video Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates multiple thumbnails from a video at different specified times. It uses the `split` and `select` filters to isolate frames at specific time points. Each selected frame is then output as a single video frame thumbnail. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -filter_complex "[0:v]split=2[first][second];[first]select='gte(t,5)'[thumb1];[second]select='gte(t,15)'[thumb2]" -map "[thumb1]" -frames:v 1 output_thumbnail_1.png -map "[thumb2]" -frames:v 1 output_thumbnail_2.png ``` -------------------------------- ### Concatenate Videos with Background Music using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt This FFmpeg command concatenates multiple video segments (intro, main, outro) and mixes them with background music. It handles scaling, padding, audio formatting, fade-in/out effects for music, and audio mixing. The output is a single MP4 file with combined audio and video. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_5sec_intro.mp4 \ -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -i https://storage.rendi.dev/sample/big_buck_bunny_720p_5sec_outro.mp4 \ -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 \ -filter_complex "[0:v]fps=30,format=yuv420p,setsar=1[intro_v];\ [1:v]scale=-2:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2:black,fps=30,format=yuv420p,setsar=1[main_v];\ [2:v]fps=30,format=yuv420p,setsar=1[outro_v];\ [0:a]aformat=sample_fmts=fltp:channel_layouts=stereo[intro_a];\ [1:a]aformat=sample_fmts=fltp:channel_layouts=stereo[main_a];\ [2:a]aformat=sample_fmts=fltp:channel_layouts=stereo[outro_a];\ [intro_v][intro_a][main_v][main_a][outro_v][outro_a]concat=n=3:v=1:a=1[combined_video][combined_audio];\ [3:a]volume=0.1,aformat=sample_fmts=fltp,afade=t=in:ss=0:d=1.5,afade=t=out:st=20:d=2[bgm_faded];\ [combined_audio][bgm_faded]amix=inputs=2:duration=first:dropout_transition=2[final_audio]" \ -map "[combined_video]" -map "[final_audio]" \ -c:v libx264 -c:a aac -shortest \ intro_main_outro.mp4 ``` -------------------------------- ### Create Thumbnail from Scene Change Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Detects scene changes in a video and creates a thumbnail from the first frame of a detected scene. The `gt(scene,0.4)` filter sensitivity can be adjusted (0 to 1) to control how many scene changes are detected, with lower values being more sensitive. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "select='gt(scene,0.4)'" -frames:v 1 -q:v 2 thumbnail_scene.jpg ``` -------------------------------- ### Generic Optimized FFmpeg Command Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md A versatile FFmpeg command for resizing and optimizing video output for various devices and streaming. It resizes the video to 1080x1920, pads it with black bars if necessary, and applies optimized encoding settings for quality and playback. ```shell ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" -crf 18 -preset veryslow -threads 0 -tune fastdecode -movflags +faststart output_scaled_optimized.mp4 ``` -------------------------------- ### Create Looping Image Video with Fade-in (FFmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates a 10-second video from a single looping image and audio file. The image fades into view over the first second. It's recommended to download the image locally for faster processing. Dependencies: ffmpeg. ```sh ffmpeg -loop 1 -t 10 -i https://storage.rendi.dev/sample/bbb-splash.png -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black,setsar=1,fade=t=in:st=0:d=1,format=yuv420p" -c:v libx264 -c:a aac -shortest output_loop.mp4 ``` -------------------------------- ### Create Individual Scene Images from Video Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Extracts individual frames from a video based on scene changes and saves each scene as a separate image file. The `-vsync 0` option ensures that frames belonging to the same scene are not duplicated. ```shell ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "select='gt(scene,0.4)'" -vsync 0 scene_storyboard_%03d.jpg ``` -------------------------------- ### Create Looping Video from Image with Fade and Audio using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt This FFmpeg command generates a video from a static image with a specified duration, applying a fade-in effect and adding an audio track. It handles scaling, padding, and format conversions. The output is a looping video saved as MP4. ```sh ffmpeg -loop 1 -t 10 \ -i https://storage.rendi.dev/sample/bbb-splash.png \ -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 \ -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black,setsar=1,fade=t=in:st=0:d=1,format=yuv420p" \ -c:v libx264 -c:a aac -shortest \ output_loop.mp4 ``` -------------------------------- ### Generate Scaled Videos with Overlay using FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Creates two scaled video outputs from a single input video and an overlay image. The first output is a horizontally scaled video with padding. The second output is a vertically scaled video with the overlay image placed at the top center. This command utilizes FFmpeg's `filter_complex` for advanced filtering, `split` to duplicate the video stream, and `overlay` to add the logo. ```shell ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -i https://storage.rendi.dev/sample/rendi_banner_white.png -filter_complex "[0:v]split=2[s0][s1];[s0]scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[out1];[s1]scale=w=720:h=1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[s2];[s2][1]overlay=(main_w-overlay_w)/2:(main_w-overlay_w)/5[out2]" -map [out1] -map 0:a output_youtube.mp4 -map [out2] -map 0:a output_shorts.mp4 ``` -------------------------------- ### Optimize Video for Web (H.264) Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Encodes a video with optimal settings for web streaming using the H.264 codec. It scales and pads the video to 1080x1920 with a black background, sets the SAR to 1:1, and uses quality-based encoding (`-crf 18`) with a slow encoding preset (`-preset veryslow`) for a good balance between quality and file size. `-movflags +faststart` is crucial for web playback. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" \ -crf 18 \ -preset veryslow \ -threads 0 \ -tune fastdecode \ -movflags +faststart \ output_scaled_optimized.mp4 ``` -------------------------------- ### Merge and Mix Audio with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Merges the audio from two MP4 files, mixes them into a single mono channel with equal volume contribution, normalizes the volume dynamically, downsamples to 16 kHz, and encodes the result as an MP3 at 64 KBits/s. Dependencies include FFmpeg. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -i https://storage.rendi.dev/sample/popeye_talking.mp4 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest,pan=mono|c0=.5*c0+.5*c1,dynaudnorm" -ar 16000 -c:a libmp3lame -b:a 64k merged_audio.mp3 ``` -------------------------------- ### Replace Audio in Video using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Replaces the audio track of a video file with a new audio file. The `-map` option selects the video stream from the first input and the audio stream from the second. `-shortest` ensures the output duration matches the shorter input, and `-c:v copy` avoids re-encoding the video. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -i https://storage.rendi.dev/sample/Neon_Lights_5sec.mp3 \ -map 0:v -map 1:a -shortest -c:v copy -c:a aac \ output_replace_audio.mp4 ``` -------------------------------- ### Overlay Image on Video with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command overlays a transparent logo or watermark onto a video at specified coordinates and time intervals. It requires the input video and the overlay image as inputs. The output is a new video file with the overlay applied. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -i https://storage.rendi.dev/sample/rendi_banner_white_transparent.png -filter_complex "overlay=x=(main_w-overlay_w)/8:y=(main_h-overlay_h)/8:enable='gte(t,1)*lte(t,7)'" -c:v libx264 -c:a output_logo.mp4 ``` -------------------------------- ### FFmpeg Input Seeking Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Demonstrates how to use the -ss option before the -i flag for fast, keyframe-based seeking in FFmpeg. This method is quick but may be less accurate and can reset timestamps, affecting subsequent filters. ```shell ffmpeg -ss 00:00:03 -i "https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4" -frames:v 1 "input_seeking.jpg" ``` -------------------------------- ### Mix Audio in Video with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Mixes the original audio from a video file with a new audio file. The audio from the second input is lowered in volume (0.2) before being mixed with the original audio. The 'amix' filter combines the two audio streams, and '-shortest' ensures the output video duration matches the shortest input. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -i https://storage.rendi.dev/sample/Neon_Lights_5sec.mp3 -filter_complex "[1:a]volume=0.2[a1];[0:a][a1]amix=inputs=2:duration=shortest" -shortest -map 0:v -c:v copy -c:a aac output_mix_audio.mp4 ``` -------------------------------- ### Stack Videos Vertically with Padding using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt This FFmpeg command combines two videos vertically, applying padding and scaling to ensure consistent dimensions. It uses 'scale', 'pad', and 'vstack' filters within 'filter_complex'. Audio is mapped from the second input, and the output is saved as MP4. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -filter_complex "[0:v]scale=720:-2:force_original_aspect_ratio=decrease,pad=720:640:(ow-iw)/2:(oh-ih)/2:black[top];\ [1:v]scale=720:-2:force_original_aspect_ratio=decrease,pad=720:640:(ow-iw)/2:(oh-ih)/2:black[bottom];\ [top][bottom]vstack=inputs=2:shortest=1[v]" \ -map "[v]" -map 1:a -c:v libx264 -c:a aac -shortest \ output_stacked.mp4 ``` -------------------------------- ### Stack Videos Vertically with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This FFmpeg command stacks two videos vertically, creating a single output video. It scales and pads each video to ensure consistent dimensions before stacking. The audio from the second video is preserved. The 'shortest=1' option ensures the output duration is determined by the shorter input. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -i https://storage.rendi.dev/sample/popeye_talking.mp4 -filter_complex "[0:v]scale=720:-2:force_original_aspect_ratio=decrease,pad=720:640:(ow-iw)/2:(oh-ih)/2:black[top];[1:v]scale=720:-2:force_original_aspect_ratio=decrease,pad=720:640:(ow-iw)/2:(oh-ih)/2:black[bottom];[top][bottom]vstack=inputs=2:shortest=1[v]" -map "[v]" -map 1:a -c:v libx264 -c:a aac -shortest output_stacked.mp4 ``` -------------------------------- ### Upscale Video and Add Padding with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Resizes a video to a target resolution (1080x1920) while maintaining its original aspect ratio and adding black padding to fill the remaining space. The `scale` filter adjusts dimensions, `force_original_aspect_ratio=decrease` ensures the video fits within the bounds, and `pad` adds the black bars. `setsar=1:1` ensures correct pixel scaling. ```shell ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" output_resized_pad.mp4 ``` -------------------------------- ### Extract Audio from Video using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Extracts the audio track from a video file and saves it as an MP3. It allows specifying audio sample rate (`-ar`), bitrate (`-ab`), codec (`-codec:a libmp3lame`), and channels (`-ac`). The command also demonstrates how to copy the video stream without audio to a separate file. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -ar 16000 -ab 48k -codec:a libmp3lame -ac 1 \ output_extracted_audio.mp3 \ -map 0:v -c:v copy -an \ out_video_only.mp4 ``` -------------------------------- ### Resize Video with Padding and Aspect Ratio Preservation using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Upscales or downscales video to target dimensions (e.g., 1080x1920) while preserving its aspect ratio. Black padding is added to fill any gaps, ensuring the output conforms to the desired resolution. The `setsar=1:1` flag ensures correct pixel aspect ratio. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 \ -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" \ output_resized_pad.mp4 ``` -------------------------------- ### Change Audio Format to WAV with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Converts an input MP3 audio file to WAV format using the 'pcm_s32le' codec, setting the audio channels to mono (1) and the sample frequency to 48KHz. Dependencies include FFmpeg. ```sh ffmpeg -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -acodec pcm_s32le -ac 1 -ar 48000 output.wav ``` -------------------------------- ### Add Logo/Watermark Overlay to Video using FFmpeg Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt This FFmpeg command overlays a logo or watermark image onto a video with a transparent background. It controls the position using overlay filter coordinates and specifies the visibility timing using 'enable' option. The output is saved as MP4. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -i https://storage.rendi.dev/sample/rendi_banner_white_transparent.png \ -filter_complex "overlay=x=(main_w-overlay_w)/8:y=(main_h-overlay_h)/8:enable='gte(t,1)*lte(t,7)'" \ -c:v libx264 -c:a copy \ output_logo.mp4 ``` -------------------------------- ### Create Image Slideshow with Crossfade Transition Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Generates a slideshow video from multiple images, incorporating crossfade transitions between images and adding background music. It uses FFmpeg's filter_complex to manage image inputs, apply fade effects, and xfade for transitions. The output is an MP4 video. ```sh ffmpeg -loop 1 -t 5 -i https://storage.rendi.dev/sample/rodents.png \ -loop 1 -t 5 -i https://storage.rendi.dev/sample/evil-frank.png \ -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 \ -filter_complex "[0:v]format=yuv420p,fade=t=in:st=0:d=0.5,setpts=PTS-STARTPTS[v0];\ [1:v]format=yuv420p,fade=t=out:st=4.5:d=0.5,setpts=PTS-STARTPTS[v1];\ [v0][v1]xfade=transition=fade:duration=0.5:offset=4.5,format=yuv420p[v]" \ -map "[v]" -map 2:a -c:v libx264 -c:a aac -shortest \ slideshow_with_fade.mp4 ``` -------------------------------- ### Create Jump Cuts with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Removes specific time segments from both video and audio streams to create jump cuts. This is useful for shortening clips, removing silence, or eliminating transitions. It requires precise timestamp selection for both video ('setpts') and audio ('asetpts'). Dependencies include FFmpeg. ```sh ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -vf "select='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',asetpts=N/SR/TB" popeye_jumpcuts.mp4 ``` -------------------------------- ### Create Ken Burns Effect Video (FFmpeg) Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Generates a video with a Ken Burns effect using two input images and background audio. The first image zooms in towards the center for 4 seconds, then fades into the second image which zooms out from its left side over 4 seconds. The total output video is 7 seconds due to a 1-second fade transition and audio trimming. Dependencies: ffmpeg. ```sh ffmpeg -loop 1 -i https://storage.rendi.dev/sample/rodents.png -loop 1 -i https://storage.rendi.dev/sample/evil-frank.png -i https://storage.rendi.dev/sample/Neon%20Lights.mp3 -filter_complex "[0:v]scale=8000:-1,zoompan=z='zoom+0.005':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=100:s=1920x1080:fps=25,trim=duration=4,format=yuv420p,setpts=PTS-STARTPTS[v0];[1:v]scale=8000:-1,zoompan=z='if(lte(zoom,1.0),1.5,max(zoom-0.005,1.005))':x=0:y='ih/2-(ih/zoom/2)':d=100:s=1920x1080:fps=25,trim=duration=4,format=yuv420p,setpts=PTS-STARTPTS[v1];[v0][v1]xfade=transition=fade:duration=1:offset=3,format=yuv420p[v]" -map "[v]" -map 2:a -c:v libx264 -c:a aac -shortest output_kenburns.mp4 ``` -------------------------------- ### Create Thumbnail from First Detected Scene Change Source: https://context7.com/rendi-api/ffmpeg-cheatsheet/llms.txt Extracts a single thumbnail image from a video at the point of the first detected scene change. It uses the `select` video filter with a `scene` threshold of 0.4 to identify scene changes and captures the first frame that meets this criterion with high quality. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 \ -vf "select='gt(scene,0.4)'" \ -frames:v 1 \ -q:v 2 \ thumbnail_scene.jpg ``` -------------------------------- ### Stream Copy (Remux) with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Demonstrates stream copying using `-c copy` in FFmpeg. This command remuxes video and audio streams into a new container without re-encoding, which is faster and preserves original quality. It's ideal when no filters or modifications are needed. ```sh # Remux video and audio without re-encoding ffmpeg -i input.mp4 -c copy output.mkv # Copy only video stream ffmpeg -i input.mp4 -c:v copy output.mp4 # Copy only audio stream ffmpeg -i input.mp4 -c:a copy output.mp4 ``` -------------------------------- ### VP9 Encoding with CRF using FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Encodes a video using the libvpx-vp9 codec with Constant Quality (CRF) mode. This mode is suitable for web-hosted videos and saves bitrate while maintaining quality. It requires setting both `-crf` and `-b:v 0` to trigger, and `-c:a libopus` specifies the Opus audio encoder. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -c:v libvpx-vp9 -crf 15 -b:v 0 -c:a libopus big_buck_bunny_720p_16sec.webm ``` -------------------------------- ### Replace Audio in Video with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md Replaces the audio track of a video file with a new audio file. The '-shortest' option ensures the output video's duration matches the shorter of the input video or audio. It uses AAC for audio encoding and copies the video stream without re-encoding. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -i https://storage.rendi.dev/sample/Neon_Lights_5sec.mp3 -map 0:v -map 1:a -shortest -c:v copy -c:a aac output_replace_audio.mp4 ``` -------------------------------- ### Crop and Scale Video for Social Media with FFmpeg Source: https://github.com/rendi-api/ffmpeg-cheatsheet/blob/main/README.md This command crops a video into multiple segments, scales them, and concatenates them to create a vertical social media video. It uses filters like `split`, `trim`, `setpts`, `crop`, `scale`, and `concat`. The `crop` filter's dimensions and position are calculated to fit within the output frame before scaling. ```sh ffmpeg -i https://storage.rendi.dev/sample/big_buck_bunny_720p_16sec.mp4 -vf "split=3[1][2][3];[1]trim=0.0:4.5,setpts=PTS-STARTPTS,crop=min(in_w-300\,480):min(in_h-0\,720):300:0,scale=720:1080,setsar=1:1[1];[2]trim=4.5:8.5,setpts=PTS-STARTPTS,crop=min(in_w-500\,480):min(in_h-0\,720):500:0,scale=720:1080,setsar=1:1[2];[3]trim=8.5,setpts=PTS-STARTPTS,crop=min(in_w-400\,480):min(in_h-0\,720):400:0,scale=720:1080,setsar=1:1[3];[1][2][3]concat=n=3:v=1" -c:v libx264 -c:a copy output_cropped.mp4 ```