Created
March 24, 2010 02:49
-
-
Save danpaluska/341936 to your computer and use it in GitHub Desktop.
Add audio to a movie file. uses sox and ffmpeg. mac/linux
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 | |
### | |
## USAGE ./add_audio.sh moviefile.mp4 audiofile.mp3 | |
## this will take snippet from audio file and add it to moviefile. | |
## it will then trim that snippet from audiofile.mp3 | |
DURATION=`ffmpeg -i $1 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//` | |
### | |
# sox inputfilename.mp3 trimmedfilename.mp3 trim starttime duration | |
# sox foo.wav trimfoo.wav trim 10 10 # gives you 10-20seconds into foo.wav | |
# 00:00:19.55 HH:MM:SS.xx | |
echo "duration = ${DURATION}" | |
length_seconds=`sox --info -D ${2} | cut -d"." -f1` | |
sox $2 temp_audio.mp3 trim 0 $DURATION | |
length_snip=`sox --info -D temp_audio.mp3 | cut -d"." -f1` | |
ffmpeg -sameq -i $1 -i temp_audio.mp3 -ab 192k tempout.mp4 | |
# mv tempout.mp4 $1 | |
let "NEWL=${length_seconds}-${length_snip}" | |
sox $2 ${2}new.mp3 trim $DURATION $NEWL | |
mv tempout.mp4 $1 | |
mv ${2}new.mp3 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment