FirstClown

firstclown at firstclown.us

Posts Tagged ‘video’

Transcoding DV to Widescreen MP4 in Linux

When I export video from Cinelerra in Linux after editing, I always render as Raw DV. It takes a lot of harddrive space, but I've never gotten any other format to work in Cinelerra, especially when my finished video needs to be widescreen. Luckily, Linux has some great tools for transcoding video. One of the most popular is ffmpeg.

I'll usually render the video to DV and then run the following commands to get it into an MP4 that is widescreen:

ffmpeg -f dv -i RenderedVideo.dv -pass 1 -vcodec h264 -g 300 -mbd 2
    -cmp 2 -subcmp 2 -deinterlace -aspect 16:9 -s 640x360 -padtop 4
    -padbottom 4 -b 768k -acodec aac -y Final_vodcast_render.mp4

ffmpeg -f dv -i RenderedVideo.dv -pass 2 -vcodec h264 -g 300 -mbd 2
    -cmp 2 -subcmp 2 -deinterlace -aspect 16:9 -s 640x360 -padtop 4
    -padbottom 4 -b 768k -acodec aac -y Final_vodcast_render.mp4

MP4Box -add Final_vodcast_render.mp4 Final_vodcast.mp4
MP4Box -par 1=1:1 Final_vodcast.mp4
rm Final_vodcast_render.mp4

A little explanation may be in order.

The first line is a first pass of the video encoding. It's really there just to gather data in order to optimize the real encoding. You could throw away the final video file created by this, but I always choose to keep it around.

For a real understanding of all the options, take a look at this page that lists all the options and tries to explain them. Important ones are:

  • -vcodec: The video codec we want to use. Internet standard at the moment is H.264
  • -deinterlace: My camera records for standard TVs (640i). If your's does too, you'll need to deinterlace the signal for internet video
  • -aspect: Need to set it to widescreen which, for my camera, is 16:9
  • -s: This is the final size of the video, 640 pixels by 360 pixels
  • -padtop,-padbottom: Video needs to be processed in 16x16 pixel blocks. Since 360 is not divisible by 16, I need to make sure the height is divisible by 16. Adding a 4 pixel line of black padding pixels to the top and bottom makes the height 368, which is divisible by 16
  • -b: The bitrate of the video. 768k is a little big for internet video, but it keeps the quality up there for Apple TV and what not.
  • -acodec: The Audio codec we want to use, AAC
  • -y: Overwrite files, needed on the second run

The other options are really just things I got from other people on what to set to get this to run on an Apple TV. I felt that was important enough for my podcast to keep them in there. Blip.tv actually does a good job of converting this to an iPod friendly format, so I won't go into the nightmare that is transcoding video in Linux for the iPod. I actually don't think I even got a good iPod version in all the times I tried it.

The last three lines basically fix the MP4 that ffmpeg created. It would mess up the pixel aspect ratio (PAR) and I just reset it here to 1:1 square pixels.

Syncing Audio and Video in Linux

After PodcampOhio, I realized that I've got quite a few video editing ideas to share with those of you who use Linux. This first one is how I sync my separate audio and video files.

I film STeaP TV with a Panasonic H200 and, while a great camera, it doesn't have a mic input so that I can easily sync up audio recorded out of the camera with the video in the camera. In order to do that, I have to export the audio from the video file, sync the better audio with the camera audio and then overlay the better audio on the video in new MPEG file.

Important tips while filming: start your audio recording first. You'll see why later. Also, when you've just started recording, slap two boards together or knock on the table or something. Really any thing that created two sharp spikes on the audio and do this before you really start doing anything. Everything before these spikes will be unusable after syncing.

Extracting the Audio

First you'll want to extract the camera audio from the video file. If the video file it MOV002.mpg, you can do that with:

mplayer MOV002.mpg -vc null -vo null -ao pcm:fast

You'll now have a file called audiodump.wav.

Syncing the Audio

Now we want to change the better audio to be synced with the camera audio. We can do that by, while filming, slapping some boards together to get a spike on the audio wave form. We can then load them both in Audacity and match up the spikes.

To do that, we zoom in to see both spikes on the screen, highlight from spike to spike in the better audio:

Before Sync

And then cut!

After Sync

Now, highlight the better audio track and Export Selection... as MP3.

Overlaying The Audio on the Video

Now that the two audio streams have the spikes in the same place, the better audio is automatically synced with the new video! So now we just overlay the better audio on the video.

If we saved the better audio as BetterAudio.mp3 we can create a new video file called Episode.mpg like this:

mencoder MOV002.mpg -o Episodetest.mpg -ovc copy -oac mp3lame
      -audiofile BetterAudio.mp3 -of mpeg

Voila!

Music Video Via a Mac

I don't usually post videos on my blog but ... wow.

Via 37Signals.

Song via the bird and the bee

FirstClown is powered by WordPress
Entries (RSS) and Comments (RSS).