简体   繁体   中英

Xuggler H264 FPS encoding issue

I'm trying to encode a series of images into an MP4 video with xuggler. However, trying to wrap my head around the timebase/framerate issues is driving me insane! I can't seem to get a decent video encoded. Using the Converter.java example, I have

IRational num = IRational.make(24, 1);
outStreamCoder.setFrameRate(num);
outStreamCoder.setTimeBase(IRational.make(num.getDenominator(),  num.getNumerator()));

...

long tsOffset = 0;
if (outStream.getStartTime() != Global.NO_PTS && outStream.getStartTime() > 0
            && outStream.getTimeBase() != null)
{
        IRational defTimeBase = IRational.make(1, (int) Global.DEFAULT_PTS_PER_SECOND);
        tsOffset = defTimeBase.rescale(outStream.getStartTime(), outStream.getTimeBase());
}

....

long timeStamp = (3600 * count); // experimenting
IVideoPicture outFrame = converter.toPicture(worksWithXugglerBufferedImage, timeStamp);
if (outFrame.getTimeStamp() != Global.NO_PTS)
    outFrame.setTimeStamp(outFrame.getTimeStamp() - tsOffset);

For 30 images, the encoded duration is far less than 1s. I'd expect it to be just over a second. Can anyone please help me, this has had me perplexed for some time now!

So it turns out I was being an idiot! I was assigning the frame a timeStamp based on the timebase of an H.264 encoded file: (1/90,000) ; I should really have just been assigned it a time in microseconds from the first frame. (eg a multiple of (1e6/fps) ). SO my code should have read:

IRational fps = IRational.make(24, 1);
outStreamCoder.setFrameRate(fps);
outStreamCoder.setTimeBase(IRational.make(fps.getDenominator(),  fps.getNumerator()));

...

long timeStamp = (1e6/fps.getNumerator() * count);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM