Skip to content

Instantly share code, notes, and snippets.

@cjburkey01
Created April 18, 2022 15:10
Show Gist options
  • Save cjburkey01/151bb8338b68fd0cb4789c52d5de2bc8 to your computer and use it in GitHub Desktop.
Save cjburkey01/151bb8338b68fd0cb4789c52d5de2bc8 to your computer and use it in GitHub Desktop.
A simple Bash script to convert episodes of shows in the same directory whilst cleaning up the name. Uses FFMPEG!
#!/bin/bash
# CJ's Lovely Little Transcoder Script :)
# HOW TO USE
# ----------
# 1) Update the `input_name_pat` variable below to ensure that each video in the directory will be looped-through.
# For example, the current implementation will scan through names formatted like so:
# That '70s Show (1998) - S05E01 - Going to California (1080p BluRay x265).mkv
# The episode names must also have two matching groups for the season number and the episode number.
# 2) Configure the output name. The current examples will output names that look like this:
# That70sShowS05E01.mp4
# 3) Update the transcoding options (if you want to do so)
# 4) Execute this script in the same directory as the videos you wish to convert.
# 5) ???
# 6) Profit!
# IO config
input_name_pat='[^(]*\(1998\) - S([0-9]{2})E([0-9]{2}) .*\.mkv'
output_prefix='That70sShow'
season_prefix='S'
episode_prefix='E'
output_extension='mp4'
# Transcoding config
codec_video='h264'
codec_audio='copy'
codec_subs='none'
pix_fmt='yuv420p'
# Main loop
for input_file in *.mkv
do
echo "Input file: $input_file"
# Perform regex matching
[[ $input_file =~ $episode_name_pat ]]
season=${BASH_REMATCH[1]}
episode=${BASH_REMATCH[2]}
# Build output name
output_file="${show_name_prefix}${season_prefix}${season}${episode_prefix}${episode}.${output_extension}"
echo " Output file: $output_file"
# Perform transcoding
ffmpeg -i "$input_file" -c:v "$codec_video" -c:a "$codec_audio" -c:s "$codec_subs" -pix_fmt "$pix_fmt" "$output_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment