Created
January 20, 2013 12:33
-
-
Save newtriks/4578305 to your computer and use it in GitHub Desktop.
Join input audio files and encode to MP4 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 version of the script | |
VERSION=1.0 | |
echo "------------------------------------------" | |
echo "Audio Specific Concat Script v$VERSION - A script to concatenate multiple audio files and encode to MP4." | |
echo "Based on FFmpeg - www.ffmpeg.org and http://goo.gl/eDFeM" | |
echo "------------------------------------------" | |
# Syntax check (has to have at least 3 params: infile1, infile2, outfile | |
if [ -z $3 ]; then | |
echo "Syntax: $0 <input1> <input2> <input3> ... <output>" | |
exit 1 | |
fi | |
first=${@:1:1} | |
last=${@:$#:1} | |
len=$(($#-1)) | |
inputs=${@:1:$len} | |
all_a="" | |
# Clean out any existing tmp files | |
rm -rf tmp | |
# Create a new tmp files dir in the current path | |
mkdir -p tmp | |
# Iterate through all the inputs and decode | |
i=1 | |
for f in $inputs | |
do | |
mkfifo tmp/mcs_a$i.mpg | |
/usr/local/bin/ffmpeg -i $f -qscale:v 1 -y tmp/mcs_a$i.mpg < /dev/null & | |
all_a+="tmp/mcs_a$i.mpg" | |
if [ $i -lt $len ] | |
then | |
all_a+="|" | |
fi | |
let i++ | |
done | |
# Concatenate all raw audio inputs | |
/usr/local/bin/ffmpeg -i concat:$all_a -c copy tmp/mcs_a_all.mpg | |
# Encode to mp4 | |
/usr/local/bin/ffmpeg -i tmp/mcs_a_all.mpg -c:a libvo_aacenc -b:a 64k -ar 44100 -copyts -y $last | |
# Clean up all tmp files | |
rm -rf tmp | |
echo "----------------------------------------" | |
echo "*END* - audio specific join and encoding" | |
echo "----------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
libvo_aacenc is the audio codec I found works best on OS X to encode f4v to H264. On Linux I found libfaac audio codec works best.