Log in

View Full Version : Encoding Video for Blu-Ray using H264/AVC


Pages : 1 [2] 3 4 5 6 7 8 9

Sharc
4th June 2010, 19:48
Thanks, and for reminding me of the --pic-struct.

kieranrk
10th June 2010, 05:18
I wrote a simple guide for the most common Blu-Ray scenarios. See my sig.

Lyris
10th June 2010, 22:20
Much appreciated, Kieran, good to know my tests have been BD compliant.

Can you advise me (and others) here - are the following encode settings also good?

16:9 "NTSC" 720x480 Secondary Video stream
I know the max bit rate here is quite conservative, that is my intention.

x264 --bitrate 3000 --pass 1 --preset veryslow --weightp 0 --bframes 3 --me umh --merange 24 --partitions all
--subme 10 --trellis 2 --rc-lookahead 60 --direct auto --ref 6 --nal-hrd vbr --vbv-maxrate 4000 --vbv-bufsize 6000
--level 3.2 --keyint 24 --b-pyramid strict --slices 1 --aud --colorprim "smpte170m" --transfer "smpte170m"
--colormatrix "smpte170m" --sar 40:33 infile.avs -o outfile.avc

x264 --bitrate 3000 --pass 2 --preset veryslow --weightp 0 --bframes 3 --me umh --merange 24 --partitions all
--subme 10 --trellis 2 --rc-lookahead 60 --direct auto --ref 6 --nal-hrd vbr --vbv-maxrate 4000 --vbv-bufsize 6000
--level 3.2 --keyint 24 --b-pyramid strict --slices 1 --aud --colorprim "smpte170m" --transfer "smpte170m"
--colormatrix "smpte170m" --sar 40:33 infile.avs -o outfile.avc

Standard Definition Primary video (for bonus features, etc)
I gather that since 23.976fps is not allowed for SD material on BD, we need to add some sort of 3:2 pulldown flag. Is the way X264 does this BD compliant?

shon3i
10th June 2010, 22:40
Can you advise me (and others) here - are the following encode settings also good?
Everything look good to me. Just advice about vbv, keep both value near each other. You can use --keyint 48 aslo.

Standard Definition Primary video (for bonus features, etc)
I gather that since 23.976fps is not allowed for SD material on BD, we need to add some sort of 3:2 pulldown flag. Is the way X264 does this BD compliant? Yes but need to be interlaced aslo. If you sourtce is 23.976p you can use fake interlaced with 3:2 pulldown.

kieranrk
11th June 2010, 04:19
Yes but need to be interlaced aslo. If you sourtce is 23.976p you can use fake interlaced with 3:2 pulldown.

I'm not 100% sure that will pass some verifiers. It's a very strict interpretation of the spec.

shon3i
11th June 2010, 06:55
I'm not 100% sure that will pass some verifiers. It's a very strict interpretation of the spec.
As long is 29.97i should pass, but if someone send me a sample i can verify

EDIT: i create my own 23.976p sample, encoded using fake interlaced and puldown 32 to produce 29.97i stream, but this file will not pass mui generator.

Blue_MiSfit
11th June 2010, 08:50
Maybe just forget about fake interlaced and only use pulldown??

Derek

mp3dom
11th June 2010, 08:57
23.98p to 29.97i via 3:2 pulldown is allowed. Probably the fake-interlaced is not needed in this case.

shon3i
11th June 2010, 08:57
Maybe just forget about fake interlaced and only use pulldown??

Derek
it's ok for secondary video, but for primary 720x480 must be interlaced (or fake interlaced)

mp3dom
11th June 2010, 09:16
Doesn't the pulldown already flag the stream as interlaced?

shon3i
11th June 2010, 09:20
Doesn't the pulldown already flag the stream as interlaced?
No, why should?

mp3dom
11th June 2010, 09:32
Because it's based on field repetition. At least, with MPEG-2 a progressive stream when a pulldown is applied, becomes interlaced with RFF.

kieranrk
11th June 2010, 15:11
Because it's based on field repetition. At least, with MPEG-2 a progressive stream when a pulldown is applied, becomes interlaced with RFF.

The underlying stream is still coded progressively with soft pulldown.


EDIT: i create my own 23.976p sample, encoded using fake interlaced and puldown 32 to produce 29.97i stream, but this file will not pass mui generator.

I also tried and it seemed to pass.

shon3i
12th June 2010, 12:20
I also tried and it seemed to pass. It's my mistake :p

Sharktooth
8th July 2010, 18:58
just a question... for what resolutions/frame rates combinations is --pic-struct required?

kieranrk
8th July 2010, 19:26
just a question... for what resolutions/frame rates combinations is --pic-struct required?

Anything interlaced (that includes --fake-interlaced). It can't harm to put it on anyway though.

mp3dom
8th July 2010, 19:48
Personally I always set pic-struct even for progressive contents as some verifiers complains about its absence.

Sharktooth
8th July 2010, 19:59
Thanks. One more question. If i have a 480p24 source how can i produce a blu-ray compatible stream? i mean, should i convert the framerate to 29,976? in that case how should i set the --pulldown option?

shon3i
8th July 2010, 20:01
you need to use pulldown with fake interlaced or interlaced

Sharktooth
8th July 2010, 20:04
ok, so i should set something like --pulldown 32 --fake-interlaced --pic-struct ... etc.

shon3i
8th July 2010, 20:08
ok, so i should set something like --pulldown 32 --fake-interlaced --pic-struct ... etc.
yes, but you maybe need first assume 24000/1001, because pulldown 32 on 24p source will more that 29.970fps.

Sharktooth
8th July 2010, 20:14
the problem is more like 24fps and 23.976 fps are usually referred as 24 fps...
so that's more a user problem than mine (i asked all those questions coz im creating megui presets for BD encoding).

Avisynth_challenged
22nd July 2010, 20:28
Hi all,

I have a Huffyuv YV12 avi (1920x1080p @23.976fps) that I wish to encode to H.264 using x264. I'm interested in Blu-ray compliance, so looked around the forum and found this page:

http://sites.google.com/site/x264bluray/

I'm thinking of using the command line:

x264 --bitrate XXXXX --preset veryslow --tune film --weightp 0 --bframes 3
--nal-hrd vbr --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24
--b-pyramid strict --slices 4 --aud --colorprim "bt709" --transfer "bt709"
--colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file

I have a several questions:

1. I recall that for MPEG2 standard def encodes, a rule-of-thumb for bitrate is...
Avg: 6000 Kbps, Max: 8000 Kbps, Min: 2000 Kbps (...assuming 720x480p @23.976fps)
What rule-of-thumb bitrates are used for high-def H.264 encodes (1920x1080p @23.976fps)?

2. When encoding MPEG2 for DVD authoring, 23.976fps sources need to include pulldown flags to set the framerate to 29.97fps (soft-telecine) in NTSC-land. Does an H.264 encode need to have pulldown flags to achieve soft-telecine as well? Does the command line need to be revised to invoke pulldown?

3. MPEG2 encoders can often be configured to have the MPEG2 output be either in dropframe timecode format or non-dropframe timecode format. Does x264 have this capability available as a command line switch?

Thank you very much for your help.

mp3dom
22nd July 2010, 21:12
1. There's no general rule for bitrate. You can go up to 40 Mbps if necessary, but you need to adhere to VBV. For 23.98p if you have a lot of space to waste, you can have an average bitrate of 35 Mbps and a max of 40 Mbps (just as example)

