Wednesday, December 28, 2005

using ffmpeg to combine an audio and video file

In order to get my NYC video onto Google, I had to go through a number of steps to get it to a Google-acceptable MPEG2 format:
1) in XP, re-render the original Microsoft WMV file into an AVI using Adobe Premiere
2) again in XP, demux the AVI file (split apart into separate audio and video streams) using TMPGEnc into a DVD-ready, MPEG2 video stream (.m2v file) and a Windows waveform audio (.wav)
3) in Fedora, remux the video using ffmpeg:
ffmpeg -i OneWeekendInNYC.wav -i OneWeekendInNYC.m2v -target dvd -hq -minrate 8000000 -title "OneWeekendInNYC" -author "Crazed Mule Productions, Inc." -copyright "2005" -comment "Video of downtown NYC, summer 2005 with jazz accompaniment shot with JVC HD10U" OneWeekendInNYC.mpg

In the above example, ffmpeg has a number of inputs:
1) the audio file: -i OneWeekendInNYC.wav
2) the video file: -i OneWeekendInNYC.m2v
3) a target media type for the combined audio and video file: -target dvd
4) high quality transcode: -hq
5) a minimum bit rate for the compression: -minrate 8000000 (This doesn't seem to work based on the second to the last line of output which shows a lower average bitrate, below)
6) various descriptive metadata (-title "OneWeekendInNYC" -author "Crazed Mule Productions, Inc." -copyright "2005" -comment "Video of downtown NYC, summer 2005 with jazz accompaniment shot with JVC HD10U")
7) the filename of the combined audio and video streams: OneWeekendInNYC.mpg

Here is the output of that command. Note the input files, output filename and second to last line with the average bit rate. I believe the -target dvd overrides the -minrate option:
[root@computer video]# ffmpeg -i OneWeekendInNYC.wav -i OneWeekendInNYC.m2v -target dvd -hq -minrate 8000000 -title "OneWeekendInNYC" -author "Crazed Mule Productions, Inc." -copyright "2005" -comment "Video of downtown NYC, summer 2005 with jazz accompaniment shot with JVC HD10U" /root/OneWeekendInNYC.mpg
ffmpeg version 0.4.9-pre1, build 4753, Copyright (c) 2000-2004 Fabrice Bellard
Input #0, wav, from 'OneWeekendInNYC.wav':
Duration: 00:01:57.6, start: 0.000000, bitrate: 1536 kb/s
Stream #0.0: Audio: pcm_s16le, 48000 Hz, stereo, 1536 kb/s
Input #1, mpegvideo, from 'OneWeekendInNYC.m2v':
Duration: 00:01:57.6, start: 0.000000, bitrate: 7998 kb/s
Stream #1.0: Video: mpeg2video, yuv420p, 720x480, 29.97 fps, 7998 kb/s
Assuming NTSC for target.
Output #0, dvd, to '/root/OneWeekendInNYC.mpg':
Stream #0.0: Video: mpeg2video (hq), yuv420p, 720x480, 29.97 fps, q=2-31, 6000 kb/s
Stream #0.1: Audio: ac3, 48000 Hz, stereo, 448 kb/s
Stream mapping:
Stream #1.0 -> #0.0
Stream #0.0 -> #0.1
[mpeg2video @ 0x7f6a330]Warning min_rate > 0 but min_rate != max_rate isn't recommended!
Press [q] to stop encoding
frame= 3526 q=0.0 Lsize= 91494kB time=117.6 bitrate=6373.5kbits/s
video:83347kB audio:6431kB global headers:0kB muxing overhead 1.911009%

Obviously, there will be some loss of quality with these many rendering steps, but quality is not of primary importance when posting to Google video.

Hope this helps!
mule

Reference
FFMPEG HowTo

2 comments:

Unknown said...

Thanks for this wonderful post and hoping to post more of this blog here. I am a newbie to try this.

Aven, developer of how to convert avi to mov mac

Unknown said...

ffmpeg is great for converting and editing videos. I have been using it for editing mov video for long time.