Rasti Xvid kodekų failus mkv konteineryje ir perkoduoti į h264
Jump to navigation
Jump to search
#!/bin/bash
# This script will search provided folder and find all invalid mkv files in it that does not contain x264 video stream
# For example file with mkv container contains mpeg4 or XVID stream
# After it finds those invalid files will execute the transcoding on them
# expected video codec is h264, it can be changed
# if no expected codec found then the transcode will arise
EXT=mkv
FOLD="$@"
dirstat() {
if [[ ! -d "archived" ]]; then
mkdir archived
fi
echo "Moving: $1 to archived/$1"
mv "$1" archived/
}
process() {
echo "Processing motherfucker $1"
VAL=$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$1")
if [[ "$VAL" != "h264" ]]; then
echo "File: $1 has invalid video codec: $VAL"
OUTF="$1_out.mkv"
echo "Transcoding: ffmpeg -i $1 -c:a copy -c:v libx264 $OUTF"
ffmpeg -i "$1" -c:a copy -c:v libx264 "$OUTF"
dirstat "$1"
echo "Renaming files..."
mv "$OUTF" "$1"
else
echo "File: $1 is ok"
fi
}
cd ${FOLD}
for i in *.${EXT}; do # Whitespace-safe but not recursive.
process "$i"
done
echo "Done all!"
Usage:
./script <dir>