Log in

View Full Version : Encoding for Streaming Boxes


JK1974
16th October 2012, 11:46
Hi,

I want to encode MP4-AVC files with ffmpeg that should work on streaming settop boxes or TV sets. As the source is PAL-SD resolution, I though about starting with the information at https://sites.google.com/site/x264bluray/home/576i-pal.

But, in my case, several parameters are different. As the devices are not Blu-ray players (even if they might use the same chipsets) and the data is streamed by broadband internet connection and not delivered at a fixed rate from a physical media, I am first not sure what vbv values are best to take.
If I understand correctly, --vbv-maxrate limits the rate at which the buffer is being filled. But because I donīt know the internet speed of the users, wouldnīt it be best set it to a maximum value, e.g. 40000 like with Blu-ray encodings, to fill the buffer at the highest possible speed?
Second: What do I set as --vbv-bufsize? The example at http://mewiki.project357.com/wiki/X264_Encoding_Suggestions tells me that it would be best to set it to a minimum to avoid long buffering times. Other guides tell me that the vbv should be big enough to hold a full gop (I have currently set the keyint to 25, so it wouldnīt be too big).
Finally: The option --vbv-init does not seem to work with ffmpeg - simply seems to be ignored, even with the -x264ops option.

Another question concerning format compatibility has to do with the format profile and the codec-id. MediaInfo talks about "Base Media / Version 2" and "mp42" on a lot of files (e.g. rendered with Adobe Media Encoder), while ffmpeg encodings are said to have the format profile "Base Media" and codec-ID "isom". Is this just meta-data (as I have read on several pages) or can this have a bigger impact on compatibility?

Last, but not least: The Blu-ray x264 example commands use the parameters --colorprim "bt470bg" --transfer "bt470bg" --colormatrix "bt470bg"If I encode an MPEG-2 file to MP4-AVC using ffmpeg, MediaInfo tells me:colour_primaries : BT.601 PAL
transfer_characteristics : BT.470 System B, BT.470 System G
matrix_coefficients : BT.601

Is the result really correct? I have also read that BT.470-2 corresponds to BT.601... I have also seen a lot of encodings where MediaInfo does not print any information about those colour parameters, so I donīt think that this really causes incompatibilities if I leave it out.

Thank you very much in advance for any hints!

sneaker_ger
16th October 2012, 20:34
If I understand correctly, --vbv-maxrate limits the rate at which the buffer is being filled.

Correct.

But because I donīt know the internet speed of the users, wouldnīt it be best set it to a maximum value, e.g. 40000 like with Blu-ray encodings, to fill the buffer at the highest possible speed?

That won't do. You have to use a value that fits your users internet connection. Most sites offer different resolutions/bitrates to cover most users. ( e.g. 500 kbit/s mobile, 1.5 Mit/s slow broadband, 6 Mbit/s High Quality)
If you don't do that the user experience on your site will be bad, because streams can pause and go back to buffering in the middle of a video.

Second: What do I set as --vbv-bufsize? The example at http://mewiki.project357.com/wiki/X264_Encoding_Suggestions tells me that it would be best to set it to a minimum to avoid long buffering times. Other guides tell me that the vbv should be big enough to hold a full gop (I have currently set the keyint to 25, so it wouldnīt be too big).

Make it a few seconds long. That way the encoder has a big enough buffer to work with and users will only have to wait max. those few seconds at the beginning before the video will play.
I wouldn't use a short GOP like 25 if I'm not forced to do it. (Blu-Ray forces max. 1 or 2 second GOP, but you are not doing Blu-Ray.)

Last, but not least: The Blu-ray x264 example commands use the parameters --colorprim "bt470bg" --transfer "bt470bg" --colormatrix "bt470bg"If I encode an MPEG-2 file to MP4-AVC using ffmpeg, MediaInfo tells me:colour_primaries : BT.601 PAL
transfer_characteristics : BT.470 System B, BT.470 System G
matrix_coefficients : BT.601

