Last active
January 2, 2020 11:01
-
-
Save jaspervdj/433901c2589ea87503b06e150fede6c9 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -o errexit -o pipefail -o nounset | |
# Get args. | |
if [[ $# -lt 1 ]]; then | |
1>&2 echo "Usage: $0 MKV" | |
exit 1 | |
fi | |
# Input and output. | |
MKV_IN="$1" | |
MKV_OUT="$(basename "$MKV_IN" .mkv).bad.mkv" | |
# Two temporary files. | |
ORIGINAL_VIDEO="$(mktemp --tmpdir original.XXXXXXXX)" | |
BAD_VIDEO="$(mktemp --tmpdir downgraded.XXXXXXXX.mp4)" | |
function cleanup() { | |
rm -f "$ORIGINAL_VIDEO" "$BAD_VIDEO" | |
} | |
trap cleanup exit | |
# Find video track. | |
VIDEO_TRACK_ID="$(mkvinfo "$MKV_IN" | \ | |
awk '/Track number/ {vt = $5-1} /Track type: video/ {print(vt)}')" | |
# Extract video track. | |
mkvextract tracks "$MKV_IN" "$VIDEO_TRACK_ID:$ORIGINAL_VIDEO" | |
# Re-encode video track. | |
ffmpeg -y -i "$ORIGINAL_VIDEO" -c:v libx264 -threads 1 "$BAD_VIDEO" | |
# Merge into new container; replacing the video track. | |
mkvmerge -o "$MKV_OUT" "$BAD_VIDEO" -d "!$VIDEO_TRACK_ID" "$MKV_IN" |
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
install: | |
ln -sf $(PWD)/badtv.sh $(HOME)/.local/bin/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment