使用FFmpeg编码H.264 CBR视频 [英] Encoding H.264 CBR videos with FFmpeg

查看:393
本文介绍了使用FFmpeg编码H.264 CBR视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ffmpeg的视频以恒定的比特率编码为H.264(通过libx264库).我知道,我知道VBR通常是首选,但是对于此特定工作,我需要使用CBR(只要每秒这么多的千字节;不必每帧精确地千字节,afaik).我用来测试的示例视频来自此处:

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)

使用MPEG-4视频编码视频时,我可以获得恒定的比特率(使用命令 ffmpeg -i sample_iTunes.mov -b 819968 -minrate 819968 -maxrate 819968 out.mov ),和比特率是预期的.通过QuickTime检查器读取视频的规格,其数据速率为844.94 kbit/s.很好.

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.

但是,当我将编解码器更改为libx264时,似乎完全忽略了我的比特率请求!我正在尝试的命令是" ffmpeg -i sample_iTunes.mov -vcodec libx264 -vpre medium -b 819968 -vb 819968 -minrate 819968 -maxrate 819968 -bufsize 400000 test.mov ".但是,当我通过QuickTime检查器检查视频的规格时,其数据速率为254.74 kbit/s.WTF?还差得远!

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!

我尝试更改这么多参数并添加了许多不同的东西,并且花了2天的时间进行了谷歌搜索,但似乎无法正常工作.如果我使用MainConcept H.264编码器对视频进行编码,则可以获得恒定的比特率,但是使用ffmpeg时需要使用此比特率.

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.

如果有人可以帮助我弄清楚如何使用FFmpeg进行CBR H.264编码,我将永远爱你!

If someone can help me figure out how to do CBR H.264 encoding with FFmpeg, I will love you forever!

推荐答案

我也一直在努力从x264中获取CBR.我发现Dark Shakari撰写的该博客帖子非常有趣.

I too have been working on trying to get CBR out of x264. I found this blog post by Dark Shakari quite interesting.

这里是我将低延迟CBR视频转换成MPEG传输流的方法:

Here is what I have for low-latency CBR video to an MPEG tranport stream:

ffmpeg -i sintel_trailer-720p.mp4 -an -tune zerolatency \
       -x264opts bitrate=4000:vbv-maxrate=4000:vbv-bufsize=166 \
       -vcodec libx264 -f mpegts -muxrate 4000K -y trailer.ts

根据您设置的x264开发者博客:

According the x264 developer's blog you set:

  • vbv-maxrate =比特率= B =目标比特率
  • vbv-bufsize = B/fps(在此视频中为24 fps)

最后,为-tune zerolatency的x264设置ffmpeg开关.

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!

这篇关于使用FFmpeg编码H.264 CBR视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