Blu-ray encoding again
Hi! With Marton's patches from git clone -b mpegts https://github.com/cus/ffmpeg/ and CinGG compiled with ffmpg.git I _nearly_ got some rendering. But option files still needed some modification For example I was running into x264 errors. cin Cinelerra Infinity - built: Nov 14 2019 14:17:05 git://git.cinelerra-gg.org/goodguy/cinelerra.git (c) 2006-2019 Heroine Virtual Ltd. by Adam Williams (c) 2007-2019 cin5 derivative by W.P. Morrow aka goodguy Cinelerra is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. There is absolutely no warranty for Cinelerra. Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl [libx264 @ 0xe9a3c4c0] interlace + weightp is not implemented [libx264 @ 0xe9a3c4c0] using mv_range_thread = 88 [libx264 @ 0xe9a3c4c0] NAL HRD parameters require VBV parameters [libx264 @ 0xe9a3c4c0] using SAR=1/1 [libx264 @ 0xe9a3c4c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX XOP FMA3 BMI1 [libx264 @ 0xe9a3c4c0] profile High, level 4.1 Device type none is not supported. Available device types: vdpau cuda vaapi opencl FFMPEG::encode_activate: write header failed /dev/shm//bd_20191114-163217/bd.m2ts err: Недопустимый аргумент Render::render_single: Session finished. Device type none is not supported. Available device types: vdpau cuda vaapi opencl some of them were fixed by applying parameters from http://www.x264bluray.com/home/1080i-p [libx264 @ 0xe0609640] using mv_range_thread = 88 [libx264 @ 0xe0609640] using SAR=1/1 [libx264 @ 0xe0609640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX XOP FMA3 BMI1 [libx264 @ 0xe0609640] HRD bitrate: 40000000 bits/sec [libx264 @ 0xe0609640] CPB size: 30000000 bits [libx264 @ 0xe0609640] profile High, level 4.1 [SWR @ 0xcfba81c0] Using fltp internally between filters Device type none is not supported. Available device types: vdpau cuda vaapi opencl Render::render_single: Session finished. but there still warning at ffmpeg site about deprecation of x264opts: https://trac.ffmpeg.org/wiki/Encode/H.264 Warning: Do not use the option x264opts, as it will eventually be removed. Use x264-params instead. --- /usr/share/cin/ffmpeg/video/bluray.m2ts 417/417 100% bluray libx264 bluray-compat=1 id=0x1011 level=41 bf=2 fake-interlaced=1 bitrate=40000 slices=4 sar=1:1 # vbv-maxrate=40000 # vbv-bufsize=30000 refs=3 cin_pix_fmt=yuv420p color_range=mpeg colorspace=bt709 color_trc=bt709 color_primaries=bt709 profile=high preset=medium flags=+cgop # must be last for bdcreate.C x264opts keyint=25:min-keyint=4:qpmin=3:qpmax=33:qp_step=4:merange=8:vbv-maxrate=40000:vbv-bufsize=30000 --- /usr/share/cin/ffmpeg/format/bluray 129/129 100% mpegts mpegts_m2ts_mode=1 mpegts_start_pid=1024 mpegts_pmt_start_pid=256 muxrate 1 #sdt_period=-1 packetsize 2048 preload 500000 But please note some x264 params actually should vary for interlaced or progressive, 25 vs 30 fps: 1080p Primary and Secondary Streams 1080p23.976 / 1080p24 x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file NB: the following two streams are encoded using fake-interlaced mode. This allows the stream to be encoded progressively yet flagged as interlaced. 1080p25 x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file 1080p29.97 x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file 1080i Primary and Secondary Streams (assumes top field first) 1080i25 x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file 1080i29.97 / 1080i30 x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file so, keyint must be dynamically-selected, depending on profile you (user) choose, and fake_interlaced must be present for progressive encodings More on those constrains, refering same page: https://av.community/guides/encoding-video-for-blu-ray-using-h264-avc/ "8-bit (4:2:0) Colorspace is only allowed Main and High profiles are allowed Maximum 3 B-Frames is allowed NAL-HRD Type 2 capable encoder is needed" note, according to some comments around vbv-bufsize you can mux to DVD, so test this, too? "vbv-maxrate Maximum allowed bitrate. Depend of destination media, for normal BD Media, maximum settings is allowed (40000), while for DVD Media (eg BD-5 or BD-9) there is no maximum per Blu-Ray specification, but is strongly recommended that use less or equal to 15000, since DVD reading is slower."
the log messages for dev type are a bug, but it does not fail the render. The function: AVHWDeviceType FFVideoStream::decode_hw_activate() is using the translation for "none" to detect the intent not to use the hw. if( hw_dev && *hw_dev && strcmp(_("none"), hw_dev) ) { Apparently your init is applying the english version, as it is in the log msg. The result of the hw probe is the same in both cases, and is not a fail. *I will change this to check both with and without get_text() so that it* *will not report if LANG is not applied.* "Warning: Do not use the option x264opts, as it will eventually be removed. Use x264-params instead." *ok. we will change that.* f*or bluray_format, mpegts_m2ts_mode=1 *(changed to 2 by me) causes the transport stream to set the transport_priority flag if the packet is audio ac3, which is sort of a kludge... but this is necessary to get audio to reproduce on my home bluray player (samsung ubd-k8500). This was discovered by checking the diff between the ffmpeg output (which fails on player) and the "sintel" iso file from blender site (which works on player). The mode=2 triggers mode=1 and add the transport_priority flag for ac3 audio. It definitely helps here at home. Similarly, *sdt_period=-1* turns off the service descriptor table output, since this is not a broadcast stream. I am not an expert on mpegts and these changes work for me. If you have better information, let me know. *for bluray.m2ts*, you have added fake-interlaced=1 bitrate=40000 slices=4 sar=1:1 # vbv-maxrate=40000 # vbv-bufsize=30000 cin_pix_fmt=yuv420p x264opts ... vbv-maxrate=40000:vbv-bufsize=30000 These are all good, except that bitrate is computed in bdcreate.C and set in the codec parameters for avcodec_open2 call (of open_encoder). Recently we discovered that the "bitrate" param does not always work (change applied 20190922 git e620b69f). If it is specified, it seems to override the codec params (at least in some cases) and the computed rate (that prevents the disc from overflowing) is lost. If you are sure, I can add this, but I do not recommend it. Phyllis is going to try these changes, and if they work here at home, then they are good. Thanks for the good work. Stay tuned. gg
В сообщении от Thursday 14 November 2019 19:59:16 Good Guy написал(а):
the log messages for dev type are a bug, but it does not fail the render. The function: AVHWDeviceType FFVideoStream::decode_hw_activate() is using the translation for "none" to detect the intent not to use the hw. if( hw_dev && *hw_dev && strcmp(_("none"), hw_dev) ) { Apparently your init is applying the english version, as it is in the log msg. The result of the hw probe is the same in both cases, and is not a fail. *I will change this to check both with and without get_text() so that it* *will not report if LANG is not applied.*
Oh, this is cosmetical issue (I hope), but thanks for caring about those messages ..and users!
"Warning: Do not use the option x264opts, as it will eventually be removed. Use x264-params instead." *ok. we will change that.*
f*or bluray_format, mpegts_m2ts_mode=1 *(changed to 2 by me) causes the transport stream to set the transport_priority flag if the packet is audio ac3, which is sort of a kludge... but this is necessary to get audio to reproduce on my home bluray player (samsung ubd-k8500). This was discovered by checking the diff between the ffmpeg output (which fails on player) and the "sintel" iso file from blender site (which works on player). The mode=2 triggers mode=1 and add the transport_priority flag for ac3 audio. It definitely helps here at home. Similarly, *sdt_period=-1* turns off the service descriptor table output, since this is not a broadcast stream. I am not an expert on mpegts and these changes work for me. If you have better information, let me know.
I'm not expert too, but may be Marton can explain to us if those changes acceptable in upstream, or they must be done as separate parameters ..
*for bluray.m2ts*, you have added fake-interlaced=1 bitrate=40000 slices=4 sar=1:1 # vbv-maxrate=40000 # vbv-bufsize=30000 cin_pix_fmt=yuv420p x264opts ... vbv-maxrate=40000:vbv-bufsize=30000
These are all good, except that bitrate is computed in bdcreate.C and set in the codec parameters for avcodec_open2 call (of open_encoder). Recently we discovered that the "bitrate" param does not always work (change applied 20190922 git e620b69f). If it is specified, it seems to override the codec params (at least in some cases) and the computed rate (that prevents the disc from overflowing) is lost. If you are sure, I can add this, but I do not recommend it.
No, I think I just used "bitrate" trying to make encoder work. Just tried without this parameter - it still works
Phyllis is going to try these changes, and if they work here at home, then they are good.
I think you can keep format/bluray with ffmpeg-4.2 (modified by your version of patch), and only alter video/bluray.m2ts One thing at a time (also, if your player accept DVD-R you can save on BD disk...) I think bdcreate.C can be modified around lines 330/331 to automagically add fake-interlaced=1 to options IF BD profile set to progressive ... But conditionally replacing keyint=25 with another string..I don't know how to do this, found this example on the net: https://www.linuxquestions.org/questions/programming-9/replace-a-substring-w... #include <stdio.h> #include <string.h> char *replace_str(char *str, char *orig, char *rep) { static char buffer[4096]; char *p; if(!(p = strstr(str, orig))) // Is 'orig' even in 'str'? return str; strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$ buffer[p-str] = '\0'; sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig)); return buffer; } int main(void) { puts(replace_str("Hello, world!", "world", "Miami")); return 0; } so, in our case str will be options string, orig will be keyint=25 (from opts file) and rep will be some value derived from selected BD profile ... I think ...
Thanks for the good work. Stay tuned.
I will!
gg
Andrew, GG has been working on an integration of some of the ffmpeg Blu-ray patches because it looks like they have stabilized. He checked in final patches to GIT which incorporated what worked so things are cleaner and more similar now. We tested on 2 different bluray viewing devices and encountered no problems. This was worked on for about 3 days but should be done now for awhile anyway. I know this is a low use Cinelerra feature BUT we use it ourselves so it is important to us. With Marton's patches from git clone -b mpegts
https://github.com/cus/ffmpeg/ and CinGG compiled with ffmpg.git I _nearly_ got some rendering.
But option files still needed some modification
For example I was running into x264 errors.
cin Cinelerra Infinity - built: Nov 14 2019 14:17:05 git://git.cinelerra-gg.org/goodguy/cinelerra.git (c) 2006-2019 Heroine Virtual Ltd. by Adam Williams (c) 2007-2019 cin5 derivative by W.P. Morrow aka goodguy Cinelerra is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. There is absolutely no warranty for Cinelerra.
Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl Device type none is not supported. Available device types: vdpau cuda vaapi opencl [libx264 @ 0xe9a3c4c0] interlace + weightp is not implemented [libx264 @ 0xe9a3c4c0] using mv_range_thread = 88 [libx264 @ 0xe9a3c4c0] NAL HRD parameters require VBV parameters [libx264 @ 0xe9a3c4c0] using SAR=1/1 [libx264 @ 0xe9a3c4c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX XOP FMA3 BMI1 [libx264 @ 0xe9a3c4c0] profile High, level 4.1 Device type none is not supported. Available device types: vdpau cuda vaapi opencl FFMPEG::encode_activate: write header failed /dev/shm//bd_20191114-163217/bd.m2ts err: Недопустимый аргумент Render::render_single: Session finished. Device type none is not supported. Available device types: vdpau cuda vaapi opencl
some of them were fixed by applying parameters from
http://www.x264bluray.com/home/1080i-p
[libx264 @ 0xe0609640] using mv_range_thread = 88 [libx264 @ 0xe0609640] using SAR=1/1 [libx264 @ 0xe0609640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX XOP FMA3 BMI1 [libx264 @ 0xe0609640] HRD bitrate: 40000000 bits/sec [libx264 @ 0xe0609640] CPB size: 30000000 bits [libx264 @ 0xe0609640] profile High, level 4.1 [SWR @ 0xcfba81c0] Using fltp internally between filters Device type none is not supported. Available device types: vdpau cuda vaapi opencl Render::render_single: Session finished.
but there still warning at ffmpeg site about deprecation of x264opts:
https://trac.ffmpeg.org/wiki/Encode/H.264 Warning: Do not use the option x264opts, as it will eventually be removed. Use x264-params instead.
--- /usr/share/cin/ffmpeg/video/bluray.m2ts
417/417 100% bluray libx264 bluray-compat=1 id=0x1011 level=41 bf=2 fake-interlaced=1 bitrate=40000 slices=4 sar=1:1 # vbv-maxrate=40000 # vbv-bufsize=30000 refs=3 cin_pix_fmt=yuv420p color_range=mpeg colorspace=bt709 color_trc=bt709 color_primaries=bt709 profile=high preset=medium flags=+cgop # must be last for bdcreate.C x264opts keyint=25:min-keyint=4:qpmin=3:qpmax=33:qp_step=4:merange=8:vbv-maxrate=40000:vbv-bufsize=30000
--- /usr/share/cin/ffmpeg/format/bluray
129/129 100% mpegts mpegts_m2ts_mode=1 mpegts_start_pid=1024 mpegts_pmt_start_pid=256 muxrate 1 #sdt_period=-1 packetsize 2048 preload 500000
But please note some x264 params actually should vary for interlaced or progressive, 25 vs 30 fps:
1080p Primary and Secondary Streams
1080p23.976 / 1080p24
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 24 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file
NB: the following two streams are encoded using fake-interlaced mode. This allows the stream to be encoded progressively yet flagged as interlaced.
1080p25
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file
1080p29.97
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file
1080i Primary and Secondary Streams (assumes top field first)
1080i25
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file
1080i29.97 / 1080i30
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file
x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --tff --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.file
so, keyint must be dynamically-selected, depending on profile you (user) choose, and fake_interlaced must be present for progressive encodings
More on those constrains, refering same page: https://av.community/guides/encoding-video-for-blu-ray-using-h264-avc/
"8-bit (4:2:0) Colorspace is only allowed Main and High profiles are allowed Maximum 3 B-Frames is allowed NAL-HRD Type 2 capable encoder is needed"
note, according to some comments around vbv-bufsize you can mux to DVD, so test this, too? "vbv-maxrate Maximum allowed bitrate. Depend of destination media, for normal BD Media, maximum settings is allowed (40000), while for DVD Media (eg BD-5 or BD-9) there is no maximum per Blu-Ray specification, but is strongly recommended that use less or equal to 15000, since DVD reading is slower." -- Cin mailing list [email protected] https://lists.cinelerra-gg.org/mailman/listinfo/cin
participants (3)
-
Andrew Randrianasulu -
Good Guy -
Phyllis Smith