Transcoding for local streaming
My home network has a local streaming service based on a local Plex server. It has a few videos wwhich came in odd formats, and where for practical purposes it would be nice to have everything in the same format.
This is my way of transcoding everything to the same format before adding it to the Plex server.
This little script will take all files in the the same directory as the script (given the 4 extentions) and encoding all to Xvid format. The Xvid format is my current prefered format balancing size and quality - and allow for Chromecasting. It may change to a H265 format once all the oldest Chromecast devices are updated and all can handle H265.
The .xvid.mkv is choosen to make it clear which files have been transcoded - and avoid name collisions with the source files.
#!/bin/bash
# Define input extensions you want to process
EXTENSIONS=("mp4" "mov" "avi" "mkv")
# Loop through files with supported extensions
for ext in "${EXTENSIONS[@]}"; do
for input in *."$ext"; do
# Skip if no files match
[ -e "$input" ] || continue
# Get base name without extension
base="${input%.*}"
output="${base}.xvid.mkv"
echo "Transcoding: $input → $output"
ffmpeg -i "$input" \
-c:v mpeg4 -vtag xvid -b:v 2188k -r 25 -pix_fmt yuv420p \
-c:a libmp3lame -b:a 128k -ar 48000 -ac 2 \
"$output"
done
done