bbc / bmx

Library and utilities to read and write broadcasting media files. Primarily supports the MXF file format
BSD 3-Clause "New" or "Revised" License
62 stars 17 forks source link

MPEG-2 SD 4:3 flagged files are being tagged 16:9 thus ignoring the bitstream flag #66

Closed FranceBB closed 5 months ago

FranceBB commented 5 months ago

When an MPEG-2 4:2:0 SD file is encoded with the flag 4:3 and remuxed with BMX then the flag always defaults to 16:9 thus leading to a mismatch between the flag in the bitstream and the flag in the container.

Here you're gonna find the following files: sd_4x3_omneon.zip sd_4x3_ffmpeg.zip sd_wrong_ar_bmx.zip

The first one is the original SD 4:3 source muxed in .mxf by ommcp (the Harmonic Omneon muxer). The second one is the remuxed version with FFMpeg which is still 4:3. The third one is the bad remuxed output produced by BMX version 1.2 (latest).

SD 4:3 Omneon Mediainfo:

General Complete name : A:\MEDIA\temp\sd_4x3_omneon.mxf Format : MXF Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 3.07 MiB Duration : 1 s 440 ms Overall bit rate : 17.9 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-18 17:06:02.624 Writing application : Omneon Inc. Omneon Media Subsystem 9.8.0.0.1 Writing library : Omneon Media Api (windows)

Video ID : 2 Format : MPEG Video Format version : Version 2 Format profile : Main@Main Format settings : BVOP Format settings, BVOP : Yes Format settings, Matrix : Default Format settings, picture structure : Frame Format settings, wrapping mode : Frame Codec ID : 0D01030102046001-0401020201011100 Duration : 1 s 440 ms Bit rate mode : Constant Bit rate : 12.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 4:3 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 1.157 Time code of first frame : 00:00:00:15 Time code source : Group of pictures header Stream size : 2.06 MiB (67%) Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.601 Matrix coefficients : BT.470 System B/G

SD 4:3 FFMpeg Mediainfo:

General Complete name : A:\MEDIA\temp\sd_4x3_ffmpeg.mxf Format : MXF Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 2.95 MiB Duration : 1 s 440 ms Overall bit rate : 17.2 Mb/s Frame rate : 25.000 FPS Encoded date : 0-00-00 00:00:00.000 Writing application : FFmpeg OP1a Muxer 61.0.100.0.0 Writing library : Lavf (mingw32) 61.0.100.0.0

Video ID : 2 Format : MPEG Video Format version : Version 2 Format profile : Main@Main Format settings : BVOP Format settings, BVOP : Yes Format settings, Matrix : Default Format settings, picture structure : Frame Format settings, wrapping mode : Frame Codec ID : 0D01030102046001-0401020201011100 Duration : 1 s 440 ms Bit rate mode : Constant Bit rate : 12.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 4:3 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 1.157 Time code of first frame : 00:00:00:15 Time code source : Group of pictures header Stream size : 2.06 MiB (70%) Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.709 transfer_characteristics_Original : BT.601 Matrix coefficients : BT.601 matrix_coefficients_Original : BT.470 System B/G

BBC BMX Transwrap wrong aspect ratio (16:9 instead of 4:3) mediainfo:

General Complete name : A:\MEDIA\temp\sd_test_bmx.mxf Format : MXF Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 2.92 MiB Duration : 1 s 400 ms Overall bit rate : 17.5 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-18 17:07:09.336 Writing application : BBC bmx 1.2.0.0.0 Writing library : libMXF (Win64) 1.2.0.0.0

Video ID : 1001 Format : MPEG Video Format version : Version 2 Format profile : Main@Main Format settings : BVOP Format settings, BVOP : Yes Format settings, Matrix : Default Format settings, picture structure : Frame Format settings, wrapping mode : Frame Codec ID : 0D01030102046001-0401020201011100 Duration : 1 s 400 ms Bit rate mode : Constant Bit rate : 12.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 16:9 Original display aspect ratio : 4:3 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 1.157 Time code of first frame : 00:00:00:15 Time code source : Group of pictures header Stream size : 2.00 MiB (69%) Title : V1 Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.601 Matrix coefficients : BT.601 matrix_coefficients_Original : BT.470 System B/G

How to reproduce:

bmxtranswrap.exe -p -t op1a -o "sd_test_bmx.mxf" "sd_4x3_ffmpeg.mxf"

Expected behavior: The muxer follows the bitstream flag, thus flagging the output as 4:3.

Actual behavior: The muxer is defaulting to 16:9 thus causing a mismatch between the bitstream aspect ratio flag and the container aspect ratio flag.

### Tasks
philipnbbc commented 5 months ago

Thanks for the bug report. A quick look at the code shows bmx isn't using the aspect ratio parsed from the MPEG-2 bitstream and so it looks like a relatively easy fix to make. I'll probably get to it around Monday.

FranceBB commented 5 months ago

Thank you Philip, I feel like I owe you a thousand coffees at this point... :P

philipnbbc commented 5 months ago

Could you check that https://github.com/bbc/bmx/pull/67 fixes it for you? It worked for bmxtranswrap.exe -p -t op1a -o "sd_test_bmx.mxf" "sd_4x3_ffmpeg.mxf". Thanks.

FranceBB commented 5 months ago

Works like a charm for both 12 Mbit/s Long GOP and 50 Mbit/s all intra. :D Thank you a lot, as always, Philip, for this and for all the work you've been doing over the years. :)

SD_MPEG2_12Mbits_yv12_16x9_BMX

General Complete name : A:\MEDIA\temp\SD_MPEG2_12Mbits_yv12_16x9_BMX.mxf Format : MXF Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 313 MiB Duration : 2 min 38 s Overall bit rate : 16.6 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-23 13:20:50.544 Writing application : BBC bmx 1.2.0.0.0 Writing library : libMXF (Win64) 1.2.0.0.0

Video ID : 1001 Format : MPEG Video Format version : Version 2 Format profile : Main@Main Format settings : BVOP Format settings, BVOP : Yes Format settings, Matrix : Default Format settings, GOP : M=3, N=15 Format settings, picture structure : Frame Format settings, wrapping mode : Frame Codec ID : 0D01030102046001-0401020201011100 Duration : 2 min 38 s Bit rate mode : Constant Bit rate : 12.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 16:9 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 1.157 Time code of first frame : 00:00:00:00 Time code source : Group of pictures header GOP, Open/Closed : Closed Stream size : 226 MiB (72%) Title : V1 Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.470 System B/G Matrix coefficients : BT.601 matrix_coefficients_Original : BT.470 System B/G

SD_MPEG2_12Mbits_yv12_4x3_BMX

General Complete name : A:\MEDIA\temp\SD_MPEG2_12Mbits_yv12_4x3_BMX.mxf Format : MXF Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 313 MiB Duration : 2 min 38 s Overall bit rate : 16.6 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-23 13:21:37.272 Writing application : BBC bmx 1.2.0.0.0 Writing library : libMXF (Win64) 1.2.0.0.0

Video ID : 1001 Format : MPEG Video Format version : Version 2 Format profile : Main@Main Format settings : BVOP Format settings, BVOP : Yes Format settings, Matrix : Default Format settings, GOP : M=3, N=15 Format settings, picture structure : Frame Format settings, wrapping mode : Frame Codec ID : 0D01030102046001-0401020201011100 Duration : 2 min 38 s Bit rate mode : Constant Bit rate : 12.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 4:3 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 1.157 Time code of first frame : 00:00:00:00 Time code source : Group of pictures header GOP, Open/Closed : Closed Stream size : 226 MiB (72%) Title : V1 Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.470 System B/G Matrix coefficients : BT.601 matrix_coefficients_Original : BT.470 System B/G

SD_MPEG2_IMX50_yv16_4x3_BMX.mxf

General Complete name : A:\MEDIA\temp\SD_MPEG2_IMX50_yv16_4x3_BMX.mxf Format : MXF Commercial name : IMX 50 Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 1.01 GiB Duration : 2 min 38 s Overall bit rate : 54.6 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-23 13:22:46.892 Writing application : BBC bmx 1.2.0.0.0 Writing library : libMXF (Win64) 1.2.0.0.0

Video ID : 1001 Format : MPEG Video Commercial name : IMX 50 Format version : Version 2 Format profile : 4:2:2@Main Format settings, BVOP : No Format settings, Matrix : Default Format settings, GOP : N=1 Format settings, picture structure : Frame Format settings, wrapping mode : Frame (D-10) Codec ID : 0D0103010201017F-0401020201020101 Duration : 2 min 38 s Bit rate mode : Constant Bit rate : 50.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 4:3 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:2 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 4.823 Time code of first frame : 00:00:00:00 Time code source : Group of pictures header GOP, Open/Closed : Closed Stream size : 943 MiB (92%) Title : V1 Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.601 transfer_characteristics_Original : BT.470 System B/G Matrix coefficients : BT.470 System B/G

SD_MPEG2_IMX50_yv16_16x9_BMX

General Complete name : A:\MEDIA\temp\SD_MPEG2_IMX50_yv16_16x9_BMX.mxf Format : MXF Commercial name : IMX 50 Format version : 1.3 Format profile : OP-1a Format settings : Closed / Complete File size : 1.01 GiB Duration : 2 min 38 s Overall bit rate : 54.6 Mb/s Frame rate : 25.000 FPS Encoded date : 2024-04-23 13:23:34.564 Writing application : BBC bmx 1.2.0.0.0 Writing library : libMXF (Win64) 1.2.0.0.0

Video ID : 1001 Format : MPEG Video Commercial name : IMX 50 Format version : Version 2 Format profile : 4:2:2@Main Format settings, BVOP : No Format settings, Matrix : Default Format settings, GOP : N=1 Format settings, picture structure : Frame Format settings, wrapping mode : Frame (D-10) Codec ID : 0D0103010201017F-0401020201020101 Duration : 2 min 38 s Bit rate mode : Constant Bit rate : 50.0 Mb/s Width : 720 pixels Height : 576 pixels Display aspect ratio : 16:9 Frame rate : 25.000 FPS Standard : PAL Color space : YUV Chroma subsampling : 4:2:2 Bit depth : 8 bits Scan type : Interlaced Scan order : Top Field First Compression mode : Lossy Bits/(Pixel*Frame) : 4.823 Time code of first frame : 00:00:00:00 Time code source : Group of pictures header GOP, Open/Closed : Closed Stream size : 943 MiB (92%) Title : V1 Color range : Limited Color primaries : BT.601 PAL Transfer characteristics : BT.601 transfer_characteristics_Original : BT.470 System B/G Matrix coefficients : BT.470 System B/G

FranceBB commented 5 months ago

In case anyone comes across the same issue and needs a Windows build straight away, here: build_ok.zip