### Mix Multiple Audio Tracks (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Mixes multiple audio tracks into a single output. This example mixes a video's audio with background music. ```bash ffmpeg -i video.mp4 -i background_music.mp3 \ -filter_complex "[0:a][1:a]amix=inputs=2:duration=first:dropout_transition=2" \ -c:v copy output.mp4 ``` -------------------------------- ### Convert Audio Format (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Converts audio files between different formats. Examples show conversion from WAV to MP3 and MP3 to Opus. ```bash ffmpeg -i input.wav -c:a libmp3lame -q:a 2 output.mp3 ``` ```bash ffmpeg -i input.mp3 -c:a libopus -b:a 128k output.opus ``` -------------------------------- ### RTMP Live Streaming: YouTube, Twitch, Webcam, and Desktop Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Demonstrates how to use FFmpeg for live streaming via the RTMP protocol to platforms like YouTube and Twitch. Examples include streaming from a file, capturing webcam and microphone input, and streaming the desktop screen. ```bash # Stream to YouTube Live ffmpeg -re -i input.mp4 \ -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k \ -pix_fmt yuv420p -g 50 \ -c:a aac -b:a 128k -ar 44100 \ -f flv "rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY" # Stream to Twitch ffmpeg -re -i input.mp4 \ -c:v libx264 -preset fast -b:v 2500k \ -c:a aac -b:a 128k \ -f flv "rtmp://live.twitch.tv/app/YOUR_STREAM_KEY" # Stream webcam and microphone (Linux) ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default \ -c:v libx264 -preset ultrafast -tune zerolatency \ -c:a aac -b:a 128k \ -f flv "rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY" # Stream desktop screen (Linux with X11) ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 \ -f pulse -i default \ -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \ -c:a aac -b:a 128k \ -f flv "rtmp://live.twitch.tv/app/YOUR_STREAM_KEY" ``` -------------------------------- ### Node.js FFmpeg Wrapper: Conversion, Thumbnails, Watermarking, Metadata Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Employs the fluent-ffmpeg library for Node.js to generate and execute FFmpeg commands with event-driven progress tracking. This example covers basic video conversion, generating thumbnails, applying watermarks, and retrieving video metadata. Requires the 'fluent-ffmpeg' package. ```javascript const ffmpeg = require('fluent-ffmpeg'); // Basic video conversion with progress tracking ffmpeg('input.mp4') .output('output.webm') .videoCodec('libvpx-vp9') .audioCodec('libopus') .on('progress', (progress) => { console.log(`Processing: ${progress.percent}% done`); }) .on('end', () => { console.log('Conversion finished'); }) .on('error', (err) => { console.error('Error:', err.message); }) .run(); // Generate video thumbnails ffmpeg('video.mp4') .screenshots({ count: 4, folder: './thumbnails', filename: 'thumb_%i.png', size: '320x240' }); // Add watermark overlay ffmpeg('input.mp4') .input('watermark.png') .complexFilter([ '[0:v][1:v]overlay=10:10' ]) .output('watermarked.mp4') .run(); // Get video metadata ffmpeg.ffprobe('input.mp4', (err, metadata) => { if (err) throw err; const videoStream = metadata.streams.find(s => s.codec_type === 'video'); console.log(`Resolution: ${videoStream.width}x${videoStream.height}`); console.log(`Duration: ${metadata.format.duration}s`); }); ``` -------------------------------- ### Hardware Acceleration: NVIDIA NVENC, Intel QSV, and AMD VCE Encoding Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Illustrates using FFmpeg with hardware acceleration for video encoding on NVIDIA GPUs (NVENC), Intel Quick Sync (QSV), and AMD GPUs (VCE). It shows examples for H.264 and H.265 encoding, full hardware decode/encode pipelines, and how to list available hardware encoders. ```bash # NVIDIA NVENC H.264 encoding ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -cq 20 -c:a copy output.mp4 # NVIDIA NVENC H.265/HEVC encoding ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p7 -cq 23 -c:a copy output_hevc.mp4 # Full hardware decode and encode pipeline (CUDA) ffmpeg -hwaccel cuda -hwaccel_output_format cuda \ -i input.mp4 \ -c:v h264_nvenc -preset p4 -cq 22 \ -c:a copy output.mp4 # Intel Quick Sync Video (QSV) encoding ffmpeg -i input.mp4 -c:v h264_qsv -preset faster -global_quality 23 -c:a copy output.mp4 # AMD VCE encoding ffmpeg -i input.mp4 -c:v h264_amf -quality quality -rc cqp -qp 20 -c:a copy output.mp4 # List available hardware encoders ffmpeg -encoders | grep -E "nvenc|qsv|amf|vaapi" ``` -------------------------------- ### H.264 Video Encoding: High Quality, Two-Pass, and Web Optimization Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Provides command-line examples for encoding videos using FFmpeg's H.264 encoder (libx264). It covers high-quality encoding with CRF, two-pass encoding for target file sizes, using different presets for speed/compression tradeoff, and creating web-optimized MP4 files. ```bash # High quality encoding with CRF (Constant Rate Factor) # CRF 0 = lossless, 18 = visually lossless, 23 = default, 28 = lower quality ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 18 -c:a aac -b:a 192k output.mp4 # Two-pass encoding for target file size (e.g., 50MB target) ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 2M -pass 1 -an -f null /dev/null ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 2M -pass 2 -c:a aac -b:a 128k output.mp4 # Encoding presets (speed vs compression tradeoff) # ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow ffmpeg -i input.mp4 -c:v libx264 -preset veryslow -crf 20 output.mp4 # Web-optimized MP4 with fast start (moov atom at beginning) ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -movflags +faststart web_video.mp4 ``` -------------------------------- ### Audio Fade In/Out (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Applies fade-in and fade-out effects to an audio file. It specifies the type of fade, start time, and duration. ```bash ffmpeg -i input.mp3 -af "afade=t=in:st=0:d=3,afade=t=out:st=57:d=3" output.mp3 ``` -------------------------------- ### Speed Up/Slow Down Video with Audio Pitch Correction (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Adjusts video playback speed and corrects audio pitch accordingly. This example doubles the video speed and tempo of the audio. ```bash ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" fast.mp4 ``` -------------------------------- ### Change Audio Sample Rate and Channels (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Modifies the sample rate and number of audio channels. This example changes a WAV file to 44100 Hz sample rate and 2 audio channels. ```bash ffmpeg -i input.wav -ar 44100 -ac 2 output.wav ``` -------------------------------- ### Extract Specific Audio Channel (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Extracts a specific audio channel from a multi-channel audio file. This example extracts the left channel from a stereo WAV file. ```bash ffmpeg -i stereo.wav -af "pan=mono|c0=FL" left_channel.wav ``` -------------------------------- ### Video Filters: Scaling, FPS, Color Correction, Fade, and Picture-in-Picture Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Showcases FFmpeg's powerful video filtering capabilities. Examples include applying multiple filters in a chain (scaling, FPS, color correction), adding fade in/out effects, and creating a picture-in-picture overlay effect. ```bash # Apply multiple video filters with filter chain ffmpeg -i input.mp4 -vf "scale=1280:720,fps=30,eq=brightness=0.1:contrast=1.2" output.mp4 # Add fade in/out effects ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=2,fade=t=out:st=58:d=2" output.mp4 # Picture-in-picture overlay ffmpeg -i main.mp4 -i overlay.mp4 \ -filter_complex "[1:v]scale=320:240[pip];[0:v][pip]overlay=main_w-overlay_w-10:10" \ output.mp4 ``` -------------------------------- ### Go FFmpeg Wrapper: Basic Conversion and Filters with ffmpeg-go Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Demonstrates using the ffmpeg-go library to perform basic video conversions, apply video filters like scaling and text overlays, and extract audio from video files using a fluent API. ```go package main import ( "fmt" ffmpeg "github.com/u2takey/ffmpeg-go" ) func main() { // Basic video conversion err := ffmpeg.Input("input.mp4"). Output("output.avi"). OverWriteOutput(). Run() if err != nil { panic(err) } // Apply video filters: scale and add text overlay err = ffmpeg.Input("input.mp4"). Filter("scale", ffmpeg.Args{"1280:720"}). Filter("drawtext", ffmpeg.Args{ "text='Sample Video'", "fontsize=24", "fontcolor=white", "x=10", "y=10", }). Output("output.mp4", ffmpeg.KwArgs{ "c:v": "libx264", "crf": "23", }). OverWriteOutput(). Run() if err != nil { panic(err) } // Extract audio from video err = ffmpeg.Input("video.mp4"). Output("audio.mp3", ffmpeg.KwArgs{ "vn": "", "acodec": "libmp3lame", "q:a": "2", }). Run() if err != nil { panic(err) } } ``` -------------------------------- ### FFmpeg Command Line Basics: Video Conversion, Audio Extraction, Resizing, Trimming, Concatenation Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Demonstrates fundamental FFmpeg command-line operations for common multimedia tasks. These commands cover format conversion, audio extraction, video resizing while maintaining aspect ratio, trimming specific segments, and concatenating multiple video files. No external libraries are required beyond the FFmpeg executable. ```bash # Convert video format (MP4 to WebM) ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webm # Extract audio from video ffmpeg -i video.mp4 -vn -acodec libmp3lame -q:a 2 audio.mp3 # Resize video to 720p while maintaining aspect ratio ffmpeg -i input.mp4 -vf "scale=-1:720" -c:a copy output_720p.mp4 # Trim video from 00:01:00 to 00:02:30 ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:30 -c copy trimmed.mp4 # Concatenate multiple videos ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4 # filelist.txt contains: # file 'video1.mp4' # file 'video2.mp4' # file 'video3.mp4' ``` -------------------------------- ### Create Video from Images (Slideshow) (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Generates a video slideshow from a sequence of images. It sets the frame rate for input images and specifies encoding parameters for the output video. ```bash ffmpeg -framerate 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4 ``` -------------------------------- ### Add Audio to Video (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Replaces the existing audio track of a video with a new audio file. It copies the video stream and maps the new audio stream. ```bash ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4 ``` -------------------------------- ### Python FFmpeg Wrapper: Video Conversion, Filtering, Frame Extraction, Metadata Probing Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Utilizes the ffmpeg-python library to programmatically build FFmpeg command pipelines in Python. This snippet showcases basic conversion, complex filter chains involving scaling and watermarking, extracting frames at a specific rate, and retrieving video metadata. Requires the 'ffmpeg-python' package. ```python import ffmpeg # Basic video conversion with ffmpeg-python ( ffmpeg .input('input.mp4') .output('output.avi') .run() ) # Complex filter chain: resize, overlay watermark, and add audio ( ffmpeg .input('input.mp4') .filter('scale', 1280, 720) .overlay(ffmpeg.input('watermark.png'), x=10, y=10) .output('output.mp4', acodec='aac', vcodec='libx264', crf=23) .overwrite_output() .run() ) # Extract frames as images ( ffmpeg .input('video.mp4') .filter('fps', fps=1) # 1 frame per second .output('frame_%04d.png') .run() ) # Get video metadata/probe information probe = ffmpeg.probe('input.mp4') video_info = next(s for s in probe['streams'] if s['codec_type'] == 'video') width = video_info['width'] height = video_info['height'] duration = float(probe['format']['duration']) print(f"Video: {width}x{height}, Duration: {duration}s") ``` -------------------------------- ### Add Text Overlay with Timestamp (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Adds a text overlay with the current timestamp to a video. It utilizes the 'drawtext' filter to specify the text content, font size, color, and position. ```bash ffmpeg -i input.mp4 -vf "drawtext=text='%{pts\:hms}':fontsize=24:fontcolor=white:x=10:y=10" output.mp4 ``` -------------------------------- ### Color Correction and Grading (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Applies color correction and grading effects to a video using FFmpeg's filtergraph. It includes presets for 'lighter' curves, saturation adjustment, and unsharp masking. ```bash ffmpeg -i input.mp4 -vf "curves=preset=lighter,eq=saturation=1.3,unsharp=5:5:1.0" output.mp4 ``` -------------------------------- ### Normalize Audio Volume (FFmpeg) Source: https://context7.com/awesomelistsio/awesome-ffmpeg/llms.txt Normalizes audio volume to meet broadcast standards using the 'loudnorm' filter. It adjusts integrated loudness (I), true peak (TP), and loudness range (LRA). ```bash ffmpeg -i input.mp4 -af "loudnorm=I=-16:TP=-1.5:LRA=11" -c:v copy output.mp4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.