我正在尝试使用 ffmpeg 以恒定的比特率将视频编码为 H.264(通过 libx264 库)。我知道,我知道,VBR 通常是首选,但对于这个特定的工作,我需要使用 CBR(只要它是每秒这么多千字节;据我所知,它不必是每帧精确的千字节) 。我用来测试的示例视频来自这里: http://a1408.g.akamai.net/5/1408/1388/2005110403/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_iTunes.mov.zip(它来自http://support.apple.com/kb/HT1425)
我在编码时可以获得恒定的比特率具有 MPEG-4 视频的视频(使用命令 ffmpeg -i Sample_iTunes.mov -b 819968 -minrate 819968 -maxrate 819968 out.mov
),并且比特率符合预期。通过 QuickTime Inspector 读取视频的规格,其数据速率为 844.94 kbit/s。凉爽的。
然而,当我将编解码器更改为 libx264 时,它似乎完全忽略了我的比特率请求!我正在尝试的命令是“ffmpeg -i example_iTunes.mov -vcodec libx264 -vpremedium -b 819968 -vb 819968 -minrate 819968 -maxrate 819968 -bufsize 400000 test.mov”。但当我通过 QuickTime Inspector 检查视频的规格时,它的数据速率为 254.74 kbit/s。搞什么?那还差得远呢!
我尝试过更改如此多的参数并添加大量不同的东西,我花了两天的时间在谷歌上搜索这个,但我似乎无法让它工作。如果我使用 MainConcept H.264 编码器对视频进行编码,我可以获得恒定的比特率,但我需要它与 ffmpeg 一起使用。
如果有人能帮我弄清楚如何使用 FFmpeg 进行 CBR H.264 编码,我将永远爱你!
I'm trying to encode a video with ffmpeg into H.264 (via the libx264 library) with a constant bit rate. I know, I know, VBR is often preferred, but for this specific job I'm required to use CBR (just as long as it's so many kilobytes per second; it doesn't have to be an exact kilobytes per frame, afaik). My sample video I'm using to test is from here: http://a1408.g.akamai.net/5/1408/1388/2005110403/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_iTunes.mov.zip (it comes from http://support.apple.com/kb/HT1425)
I can get a constant bit rate when encoding the video with MPEG-4 Video (using the commands ffmpeg -i sample_iTunes.mov -b 819968 -minrate 819968 -maxrate 819968 out.mov
), and the bit rate is as expected. Reading the video's specs via the QuickTime Inspector, it's got a data rate of 844.94 kbit/s. Cool.
However, when I change the codec to libx264, it seems to completely ignore my bitrate requests! The command I'm trying is "ffmpeg -i sample_iTunes.mov -vcodec libx264 -vpre medium -b 819968 -vb 819968 -minrate 819968 -maxrate 819968 -bufsize 400000 test.mov
". But when I check the video's specs via the QuickTime Inspector, it's got a data rate of 254.74 kbit/s. WTF? That's not even close!
I've tried changing so many parameters and adding tons of different things, and I've spent 2 days googling this, but I can't seem to get it to work. If I encode the video with the MainConcept H.264 encoder, I can get a constant bitrate, but I need this to work with ffmpeg.
If someone can help me figure out how to do CBR H.264 encoding with FFmpeg, I will love you forever!
发布评论
评论(4)
我也一直致力于将 CBR 从 x264 中剔除。我发现 Dark Shakari 的这篇博客帖子非常有趣。
以下是我将低延迟 CBR 视频转换为 MPEG 传输流的方法:
根据您设置的 x264 开发人员博客:
最后,将 ffmpeg 开关设置为 -tune Zerolatency 的 x264。
希望这有帮助。而且,如果有人对此有改进,请告诉我!
I too have been working on trying to get CBR out of x264. I found this blog post by Dark Shakari quite interesting.
Here is what I have for low-latency CBR video to an MPEG tranport stream:
According the x264 developer's blog you set:
Finally, set the ffmpeg switch for x264 of -tune zerolatency.
Hope that's helpful. And, if anyone has improvements to this please do let me know!
在
-bufsize 400000
之后指定-nal-hrd cbr
。Specify
-nal-hrd cbr
after-bufsize 400000
.好的,所以我想我可能已经找到了部分问题。使 -bufsize 大于数据速率似乎已经解决了问题。当然,我不知道它是否编码真实 CBR,但 Quick Time Inspector 读取的数据速率现在看起来是正确的。
Ok, so I think I may have found part of the problem. Making -bufsize greater than the data rate seems to have solved the problem. Of course, I don't know if it's encoding real CBR, but the data rate that Quick Time Inspector reads looks right now.
这可能是一条线索(假设您设置了比特率)“CBR 是指设置了 maxrate == bitrate 和 bufsize”http://ffmpeg-users.933282.n4.nabble.com/Does-constant-bitrate-exist-in-libx264-td2255554.html
bufsize 应该是“接收客户端的“最大缓冲区大小。
This may be a clue (assuming you have a bitrate set) "CBR is when maxrate == bitrate and bufsize is set" http://ffmpeg-users.933282.n4.nabble.com/Does-constant-bitrate-exist-in-libx264-td2255554.html
bufsize is supposed to be the "receiving client's" max buffer size.