Last active
March 19, 2024 17:13
-
-
Save aardbol/ff123f3b3f4b82bd52e89e36764ab418 to your computer and use it in GitHub Desktop.
ffmpeg examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a subtitle to a video, set the language=eng, make it the default subtitle and store it as mkv | |
# $1 = video file, $2 = subtitle file | |
ffmpeg -i "$1" -i "$2" -map 0 -map 1 -metadata:s:0 language=eng -c copy -disposition:s:0 default "$1.mkv"` | |
# Add a subtitle to a video, copy just one audio stream, set metadata language=eng for the subtitle, make it the default one and store it as mkv | |
ffmpeg -i "$1.mp4" -i "$1.srt" -map 0 -map 1 -map -0:a:0 -c copy -metadata:s:s:0 language=eng -disposition:s:0 default "$1.mkv" | |
# Scale down every file to H265 720p using Intel QSV hardware encoding | |
find . -type f -exec ffmpeg -i {} -c:v hevc_qsv -s 1280x720 -global_quality 20 -c:a copy -c:s copy {}.mkv \; && find . ! -name '*.mkv.mkv' -exec rm {} \; && rename 's/.mkv.mkv/.mkv/' * | |
# Copy the video, convert the audio to opus 5.1 surround and store as mkv | |
ffmpeg -i file.mkv -map 0:v -c:v copy map 0:s -c:s copy -c:a libopus -b:a 250k -ac 6 out.mkv | |
# Copy all video and audio tracks, remove title metadata of first audio stream, disable default for first subtitle track and set it for the second one | |
ffmpeg -i file.mkv -map 0 -c:v copy -c:a copy -c:s copy -metadata:s:a:0 title= -disposition:s:s:0 none -disposition:s:s:1 default out.mkv | |
# Copy just one stream of each | |
ffmpeg -i file.mkv -c:v copy -c:a copy -c:s copy out.mkv | |
# Convert audio to flac with compression level 8 and copy other streams | |
ffmpeg -i file.mkv -map 0 -c:v copy -c:s copy -c:a flac -compression_level 8 out.mkv | |
# Keep one audio stream and all other streams. Every stream type needs a -map, otherwise the result will not be what you want | |
ffmpeg -i file.mkv -map 0:v -map 0:s -map 0:a:0 -c:v copy -c:s copy -c:a copy out.mkv | |
# Copy all subs and attachments | |
ffmpeg -i file.mkv -map 0:s -c:s copy -map 0:t -c:t copy out.mkv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment