Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken header for mp4 outputs causes playback issues #660

Closed
Dendraspis opened this issue Jan 6, 2025 · 6 comments
Closed

Broken header for mp4 outputs causes playback issues #660

Dendraspis opened this issue Jan 6, 2025 · 6 comments

Comments

@Dendraspis
Copy link
Contributor

Hello rigaya,

when using the mp4 output file extension, the header is broken.

Here are two metadata readouts made by MP4Box, one from an encode made with AV1 codec, the other with H265. Please check the line in the middle starting with Visual Track layout: where metadata states a dimension of width=0 height=1080 as well as Indicated track size 0 x 1080 for H265 codec.
This causes playback issues with Browsers, TVs, etc.

Side note:

  • It seems the be an old issue as NVEncC v7.77 was also affected.
  • Using --avhw leads to the same issue.

AV1

Command Line:
[..]\NVEncC64.exe --avsdll [..]\AviSynth.dll --qvbr 28 --codec av1 --output-depth 10 --colormatrix bt709 --colorprim bt709 --transfer bt709 -i XXX_Test.avs -o XXX_Test.mp4

# Movie Info - 1 track - TimeScale 1000
Duration 00:03:33.680
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 av01 iso2 mp41
Created: UNKNOWN DATE

Meta-Data Tags:
        tool: NVEncC (x64) 7.80

# Track 1 Info - ID 1 - TimeScale 12800
Media Duration 00:03:33.680
Track has 1 edits: track duration is 00:03:33.680
Track flags: Enabled In Movie
Media Samples: 5342 - CFR 25/sec
Visual Track layout: x=0 y=0 width=0 height=1080
Media Type: vide:av01
        Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits)
        AOM AV1 stream - Resolution 1920 x 1080
        version=1, profile=0, level_idx0=8, tier=0
        high_bitdepth=1, twelve_bit=0, monochrome=0
        chroma: subsampling_x=1, subsampling_y=1, sample_position=0
        OBU#1 seq_header hash: CFE7143C7744D69645D203A592093ED0808D1D1E
        RFC6381 Codec Parameters: av01.0.08M.10.0.110.01.01.01.0

        Average GOP length: 254 samples
        Max sample duration: 512 / 12800

H265

Command Line:
[..]\NVEncC64.exe --avsdll [..]\AviSynth.dll --qvbr 28 --codec h265 --colormatrix bt709 --colorprim bt709 --transfer bt709 -i XXX_Test.avs -o XXX_Test.mp4

# Movie Info - 1 track - TimeScale 1000
Duration 00:03:33.680
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 iso2 mp41
Created: UNKNOWN DATE

Meta-Data Tags:
        tool: NVEncC (x64) 7.80

# Track 1 Info - ID 1 - TimeScale 12800
Media Duration 00:03:33.680  (recomputed 00:03:33.720)
Track has 1 edits: track duration is 00:03:33.680
Track flags: Enabled In Movie
Media Samples: 5342 - CFR 25/sec
Visual Track layout: x=0 y=0 width=0 height=1080
Media Type: vide:hvc1
        Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits)
        HEVC Video - Visual Size 1920 x 1080
        HEVC Info: Profile Main 10 @ Level 4 - Chroma Format YUV 4:2:0

        NAL Unit length bits: 32 - general profile compatibility 0x20000000

        Parameter Sets: 1 VPS 1 SPS 1 PPS
        SPS resolution 1920x1080 - Pixel Aspect Ratio 1:1 - Indicated track size 0 x 1080
        Bit Depth luma 10 - Chroma 10 - 1 temporal layers
        VPS#1 hash: 7336C4822DE1EE092932CC26D5A7CF4BEB90D640
        SPS#1 hash: 3CA59495C993B07ABB5CF3DC79132167A528D133
        PPS#1 hash: 3CCA1B55B5E68ACEFBB99FB5A68BCE674686406F

        RFC6381 Codec Parameters: hvc1.2.4.L120.90

        Average GOP length: 254 samples
        Max sample duration: 512 / 12800
rigaya added a commit that referenced this issue Jan 7, 2025
… boxdumper)、"Visual Track layout"(mp4box -info)のwidthが0になってしまう問題を回避。 ( #660 )
@rigaya
Copy link
Owner

rigaya commented Jan 7, 2025

I've checked through the source code of libavformat mp4 muxer, and found out that it seems like the mp4 muxer calculates width for tkhd (Track Header Box) as 0 when SAR (sample aspect ratio) is "undefined" (unset).

Although I do think "undefined" SAR itself should have no problem, I made a change to set SAR = "1:1" for muxer when SAR is "undefined", in order to avoid this problem.

Below is the test build, would you please have a test if it can avoid the problem?
https://nightly.link/rigaya/NVEnc/actions/runs/12649481331/NVEncC_release_r3125_x64.zip

@Dendraspis
Copy link
Contributor Author

I have tried the linked version, but the result is still width=0 height=1080:

# Movie Info - 1 track - TimeScale 1000
Duration 00:03:33.680
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 iso2 mp41
Created: UNKNOWN DATE

Meta-Data Tags:
        tool: NVEncC (x64) 7.81

# Track 1 Info - ID 1 - TimeScale 12800
Media Duration 00:03:33.680  (recomputed 00:03:33.720)
Track has 1 edits: track duration is 00:03:33.680
Track flags: Enabled In Movie
Media Samples: 5342 - CFR 25/sec
Visual Track layout: x=0 y=0 width=0 height=1080
Media Type: vide:hvc1
        Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits)
        HEVC Video - Visual Size 1920 x 1080
        HEVC Info: Profile Main 10 @ Level 4 - Chroma Format YUV 4:2:0

        NAL Unit length bits: 32 - general profile compatibility 0x20000000

        Parameter Sets: 1 VPS 1 SPS 1 PPS
        SPS resolution 1920x1080 - Pixel Aspect Ratio 1:1 - Indicated track size 0 x 1080
        Bit Depth luma 10 - Chroma 10 - 1 temporal layers
        VPS#1 hash: 7336C4822DE1EE092932CC26D5A7CF4BEB90D640
        SPS#1 hash: 3CA59495C993B07ABB5CF3DC79132167A528D133
        PPS#1 hash: 3CCA1B55B5E68ACEFBB99FB5A68BCE674686406F

        RFC6381 Codec Parameters: hvc1.2.4.L120.90

        Average GOP length: 254 samples
        Max sample duration: 512 / 12800

....

But when I extend the command line by --sar 1:1 the result is correct (for both codecs) and the playback compatibilities are intact:

# Movie Info - 1 track - TimeScale 1000
Duration 00:03:33.680
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 iso2 mp41
Created: UNKNOWN DATE

Meta-Data Tags:
        tool: NVEncC (x64) 7.81

# Track 1 Info - ID 1 - TimeScale 12800
Media Duration 00:03:33.680  (recomputed 00:03:33.720)
Track has 1 edits: track duration is 00:03:33.680
Track flags: Enabled In Movie
Media Samples: 5342 - CFR 25/sec
Visual Track layout: x=0 y=0 width=1920 height=1080
Media Type: vide:hvc1
        Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits)
        HEVC Video - Visual Size 1920 x 1080
        HEVC Info: Profile Main 10 @ Level 4 - Chroma Format YUV 4:2:0

        NAL Unit length bits: 32 - general profile compatibility 0x20000000

        Parameter Sets: 1 VPS 1 SPS 1 PPS
        SPS resolution 1920x1080 - Pixel Aspect Ratio 1:1 - Indicated track size 1920 x 1080
        Bit Depth luma 10 - Chroma 10 - 1 temporal layers
        VPS#1 hash: 7336C4822DE1EE092932CC26D5A7CF4BEB90D640
        SPS#1 hash: 3CA59495C993B07ABB5CF3DC79132167A528D133
        PPS#1 hash: 3CCA1B55B5E68ACEFBB99FB5A68BCE674686406F

        RFC6381 Codec Parameters: hvc1.2.4.L120.90

        Average GOP length: 254 samples
        Max sample duration: 512 / 12800

@Dendraspis
Copy link
Contributor Author

Although I do think "undefined" SAR itself should have no problem, I made a change to set SAR = "1:1" for muxer when SAR is "undefined", in order to avoid this problem.

Nevertheless a bit strange, that even without setting SAR to 1:1, the height=1080 is always correct. It seems to be sort of an unset variable issue, otherwise the height should also be 0, no?

rigaya added a commit that referenced this issue Jan 7, 2025
@rigaya
Copy link
Owner

rigaya commented Jan 7, 2025

Sorry, I've made a wrong fix in the previous version.

Would you mind trying the following build? It should act as the same as --sar 1:1.
https://nightly.link/rigaya/NVEnc/actions/runs/12660601508/NVEncC_release_r3126_x64.zip

@Dendraspis
Copy link
Contributor Author

No problem. Sure ... and yeah, works great. 😅👍

# Movie Info - 1 track - TimeScale 1000
Duration 00:03:33.680
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 av01 iso2 mp41
Created: UNKNOWN DATE

Meta-Data Tags:
        tool: NVEncC (x64) 7.81

# Track 1 Info - ID 1 - TimeScale 12800
Media Duration 00:03:33.680
Track has 1 edits: track duration is 00:03:33.680
Track flags: Enabled In Movie
Media Samples: 5342 - CFR 25/sec
Visual Track layout: x=0 y=0 width=1920 height=1080
Media Type: vide:av01
        Visual Sample Entry Info: width=1920 height=1080 (depth=24 bits)
        AOM AV1 stream - Resolution 1920 x 1080
        version=1, profile=0, level_idx0=8, tier=0
        high_bitdepth=1, twelve_bit=0, monochrome=0
        chroma: subsampling_x=1, subsampling_y=1, sample_position=0
        OBU#1 seq_header hash: CFE7143C7744D69645D203A592093ED0808D1D1E
        RFC6381 Codec Parameters: av01.0.08M.10.0.110.01.01.01.0

        Average GOP length: 254 samples
        Max sample duration: 512 / 12800

@Dendraspis
Copy link
Contributor Author

Thanks for the fix. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants