[英]Xuggler H264 FPS encoding issue
I'm trying to encode a series of images into an MP4 video with xuggler. 我正在尝试使用xuggler将一系列图像编码为MP4视频。 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 使用
Converter.java
示例,我有
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. 对于30张图像,编码持续时间远远小于1秒。 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)
; 我正在基于H.264编码文件的
timebase
为帧分配一个timeStamp
: (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)
). (例如
(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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.