Skip to content

Instantly share code, notes, and snippets.

@mortsavi
Forked from blairanderson/conv.sh
Created October 8, 2018 07:34
Show Gist options
  • Save mortsavi/c0f67339810bb384762a851809382701 to your computer and use it in GitHub Desktop.
Save mortsavi/c0f67339810bb384762a851809382701 to your computer and use it in GitHub Desktop.
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage:
#########################
# $ ls -al
# -> conv.sh
# -> /out
# -> /videos
# $ ./conv.sh videos/
#########################
# Source dir
sourcedir="$1"
if [[ $sourcedir ]]; then
echo -e "Using \033[1;34m$sourcedir\033[0m as Input Folder"
else
echo -e "\033[1;31mError: Check if you have set an input folder\033[0m"
exit
fi
################################################################
cd "$sourcedir"
for filelist in `ls`
do
if ffmpeg -i $filelist 2>&1 | grep 'Invalid data found' #check if it's video file
then
echo "ERROR File $filelist is NOT A VIDEO FILE can be converted!"
continue
fi
echo -e "ffmpeg -i $filelist -y -f mp4 -an -c:v libx264 -crf 30 -vf scale=1920:1080 -preset medium -map_metadata 0 out-"$filelist" < /dev/null"
ffmpeg -i $filelist -y -f mp4 -an -c:v libx264 -crf 30 -vf scale=1920:1080 -preset medium -map_metadata 0 "../out/$filelist" < /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment