Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Last active March 25, 2017 01:00
Show Gist options
  • Select an option

  • Save dantheman213/fcf4853773e24ae214a9614f5afbc422 to your computer and use it in GitHub Desktop.

Select an option

Save dantheman213/fcf4853773e24ae214a9614f5afbc422 to your computer and use it in GitHub Desktop.
Batch transcode mp4 files from a directory, set bitrate, and output to another directory.
#!/bin/sh
#
# Batch transcode mp4 files from a directory,
# set bitrate, and output to another directory.
# User-defined parameters
INPUT_DIR="/home/user/Videos/pre"
OUTPUT_DIR="/home/user/Videos/post"
MEDIA_EXTENSION="mp4"
TARGET_BITRATE_VIDEO="8M"
TARGET_BITRATE_AUDIO="128K"
# Execution
echo "Started down transcode script"
echo "Looking for $MEDIA_EXTENSION files within $INPUT_DIR"
for filePath in `find $INPUT_DIR | grep ".$MEDIA_EXTENSION"`; do
fileName=basename "${filePath}"
echo "Transcoding $fileName..."
ffmpeg -i $filePath -vcodec libx264 -b:v $TARGET_BITRATE_VIDEO -acodec aac -b:a $TARGET_BITRATE_AUDIO $OUTPUT_DIR/$fileName
done
echo "completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment