
ou401cru02 at sneakemail
Dec 9, 2003, 12:23 PM
Post #27 of 28
(1852 views)
Permalink
|
|
Re: A prelude to transcoding MPEG2->MPEG2
[In reply to]
|
|
On Tue, 09 Dec 2003 00:58:25 -0700, "Craig Rindy" said: > I am using GOPchop 0.9.1 with one minor modification to avoid an endless > loop because I'm using Gentoo's libmpeg2-0.3.2_pre20030625 ebuild and > GOPchop 0.9.1 was written against mpeg2dec version 0.3.1. All of my > streams are 720x480 with a bitrate of 4 Mbps default or 8 Mbps for high > quality. > Note that all that I am currently doing is reimplementing GOPchop from scratch. There are two reasons for wasting my time on this: 1) From my understanding (and what I've gleaned from the code), GOPchop plays some nasty tricks to do its job. For instance it doesn't demux the audio and video before chopping. Maybe it does, but I don't think so from my understandingof how it works. which leads us to... 2) the MPEG2 format is quite complex, and trying to understand it from a piece of code which doesn't directly implement the spec is not easy. By writing all the code myself, I am learning how the format goes together, which should make everytihng a lot easier down the road. After all this, I'd really like to find a way to use libavformat to decode the streams, since getting all the corner-cases right is a real pain. Anyhow, I have been able to successfully take a stream, seperate audio and video, and clip the video and audio. I have yet to determine how to remux the streams successfully. The problem is that the mpeg-audio format has a fixed number of samples per frame (for mp2, it is 1152). At 48kHZ, this is .024 sec (at 32kHz it is .036 sec). However, the video frames have a resolution of about 1/29.97 = .033 or 1/25 = .04 sec. So after doing a cut, I can only guarantee A/V sync up-to about .012 sec for 48kHZ, .018sec for 32kHZ audio. This means that the audio may be off by as much as ~0.5 of a video frame. If I get it all right, it should not be an additive affect, but it isn't perfect. I don't know if that is a noticable delta or not to be honest. The fix appears to be to adjust the time-offsets during muxing, but I'm not sure if all decoders will honour those time-offsets. .Geoff
|