gpt4 book ai didi

java - Xuggler H264 FPS 编码问题

转载 作者:行者123 更新时间:2023-12-01 05:35:52 24 4
gpt4 key购买 nike

我正在尝试使用 xuggler 将一系列图像编码为 MP4 视频。然而,试图解决时基/帧速率问题让我发疯!我似乎无法获得像样的视频编码。使用 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);

对于 30 张图像,编码时长远小于 1 秒。我预计它只会一秒钟多一点。谁能帮帮我,这让我困惑了一段时间了!

最佳答案

原来我是个白痴!我根据 H.264 编码文件的 timebase 为帧分配一个 timeStamp:(1/90,000);我真的应该从第一帧开始分配一个以微秒为单位的时间。 (例如 (1e6/fps) 的倍数)。所以我的代码应该是:

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

...

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

关于java - Xuggler H264 FPS 编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8217088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com