2. For HD sources, 23.98/24p are allowed without any soft-pulldown (this doesn't depends by h.264, but BD specs. You can have the same using MPEG2 or VC1 sources). For SD primary-video you need soft pulldown because only 50i/59.94i are allowed.

nm
22nd July 2010, 21:23
I have a several questions:

1. I recall that for MPEG2 standard def encodes, a rule-of-thumb for bitrate is...
Avg: 6000 Kbps, Max: 8000 Kbps, Min: 2000 Kbps (...assuming 720x480p @23.976fps)
What rule-of-thumb bitrates are used for high-def H.264 encodes (1920x1080p @23.976fps)?

I'd rather use rule-of-thumb CRF. Generally 20 is a good value to start with. If there's a need to fit the video within limited space, derive the necessary average bitrate from the allowed file size and video length.

2. When encoding MPEG2 for DVD authoring, 23.976fps sources need to include pulldown flags to set the framerate to 29.97fps (soft-telecine) in NTSC-land. Does an H.264 encode need to have pulldown flags to achieve soft-telecine as well?

Blu-ray supports straight 24000/1001 fps 1080p video without pulldown flags.

3. MPEG2 encoders can often be configured to have the MPEG2 output be either in dropframe timecode format or non-dropframe timecode format. Does x264 have this capability available as a command line switch?

Drop frame timecodes are an NTSC nuisance, not HD.

video_magic
24th July 2010, 05:39
....
1. I recall that for MPEG2 standard def encodes, a rule-of-thumb for bitrate is...
Avg: 6000 Kbps, Max: 8000 Kbps, Min: 2000 Kbps (...assuming 720x480p @23.976fps)
What rule-of-thumb bitrates are used for high-def H.264 encodes (1920x1080p @23.976fps)?
....

Select a range of say, 1500 frames, from your source video (i.e. by using the trim command from avisynth in your .avs script), to use as a test to choose your bitrate but so you don't have to spend the time doing your entire video repeatedly until you find the bitrate (and other settings you might tweak and test); try and select the range from a fairly typical or even quite challenging part of your video.

I suggest for 1920x1080p , 23.976fps you try 7000 bitrate, and also do another encode at 10000 (both with exactly the same settings). Compare them with each other and with the source. Try increments of 2000 after that; but in addition to bitrate of course you could consider any other x264 settings or what you might have going on processing-wise before x264 encodes it.

Sharc
6th August 2010, 23:49
According to the first post in this thread the SAR for 720x576 resolution should be 16:11. My standalone (SONY 360) plays it back at 64:45 however, i.e. a picture with a SAR of 16:11 and flagged as 16:11 in the stream is slighly sqeezed on playback.
It's not a big issue, but has anyone seen a Blu-Ray standalone player which really obeys the SAR as signalled in the stream?

kieranrk
7th August 2010, 02:48
According to the first post in this thread the SAR for 720x576 resolution should be 16:11. My standalone (SONY 360) plays it back at 64:45 however, i.e. a picture with a SAR of 16:11 and flagged as 16:11 in the stream is slighly sqeezed on playback.
It's not a big issue, but has anyone seen a Blu-Ray standalone player which really obeys the SAR as signalled in the stream?

There is an aspect ratio flag in the HDMV extensions of the TS container that might be set wrong.

Sharc
7th August 2010, 09:21
There is an aspect ratio flag in the HDMV extensions of the TS container that might be set wrong.
Ah, the container. How can I check if this flag is set? Can tsMuxer set this flag? I didn't find an option.

A.Fenderson
31st August 2010, 20:36
I see --mvrange 511 set on a lot of blu-ray profiles: is this strictly necessary, or does it just seem to improve compatibility on some players?

shon3i
1st September 2010, 13:37
I see --mvrange 511 set on a lot of blu-ray profiles: is this strictly necessary, or does it just seem to improve compatibility on some players?
That is because earler version of x264 are not limit mvrange to 511.75, which is now default value, and it's fine for Blu-Ray.

MasterNobody
1st September 2010, 18:16
That is because earler version of x264 are not limit mvrange to 511.75, which is now default value, and it's fine for Blu-Ray.
This was changed almost 3 years ago in revision 697 (http://git.videolan.org/gitweb.cgi?p=x264.git;a=commit;h=a2db19e6ca89f40b2523f6964832c69369a3ee29) which anyway wasn't Blu-Ray compatible so I don't see the reason why it still appears in Blu-Ray profiles.

Ulf
16th September 2010, 21:39
Encoding 720p25 or 720p29.97 with "--pulldown double" and 480p23.976 with "--pulldown 32 --fake-interlaced --pic-struct" will yield Bly-ray compatible streams (assuming the rest of the settings are OK). The question is what the maximum setting for "--keyint" would be in these cases for a 1s GOP? Is "--keyint" referring to the original frame rate or the pulldown framerate, i.e. to 25 or to 50 in the case of 720p25?

Sharc
16th September 2010, 22:01
Encoding 720p25 or 720p29.97 with "--pulldown double" .....
Have you been successful with 720p25 --pulldown double? I get jerky playback on my BD standalone unless I encode without b frames.

Ulf
17th September 2010, 09:09
I get jerky playback on my BD standalone unless I encode without b frames.

Have you seen a significant difference in playback of a 720p25 clip encoded with "--pulldown double" and the same clip with frame duplication done before encoding, i.e. AssumeFrameBased().ComplementParity().SelectEvery(1,0,0) ?

kieranrk
17th September 2010, 12:45
Encoding 720p25 or 720p29.97 with "--pulldown double" and 480p23.976 with "--pulldown 32 --fake-interlaced --pic-struct" will yield Bly-ray compatible streams (assuming the rest of the settings are OK). The question is what the maximum setting for "--keyint" would be in these cases for a 1s GOP? Is "--keyint" referring to the original frame rate or the pulldown framerate, i.e. to 25 or to 50 in the case of 720p25?

I'm not actually 100% sure. I always thought a GOP had to have actual frames in it so --keyint 50 would be correct for 720p25.

Sharc
17th September 2010, 23:54
Have you seen a significant difference in playback of a 720p25 clip encoded with "--pulldown double" and the same clip with frame duplication done before encoding, i.e. AssumeFrameBased().ComplementParity().SelectEvery(1,0,0) ?
I did frame duplication like:
AssumeFieldBased().AssumeTFF()
FieldDeinterlace().ChangeFPS(50)
which was ok.
I believe that the problem with b-frames and --pulldown double in my case is that the re-ordering of the b-frames for playback is not done. Maybe a problem of the decoder.

Added:
I tried your script. It works as well. No jerkiness.
Unfortunately the file size for same crf becomes 50% larger with the frame-doubling.

I still have problems with '--pulldown double' and b-frames. It works with MPC-HC but fails (i.e. jerky playback) with VLC and with my standalone - unless I encode without b-frames.

Midzuki
18th September 2010, 14:42
I still have problems with '--pulldown double' and b-frames. It works with MPC-HC but fails (i.e. jerky playback) with VLC and with my standalone - unless I encode without b-frames.

Does it make a difference if you set --bframes to 2 or to 1 http://forum.doom9.org/images/icons/icon5.gif
Or if you use --b-adapt 0 :confused:

Sharc
18th September 2010, 17:24
Does it make a difference if you set --bframes to 2 or to 1 http://forum.doom9.org/images/icons/icon5.gif
Or if you use --b-adapt 0 :confused:
Yes, it makes a difference.
--bframes 2 removes the backward-and-forward jerkiness. The playback is however still choppy in VLC. I didn't test on the standalone yet.
--bframes 1 is about the same
--b-adapt 0 does not make a difference.

Midzuki
18th September 2010, 18:23
Thanks for the clarification.
Now, what about:

for n b-frames, --keyint = integer multiple of n+1 ;

N.B., 25 is not an integer multiple of 4, 3, or 2. http://forum.doom9.org/images/icons/icon3.gif

--b-adapt 0 does not make a difference.

OK, but it won't hurt (much) if you use it, I guess. :)

Sharc
18th September 2010, 23:06
Thanks for the clarification.
Now, what about:

for n b-frames, --keyint = integer multiple of n+1 ;

N.B., 25 is not an integer multiple of 4, 3, or 2. http://forum.doom9.org/images/icons/icon3.gif



OK, but it won't hurt (much) if you use it, I guess. :)

I normally use --bframes 3 and --keyint 24, which actually does comply with your proposal: 3+1=4 6x4=24. Similar for --bframes 2: 2+1=3 8x3=24. So --keyint 24 should be ok.

Removing --b-pyramid strict seems to help. No backward/forward jerkyness, but still choppy (means progressive, but not very fluent).

Ulf
19th September 2010, 12:11
I'm not actually 100% sure. I always thought a GOP had to have actual frames in it so --keyint 50 would be correct for 720p25.

If --keyint refers to actual encoded frames, wouldn't --keyint 25 be correct for 720p25 even when applying soft telecine (for a 1s GOP)? Is any x264 programmer around to enlighten us?

nm
19th September 2010, 12:19
Is any x264 programmers around to enlighten us?

IIRC, kieranrk is responsible for x264's pulldown support. :)

mp3dom
19th September 2010, 20:45
I have a question for people that have the BD specs on their hands:
I need to encode to BD with (relatively) low max bitrate (about 21 Mbps, but surely not over 24 Mbps) because I've a lot of lossless/PCM audio tracks to use. To gain a little, my idea is to encode as L4.0 to have the possibility to use 1 slice only. The specs says that L4.0 allow a maxrate of 24 Mbps which is perfectly fine for my job. The question is: the BD allows me with a L4.0 video to have a total BD bitrate of 48 Mbps (21 Mbps video + 27 Mbps audio) or with L4.0 my max BD bitrate is more limited?

shon3i
19th September 2010, 21:17
Video level bitrate restriction has nothing with overall bitrate which always stay to 48mbps if data rate is least 54mbps. Data rate dictates maximum allowed bitrate for disc. In normal case you always have 48mbps, and lowering video or audio max rate will not change that, only will make more space for other streams.

mp3dom
19th September 2010, 21:29
Thank you very much!

Sharc
21st September 2010, 20:18
IIRC, kieranrk is responsible for x264's pulldown support. :)
His guides are here (http://sites.google.com/site/x264bluray/home/720p-encoding) :)
(I still have no luck with --pulldown double and b-frames, but this is perhaps just me ....)

shon3i
21st September 2010, 20:31
His guides are here (http://sites.google.com/site/x264bluray/home/720p-encoding) :)
(I still have no luck with --pulldown double and b-frames, but this is perhaps just me ....)
What you use as BD muxer?

EDIT: btw max keyint must be on real fps not pulldowned, so for 720p25 is 25 not 50, 50 is valid for 2 sec GOP

Sharc
21st September 2010, 21:54
ok, I may have found my problem:
I have to delete '--b-adapt x' from the command line.
I tried
'--b-adapt 0' => jerky
'--b-adapt 1' => jerky
'--b-adapt 2' => jerky
removing '--b-adapt ... ' helped. Playback ok with MPC-HC and with VLC.
Now I still have to test with my standalone. I will report back.

And thanks shon3i for the clarification about the --keyint with pulldown.

shon3i
21st September 2010, 22:05
@Sharc it's Tsmuxer problem. Obviously has a problem with pulldown streams.

I do a simple test, i encode video with pulldown, i muxed it with scenarist and tsmuxer. tsmuxer's stream show jerky playback, while scenarist play smooth.