Last active
April 21, 2020 01:29
-
-
Save AndriusWild/952713704006d35fbf644a0827f6b22c to your computer and use it in GitHub Desktop.
Script to compress mp4 files using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
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
unexpected end of file