Last active
February 15, 2024 11:35
-
-
Save antoinedelia/27f76fa61d048197f3922459c40bfebd to your computer and use it in GitHub Desktop.
MKVToolNix useful commands
This file contains 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
# https://www.fosshub.com/MKVToolNix.html | |
$ sudo apt install mkvtoolnix | |
# Update the default audio track to the second one in all the files in the current directory | |
$ for i in *; do if [[ $i == *.mkv ]]; then mkvpropedit "$i" --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1; fi; done | |
# If you have a single subtitle, and you want it to be default, then do: | |
$ for i in *; do if [[ $i == *.mkv ]]; then mkvpropedit "$i" --edit track:s1 --set flag-default=1; fi; done | |
# Merge two files into one | |
$ mkvmerge -o output.mkv firstfile.mkv + secondfile.mkv | |
# Identify your tracks for a given file | |
$ mkvmerge --identify [filename] | |
# Hardcode subtitle file into video file | |
$ ffmpeg -i mymovie.mp4 -vf subtitles=subtitles.srt mysubtitledmovie.mp4 | |
# Merge subtitle file to video | |
$ mkvmerge my_file.mkv -o "new_file.mkv" --language 0:en my_subtitle.srt | |
# Convert ANSI .srt file to UTF-8 | |
$ iconv -f "windows-1252" -t "UTF-8" import.csv -o new_import.csv | |
# Extract srt from mkv file | |
# The first number is which input you select (0 is the first and only input in my command), | |
# second character is what type of stream you select (s is subtitles, a is audio, v is video), | |
# third is which stream you select out of those (if you have two subtitles, you can put 0 or 1). | |
# So like this: -map input_file_index:stream_type_specifier:stream_index | |
# So the code above takes the Movie.mkv, then its subtitle streams, then the first subtitle stream. (counting starts with 0, because it's an index.) | |
$ ffmpeg -i Movie.mkv -map 0:s:0 subs.srt | |
# Some useful for loops | |
$ for i in {1..10}; do iconv -f "windows-1252" -t "UTF-8" "$i.fr.srt" -o "$i.new.srt" && mkvmerge "$i.mkv" -o "$i.new.mkv" --language 0:fr "$i.new.srt" && echo "Processed file $i successfully" || echo "Failed to process file $i"; done | |
# Get all information from an mp3 file | |
$ sudo apt update && sudo apt install ffmpeg | |
$ ffprobe -v quiet -print_format json -show_format -show_streams yourfile.mp3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment