FFmpeg Video Editing

Querying Available Codecs and Formats

ffmpeg -codecs
ffmpeg -formats

Extracting Streams

ffmpeg -i [INPUT] [-map 0:1 -map 0:2] -c:a [AUDIO CODEC] -c:v [VIDEO CODEC] 01_1.mkv


ffmpeg -ss [TIME_START] -i [FILE] -ss [+TIME_START] -t [TIME_DURATION] -c copy [OUTPUT]


ffmpeg -i [FILE] -ss [TIME_START] -to [TIME_END] -c copy [OUTPUT]

Adding Subtitles

Add Subtitle with

ffmpeg -i [VIDEO_FILE] -vf subtitles=[.ASS_FILE] -c:a copy [OUTPUT]

.ass format example:

[Script Info]
Title: [TITLE]
Original Script: RoRo
Script Updated By: version 2.8.01
ScriptType: v4.00+
Collisions: Normal
PlayResY: 600
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
Video Zoom: 6
Video Position: 0

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: DefaultVCD, Arial,28,&H00B4FCFC,&H00B4FCFC,&H00000008,&H80000008,-1,0,0,0,100,100,0.00,0.00,1,1.00,2.00,2,30,30,30,0

Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.18,0:00:06.85,DefaultVCD, NTP,0000,0000,0000,,{\pos(400,570)}The first line\NThe second line in subtitle

Downsampling FLAC

For instance,

ffmpeg -i input.flac -af "aresample=44100:resampler=soxr:precision=33:osf=s16:dither_method=shibata" -acodec flac output.m4a

Changing Audio Quality for mp3

To 320k

ffmpeg -i input -c:a libmp3lame -b:a 320k -o output.mp3

Strip metadata

ffmpeg -i in.mkv -map_metadata -1 -c:v copy -c:a copy out.mkv
ffmpeg -i tagged.mp3 -write_xing 0 -id3v2_version 0 untagged.mp3

or use

id3v2 -D input.mp3