Created
August 12, 2011 19:28
-
-
Save puppybits/1142789 to your computer and use it in GitHub Desktop.
convert point-and-shoot camera videos (MJPEG w/PCM_U8) to "HD" format (H264 w/ACC MP4)
This file contains hidden or 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 | |
# @Puppybits circa(2011-05-23) | |
#FIRST install ffmpeg with the proper plugins then add ffmpeg to profile then convert videos | |
# sudo port install ffmpeg +gpl +lame +x264 +xvid +faac | |
# cat ~/.profile echo export #FFMPEG_DATADIR=/opt/local/var/macports/software/ffmpeg/0.6.2_0/opt/local/share/ffmpeg | |
#usage: ./cheeky.sh ./ ./convertions *.mov | |
#dir to start search from | |
directory=$1 | |
#dir to save to | |
save=$2 | |
#default type to *.mov | |
videotype=${3:-*\.mov} | |
#skip | |
skipdupes=${4:-"NO"} | |
#find all files with the extension (case insensitive) | |
n=0 | |
while read file; do | |
echo $file | |
a[$n]="$file" | |
n=$((n+1)) | |
# The following < space <(...) is a bash trick so that the | |
# stuff in the while loop are executed in the current | |
# shell context, and the 'find' is executed in a subshell | |
done < <(find $directory -type f -iname $videotype) | |
echo $a | |
for file in "${a[@]}"; do | |
#get just the filename of the current file | |
filename=$(basename "$file") | |
#change the extension to .mp4 | |
name=${filename%.*}\.mp4 | |
if [ $skipdupes == "YES" ] && [ -e "$save/$name" ] | |
then | |
echo skipped "$name" | |
else | |
# encode with ffmpeg to h264 w/ aac (works from file that are mjpeg w/ pcm_u8) and redirect print to null | |
ffmpeg -i "$file" -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8-partb8x8 -me_method umh -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -refs 2 -directpred 1 -flags2 +dct8x8+fastpskip -crf 22 -wpredp 2 -acodec libfaac -ar 44100 -ac 1 -ab 256 -y "$save/$name" &>/dev/null | |
#rotate cell phone videos (not working yet) | |
#ffmpeg -vf "transpose=1" -i $file -vpre libx264-default -vcodec libx264 -acodec libfaac -ar 48000 -ac 1 -ab 64 -y $save/$name | |
#get time and date of source video | |
timef=(`stat -t "%G%m%d%H%M.%S" -f "%Sm" "$file"`) | |
#change new file to have the same date and time of source | |
touch -t $timef "$save/$name" | |
#print out results | |
echo "$file" was encoded to "$name" and date set to $timef | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment