Hi. I'm having some troubles recently with my screencasting software solutions: both recordmydesktop and ffmpeg's x11grab, which had both been functioning fine for me, now put audio and video slightly out of sync. I've done a fair amount of searching for solutions and have tried a number of suggested tweaks, but the out-of-sync problem persists.
Among the things that I've found, the only thing that has really addressed the sync issue and given me an output file that has both audio and video in pretty much perfect sync, is a kludgy-looking script someone cobbled together that gets ffmpeg to record audio and video separately, then join them into an output file. A short test file I made with this script, as I mentioned, had audio and video pretty much perfectly in sync.
The script, which came from the ubuntu forums (
http://ubuntuforums.org/showthread.php?t=2003738) follows:
Code:
#!/bin/bash
#vzybilly
#these are temp files
aud="aud.mp3"
vid="vid.mp4"
#grab audio & pid
ffmpeg -f alsa -ac 2 -i plughw:0,0 $aud &
audPID=$!
#grab screen & pid
ffmpeg -f x11grab -s "1366x768" -r "24" -i :0.0 -threads 0 -sameq -an -f mp4 $vid &
vidPID=$!
#wait, till name given (that means stop)
read -p "Stop by giving an Output video name?" out
#stop audio and video with pids
kill -n 2 $audPID
kill -n 2 $vidPID
echo "Saving to $out"
#combine to the target output file
ffmpeg -i $aud -i $vid -acodec copy -vcodec copy "$out"
#purge the temp files
rm $aud
rm $vid
I think I understand what it does, though figuring out how to use it took some experimentation. The weird and not-very-intuitive thing about it is that, in order to stop the recording and cause it to join the audio and video files, you have to just type into the terminal where it's running some file name under which it should save the output; all this while ffmpeg is running and giving you a message that you should type ctrl-c to stop the recording.
So, though effective, the script could definitely use improvement. Seems to me it should begin by asking for a file name, then make that into one of the variables: but my knowledge of scripting is so rudimentary that I don't have the slightest idea how that would be done. Then, the matter of causing the script to go from record mode to join mode seems like it could use help as well.
Can anyone on here offer some improvements to this script that would make it run a bit more coherently? Input will be greatly appreciated since, for the time being, this is the only way I have to produce screencasts that have audio and video in sync.
Thanks,
James