Is the result really correct? I have also read that BT.470-2 corresponds to BT.601... I have also seen a lot of encodings where MediaInfo does not print any information about those colour parameters, so I donīt think that this really causes incompatibilities if I leave it out.

Those are optional, but it is recommended to set them to the correct values. If you don't know the correct values for your material, don't use them.

Asmodian
16th October 2012, 21:13
If I understand correctly, --vbv-maxrate limits the rate at which the buffer is being filled. But because I donīt know the internet speed of the users, wouldnīt it be best set it to a maximum value, e.g. 40000 like with Blu-ray encodings, to fill the buffer at the highest possible speed?

Just belaboring a point sneaker_ger already made.

Don't think of it as the rate the buffer is being filled but the rate at which the buffer needs to be filled to avoid stalling the video. This allows the video's bit-rate to be higher than the vbv-maxrate but only as long as there is enough data in the buffer to not stall the video.

An example: --vbv-maxrate at 10000 kbps and --vbv-bufsize at 15000 kb

Internet connection gives 12000 kbps.

This means:
buffer takes 15000/12000 seconds to fill.
If for 1/2 a second the bit-rate spikes up to (bufsize)+(maxrate/2)=20000 kbps the buffer will empty down to 1000 kb (all the internet connection can deliver over the vbv-maxrate in 1/2 a second) and the bit-rate of the next bit of the video will be less than or equal to 10000 kbps. The bit-rate will not go above the 20000 kbps for 1/2 a second because the buffer would underflow if only filled at the vbv-maxrate of 10000 kbps. Sorry if I have made things less clear rather than helping. :o

JK1974
17th October 2012, 15:54
Thank you very much for your help.

If I understand correctly, I have to set --vbv-maxrate to a value of an "ensured" broadband rate. So, if I claim 2 MBit/s to be the minimum, I could set --vbv-maxrate to 1750 kBit/s.

But if the video data rate is aimed to be at 1500 kBit/s and is never going above 1750 kBit/s, does using higher vbv values like 1750 kBit/s in this example really make sense? Wouldnīt the encoder never degrade the video bitrate because 1750 kBit/s is never reached?

Or are these vbv buffer settings in fact meant for situation where the video bitrate is very close to the bandwith limits or might be influenced due to read errors in case of physical media like Blu-ray?

Asmodian
17th October 2012, 18:55
If the video never hits the --vbv-maxrate, even for very short periods of time, there is no need to setup VBV. However, I would be surprised if a 2-pass encode targeting 1500kbps didn't get above 1750kbps for even longish periods of time (10s of seconds) without VBV.

I set VBV any time I am targeting something with a limited data rate, pretty much everything but a PC.

Blue_MiSfit
19th October 2012, 02:08
If you're streaming, you definitely want to use VBV. Trust me on this one :)

I'd suggest using at least one second of buffer, and ideally 2-3 seconds. Setting vbv-maxrate equal to bitrate is reasonable (pseudo CBR), but experiment with this.

Use a long GOP size (at least a few seconds), unless you're obsessed with seeking granularity.

JK1974
19th October 2012, 13:39
Itīs not really because of seeking granularity, I want to optimize the playback starting time and allow seeking within the stream as fast as possible, even if the playback has completely been stopped i.e. continuing the stream after it has been stopped at a given starting point.
Currently, there is a delay of 3-8 seconds (depending on the device), and this is by far too much in my opinion. But as I can see, the existing streams have not yet really been optimized, thatīs why I try to...

smok3
19th October 2012, 19:12
just tested dumb streaming (barebone apache to chrome html5 player over lan), using 720p25 mp4 file encoded with no limits on buffering and no limits on I frames;

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings, CABAC : Yes
Format settings, ReFrames : 4 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1h 21mn
Bit rate mode : Variable
Bit rate : 4 347 Kbps
Width : 1 280 pixels

and the seeking anywhere in the file take from 0.5 to 2 seconds, which would make me test your boxes in perfect bandwidth enviroment first, just to see how much the buffer settings are actually related to seeking speed (perhaps the dumbest device needs its 8 seconds even in perfect enviroment).