Skip to content

Instantly share code, notes, and snippets.

@AndriusWild
Last active April 21, 2020 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndriusWild/952713704006d35fbf644a0827f6b22c to your computer and use it in GitHub Desktop.
Save AndriusWild/952713704006d35fbf644a0827f6b22c to your computer and use it in GitHub Desktop.
Script to compress mp4 files using ffmpeg
#! /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:
#########################
# conv.sh *folder*
#########################
# 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
# Suffix
suffix="_x264"
################################################################
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 "Converting "$filelist""
# real compressing
echo -e "ffmpeg -i "$filelist" -y -f mp4 -c:a libfdk_aac -b:a 192k -c:v libx264 -crf 23 -preset slow -map_metadata 0 "$sourcedir/${filelist%.*}$suffix.mp4" < /dev/null"
ffmpeg -i "$filelist" -y -f mp4 -c:a libfdk_aac -b:a 192k -c:v libx264 -crf 23 -preset slow -map_metadata 0 "$sourcedir/${filelist%.*}$suffix.mp4" < /dev/null
#done
echo -e "\033[1;32mDONE, your video files have be processed\033[0m"
exit
@nimahkh
Copy link

nimahkh commented Mar 19, 2020

unexpected end of file

@emilwojcik93
Copy link

unexpected end of file

You have to uncomment line 44 and install ffmpeg codec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment