gpac / gpac

GPAC Ultramedia OSS for Video Streaming & Next-Gen Multimedia Transcoding, Packaging & Delivery
https://gpac.io
GNU Lesser General Public License v2.1
2.72k stars 528 forks source link

Adding a second subtitle track generate error messages #2170

Closed Eeel-12 closed 2 years ago

Eeel-12 commented 2 years ago

Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/

I'm trying to convert a .mp4 file to play with dash.js with video, two audio track and two or more subtitle tracks. resulted files and mpd play fine with one subtitle only, as soon as i had a second subtitle track, it is unsynced.

OS is Linux Slackware 15.0

# MP4Box -version
MP4Box - GPAC version 2.0-revrelease
(c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io

Please cite our work in your research:
        GPAC Filters: https://doi.org/10.1145/3339825.3394929
        GPAC: https://doi.org/10.1145/1291233.1291452

GPAC Configuration: --prefix=/usr --mandir=/usr/man --disable-opt --enable-pic --enable-pulseaudio --cpu=x86_64 --extra-cflags=-O2 -fPIC --disable-wx --disable-amr
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_MAD GPAC_HAS_LIBA52 GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_HAS_FFMPEG GPAC_HAS_JP2 GPAC_HAS_THEORA GPAC_HAS_VORBIS GPAC_HAS_LINUX_DVB

My MP4 source test.mp4. MP4Box - MP4Box -info test.mp4 :

[isom/avcc] Missing REXT profile signaling, patching.
[iso file] Found stts entry with sample_delta=0 - forbidden ! Fixing to 1 <repeated several times>

# Movie Info - 5 tracks - TimeScale 1000
Duration 01:49:49.590 (recomputed 01:49:49.589)
Fragmented: no
Progressive (moov before mdat)
Major Brand mp42 - version 512 - compatible brands: mp42 iso2 avc1 mp41
Created: GMT Fri Apr  1 12:33:24 2022

iTunes Info:
        title: Test
        tool: HandBrake 1.5.1 2022011100

# Track 1 Info - ID 1 - TimeScale 90000
Media Duration 01:49:49.583  (recomputed 01:49:49.666)
Track has 1 edits: track duration is 01:49:49.583
Track flags: Enabled In Movie
Media Info: Language "Undetermined (und)" - Type "vide:avc1" - 157992 samples
Visual Sample Entry Info: width=1280 height=720 (depth=24 bits)
Visual Track layout: x=0 y=0 width=1329 height=720
AVC/H264 Video - Visual Size 1280 x 720
        AVC Info: 1 SPS - 1 PPS - Profile High @ Level 3.1
        NAL Unit length bits: 32
        Pixel Aspect Ratio 27:26 - Indicated track size 1329 x 720
        Chroma format YUV 4:2:0 - Luma bit depth 8 - chroma bit depth 8
        SPS#1 hash: 6208DEE775C5F3D73DE353432F02A82428672143
        PPS#1 hash: 388BF4B817C1896AC1198BB370180C1101833A4F
        RFC6381 Codec Parameters: avc1.64001F
        Average GOP length: 115 samples
        Max sample duration: 3754 / 90000

# Track 2 Info - ID 2 - TimeScale 48000
Media Duration 01:49:49.568  (recomputed 01:49:49.589)
Track has 1 edits: track duration is 01:49:49.568
Track flags: Enabled In Movie
Media Info: Language "French (fra)" - Type "soun:mp4a" - 308887 samples
2 UDTA types: 
        name: Stereo
        titl:  unknown type (13 bytes)
Alternate Group ID 1
MPEG-4 Audio AAC LC (AOT=2 implicit) - 2 Channel(s) - SampleRate 48000
        RFC6381 Codec Parameters: mp4a.40.2
        All samples are sync
        Max sample duration: 1024 / 48000

# Track 3 Info - ID 3 - TimeScale 48000
Media Duration 01:49:49.589  (recomputed 01:49:49.610)
Track has 1 edits: track duration is 01:49:49.589
Track flags: Disabled In Movie
Media Info: Language "English (eng)" - Type "soun:mp4a" - 308888 samples
2 UDTA types: 
        name: Stereo
        titl:  unknown type (13 bytes)
Alternate Group ID 1
MPEG-4 Audio AAC LC (AOT=2 implicit) - 2 Channel(s) - SampleRate 48000
        RFC6381 Codec Parameters: mp4a.40.2
        All samples are sync
        Max sample duration: 1024 / 48000

# Track 4 Info - ID 4 - TimeScale 90000
Media Duration 01:41:38.933  (recomputed 01:41:38.933)
Track has 1 edits: track duration is 01:41:38.933
Track flags: Enabled In Movie
Media Info: Language "French (fra)" - Type "sbtl:tx3g" - 550 samples
2 UDTA types: 
        name: Forced
        titl:  unknown type (13 bytes)
Alternate Group ID 3
QT/3GPP subtitle
        Size 1329 x 108 - Translation X=0 Y=0 - Layer 0
        RFC6381 Codec Parameters: tx3g
        All samples are sync
        Max sample duration: 77000760 / 90000

# Track 5 Info - ID 5 - TimeScale 90000
Media Duration 01:49:47.839  (recomputed 01:49:47.839)
Track has 1 edits: track duration is 01:49:47.839
Track flags: Disabled In Movie
Media Info: Language "French (fra)" - Type "sbtl:tx3g" - 3001 samples
2 UDTA types: 
        name: French
        titl:  unknown type (13 bytes)
Alternate Group ID 3
QT/3GPP subtitle
        Size 1329 x 108 - Translation X=0 Y=0 - Layer 0
        RFC6381 Codec Parameters: tx3g
        All samples are sync
        Max sample duration: 43821360 / 90000

Extracting subtitles in srt with MP4Box:

MP4Box -srt 4 test.mp4 MP4Box -srt 5 test.mp4

[iso file] Found stts entry with sample_delta=0 - forbidden ! Fixing to 1 <repeated several times>
Conversion done 

At this point if i add only one subtitle, the finale mpd file play fine and subtitle are in sync.

Adding WebVTT to test.mp4:

MP4Box -add test_4_text.srt:FMT=VTT:lang=fr+test_5_text.srt:FMT=VTT:lang=fr test.mp4
[isom/avcc] Missing REXT profile signaling, patching.
[iso file] Found stts entry with sample_delta=0 - forbidden ! Fixing to 1 <repeated several times>
Track Importing WebVTT - Text track 1329 x 720 layer 0
Track Importing WebVTT - Text track 1329 x 720 layer 0
Saving test.mp4: 0.500 secs Interleaving

Create mpd and files:

$ MP4Box -dash 10000 -profile dashavc264:onDemand test.mp4#trackID=1:id=video test.mp4#trackID=2:id=fre test.mp4#trackID=3:id=eng test.mp4#trackID=6:id=fr_forced:role=forced-subtitle test.mp4#trackID=7:id=fr_full:role=subtitle -out test.mpd
[Dasher] No template assigned, using $File$_dash$FS$$Number$

[MP4Mux] PID T7 ID 7 Sample 139 with DTS 295337 less than previous sample DTS 300000, adjusting prev sample duration <repeated several times>

[Dasher] Adaptation sets in period are of unequal duration min 6098.93 max 6589.59 seconds
[MPD] Generating MPD at time 2022-04-12T13:13:27.083Z
[Dasher] End of Period 
[Dasher] End of MPD (no more active streams)

MP4Box don't output the messages below with one subtitle track

[MP4Mux] PID T7 ID 7 Sample 139 with DTS 295337 less than previous sample DTS 300000, adjusting prev sample duration
[MP4Mux] PID T7 ID 7 Sample 141 with DTS 300709 less than previous sample DTS 314663, adjusting prev sample duration
[MP4Mux] PID T7 ID 7 Sample 143 with DTS 313921 less than previous sample DTS 333954, adjusting prev sample duration
[MP4Mux] PID T7 ID 7 Sample 145 with DTS 320083 less than previous sample DTS 350033, adjusting prev sample duration

Can't figure out what i'm doing wrong, is the source file not properly encoded or i'm missing some command argument ?

jeanlf commented 2 years ago

could you upload your test file somewhere ?

Eeel-12 commented 2 years ago

@jeanlf thank you, the test.mp4 created with Handbrake https://www.mediafire.com/file/03f7gktnu7pjy0d/test.tar.gz/file

note that Handbrake produce .m4v file, they said it can be simply renamed in .mp4, thats what i did.

I've also tested commands below with ffmpeg:

ffmpeg -y -i test.mp4 -c:v libx264 -x264opts 'keyint=48:min-keyint=48:no-scenecut' -r 24 -b:v 2500k -maxrate 2500k -bufsize 5000k -movflags faststart -profile:v main -preset slower -an "video.mp4" 
ffmpeg -y -i test.mp4 -map 0:1 -vn -c:a copy audio1.m4a
ffmpeg -y -i test.mp4 -map 0:2 -vn -c:a copy audio2.m4a
MP4Box -srt 4 test.mp4
MP4Box -srt 5 test.mp4

But it produce the same error messages on the second subtitle track added with MP4Box.

Eeel-12 commented 2 years ago

@jeanlf updated file link.

jeanlf commented 2 years ago

Indeed there was a potential injection of empty text segments at the wrong place resulting in all these timing warnings.

Could you try with latest git?

Eeel-12 commented 2 years ago

Hello @jeanlf and thank you. It works fine with the git version.