It can take many minutes to process a small, 30-second clip, or even hours to process a full movie. There are numerous, excellent, open source video transcoding and processing tools freely available in Ubuntu, including libav-tools, ffmpeg, mencoder, and handbrake. Surprisingly, however, none of those support parallel computing easily or out of the box. And disappointingly, I couldn't find any MPI support readily available either.
I happened to have an Orange Box for a few days recently, so I decided to tackle the problem myself, and develop a scalable, parallel video transcoding solution myself. I'm delighted to share the result with you today!
At a high level, the algorithm looks like this:
- Create a shared network filesystem, simultaneously readable and writable by all nodes
- Have the master node split the work into even sized chunks for each worker
- Have each worker process their segment of the video, and raise a flag when done
- Have the master node wait for each of the all-done flags, and then concatenate the result
For the curious, the real magic is in the config-changed hook, which has decent inline documentation.
The trick, for anyone who might make their way into this by way of various StackExchange questions and (incorrect) answers, is in the command that splits up the original video (around line 54):
avconv -ss $start_time -i $filename -t $length -s $size -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y ${filename}.part${current_node}.ts
And the one that puts it back together (around line 72):
avconv -i concat:"$concat" -c copy -bsf:a aac_adtstoasc -y ${filename}_${size}_x264_aac.${format}
In any case, once deployed, my cluster bundle looks like this. 8 units of transcoders, all connected to a shared filesystem, and performance monitoring too.
Oddly enough, the stock, 746MB high quality MP4 video doesn't play in Firefox, since it's an mpeg4 stream, rather than H264. Fail. (Yes, of course I could have used mplayer, vlc, etc., that's not the point ;-)
http://www.w3schools.com/html/html5_video.asp |
In any case, I find it quite useful to transcode my videos to MP4/H264/AAC format. And for that, a scalable, parallel computing approach to video processing would be quite helpful.
During the course of the 3 minute run, I liked watching the avconv log files of all of the nodes, using Byobu and Tmux in a tiled split screen format, like this:
Also, the transcode charm installs an Apache2 webserver on each node, so you can expose the service and point a browser to any of the nodes, where you can find the input, output, and intermediary data files, as well as the logs and DONE flags.
Once the job completes, I can simply click on the output file, Code_Rush.mp4_1280x720_x264_aac.mp4, and see that it's now perfectly viewable in the browser!
In case you're curious, I have verified the same charm with a couple of other OGG, AVI, MPEG, and MOV input files, too.
Beyond transcoding the format and codecs, I have also added configuration support within the charm itself to scale the video frame size, too. This is useful to take a larger video, and scale it down to a more appropriate size, perhaps for a phone or tablet. Again, this resource intensive procedure perfectly benefits from additional compute units.
In the mean time, I hope you'll take a look at this charm and consider using it, if you have the need to scale up your own video transcoding ;-)
Cheers,
Dustin
No comments:
Post a Comment
Please do not use blog comments for support requests! Blog comments do not scale well to this effect.
Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com
Thanks,
:-Dustin