No More Twist

Video editing, the hard way

without comments

Say I took a short video clip with a digital camera, and wanted to edit it for publishing online, how hard would it be? Of course I’d be using free software throughout.

There are several fully fledged video editing suites for Linux, however I couldn’t find pre-built packages for any of them. I downloaded source for Kino , LiVES and Cinelerra , and tried to build each. There were build problems and / or dependency problems in each case. It looked like I’d have to fall back on software that was already installed on my machine.

I could play the original video (motion jpeg format) using mplayer . It looked good but was too dark. The lengthy mplayer man page tells of building a filter chain. So I used the eq2 filter to brighten up the image (the parameters separated by colons are gamma, contrast, brightness, saturation, gamma for red, green and blue components, and gamma correction weight):

mplayer -vf eq2=2.25:1.2:0.1:1:1:1:1:1 video.avi

Now that I could see detail, it was clear that the picture was very noisy. I looked at filters again and added the denoise3d filter, which worked fine with default settings:

mplayer -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 video.avi

I was happy with the image, but the sound had a high pitched whine. I saw that mplayer supports audio filters too, and added an equaliser, to cut off the top frequency:

mplayer -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi

On to actual editing. Without a GUI the best I could hope to do was chop off the start or end of the file, but mplayer came to the rescue again. Using the -edlout file option, I could press ‘i’ during playback and the points of interest would be written to the edl file, as a two-second cut. The edl file is just a table of edits which can be easily hand tweaked, and passed into a subsequent playback using the -edl option:

mplayer -edlout edits.edl -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi

mplayer -edl edits.edl -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi

Next, I hoped to write this to a file, in a format that would be more sharable than motion jpeg (eg. mp4). The best way to do this would be to use mencoder, but for some reason I couldn’t find a binary, and didn’t want to rebuild mplayer from scratch. The man pages showed that I could send video out to yuv4mpeg format, which was readable by other tools:

mplayer -edl edits.edl -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi -vo yuv4mpeg

This created a huge stream.yuv file, but it only contained video without sound. The sound can be exported separately using a -ao option:

mplayer -edl edits.edl -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi -vo yuv4mpeg -ao pcm:file=stream.wav

This resulted in a huge stream.yuv and a large stream.wav. I turned to ffmpeg to convert these to mp4, which was painless:

ffmpeg -i stream.yuv -i stream.wav video.mp4

On playback this was skipping like crazy. I checked the output from mplayer and sure enough, it had warned me that it was skipping frames to keep up. So I revisited the mplayer command line and added the -noframedrop option:

mplayer -noframedrop -edl edits.edl -vf denoise3d,eq2=2.25:1.2:0.1:1:1:1:1:1 -af equalizer=6:6:6:6:6:6:6:6:6:-12 video.avi -vo yuv4mpeg -ao pcm:file=stream.wav

The final step was to make the output file larger, and to set the frame rate for ffmpeg:

ffmpeg -i stream.yuv -i stream.wav -s 640×480 -r 15 video.mp4

Clean up the stream files then it’s job done, one mp4 file ready for sharing. The original motion jpeg file was tiny, dark, grainy and unedited at 26Mb. The mp4 file was clearer, large and a bandwidth-friendly 3Mb.

Written by Import Robot

November 5th, 2006 at 1:20 am

Posted in UP

Leave a Reply