Menu

#339 MP4Box -splitz fails when all tracks can be split at any frame

v1.0 (example)
pending-postponed
nobody
5
2015-02-26
2014-11-10
No

Hi
So I got a mp4 video which I want to extract the audio from and split that without dropping or duplicating any (audio) frames.
What I did:

MP4Box -info video.mp4
[...]
Track # 1 Info - TrackID 1 - TimeScale 30000 - Media Duration 00:54:47.984
Track has 1 edit lists: track duration is 00:54:47.985
Media Info: Language "Undetermined" - Type "vide:avc1" - 98541 samples
Visual Track layout: x=0 y=0 width=1280 height=720
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
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 1:1 - Indicated track size 1280 x 720
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 44100 - Media Duration 00:54:47.992
Media Info: Language "Undetermined" - Type "soun:mp4a" - 141602 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100
Synchronized on stream 1
MP4Box -single 2 video.mp4

MP4Box -info video_track2.mp4
[...]
Track # 1 Info - TrackID 2 - TimeScale 44100 - Media Duration 00:54:47.992
Track is present in Root OD
Media Info: Language "Undetermined" - Type "soun:mp4a" - 141602 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100
Self-synchronized
MP4Box -splitz 0:281.5 video_track2.mp4
Adjusting chunk end time to previous random access at 0.00 sec
Extracting chunk video_track2_0_0.mp4 - duration 0.00s (0.00s->281.50s)

MP4Box -splitx 281.5:end video_track2.mp4
Extracting chunk video_track2_281_3569.mp4 - duration 3287.99s (281.50s->3569.49s)

and the corresponding file is indeed zero-length.
The audio should be splittable anywhere, which MP4Box also verifies:

MP4Box -dts video_track2.mp4
#dumping track ID 2 timing: Num DTS CTS Size RAP
Sample 1    DTS 0   CTS 0   557 1
[...]

grep "0$" video_track2_ts.txt 

finds no non-RAP frames in the output.

If I split the video without first extracting the audio, the result is:

MP4Box -splitz 0:281.5 video.mp4
Adjusting chunk end time to previous random access at 280.28 sec
Extracting chunk video_0_280.mp4 - duration 280.28s (0.00s->281.50s)
Warning: Edit list doesn't look like a track delay scheme - ignoring

MP4Box -splitx 281.5:end video.mp4
Adjusting chunk start time to previous random access at 280.28 sec
Extracting chunk video_280_3569.mp4 - duration 3289.21s (280.28s->3569.49s)
Warning: Edit list doesn't look like a track delay scheme - ignoring

which is essentially as expected, only that the start and end times are significantly altered to line up with the video keyframes, which I don't want. However, what is incorrect here, too, are he duration and end time given in the "Extracting chunk..." line. The output files playback fine though in VLC.
(Here, both audio and video stream are summed up missing one sample compared to the full video (video: 98540 vs 98541, audio 141601 vs 141602). On Windows (newer version, see below), this is only true for audio which I guess is expected when the splitting occurs on the video stream's RAPs due to the different TimeScales.)

MP4Box -info video_280_3569.mp4
[...]
Track # 1 Info - TrackID 1 - TimeScale 30000 - Media Duration 00:50:07.704
Media Info: Language "Undetermined" - Type "vide:avc1" - 90141 samples
Visual Track layout: x=0 y=0 width=1280 height=720
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
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 1:1 - Indicated track size 1280 x 720
    Chroma format 0 - Luma bit depth 8 - chroma bit depth 8
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 44100 - Media Duration 00:50:07.703
Media Info: Language "Undetermined" - Type "soun:mp4a" - 129531 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100
Synchronized on stream 1
MP4Box -info video_0_280.mp4 
[...]
Track # 1 Info - TrackID 1 - TimeScale 30000 - Media Duration 00:04:40.246
Media Info: Language "Undetermined" - Type "vide:avc1" - 8399 samples
Visual Track layout: x=0 y=0 width=1280 height=720
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
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 1:1 - Indicated track size 1280 x 720
    Chroma format 0 - Luma bit depth 8 - chroma bit depth 8
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 44100 - Media Duration 00:04:40.264
Media Info: Language "Undetermined" - Type "soun:mp4a" - 12070 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100
Synchronized on stream 1

So to find out what was happening, I took a glance at the source (rev 5499), and I believe to have identified the problem:

/*fileimport.c:1072*/   last_rap_sample_time = 0;

however, this will never be reached if -splitz is applied on a file without a track with has_non_raps==1

/*fileimport.c:1124*/   if (tki->has_non_raps && samp->IsRAP) {
                            GF_ISOSample *next_rap;
                            u32 next_rap_num, sdi;
                            last_rap_sample_time = (Double) (s64) samp->DTS;
                            last_rap_sample_time /= tki->time_scale;

accordingly last_rap_sample_time remains 0

/*fileimport.c:1236*/           if (chunk_extraction) {
                                        if (adjust_split_end) {
                                            fprintf(stderr, "Adjusting chunk end time to previous random access at %02.2f sec\n", chunk_start + last_rap_sample_time);
                                            file_split_dur = last_rap_sample_time;

Now, because I don't trust my C-skills, I'd appreciate it if you could have a look a whether this is indeed the culprit and provide a fix.
Thanks a lot!

Versions:
The pastes above were done on Linux Mint x64:

MP4Box -version
MP4Box - GPAC version 0.5.1-DEV-rev4065
GPAC Copyright (c) Telecom ParisTech 2000-2012
GPAC Configuration: --build=x86_64-linux-gnu --prefix=/usr --includedir=${prefix}/include --mandir=${prefix}/share/man --infodir=${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --libdir=${prefix}/lib/x86_64-linux-gnu --libexecdir=${prefix}/lib/x86_64-linux-gnu --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --mandir=${prefix}/share/man --libdir=lib/x86_64-linux-gnu --extra-cflags=-Wall -fPIC -DPIC -I/usr/include/mozjs -DXP_UNIX --enable-joystick --enable-debug --disable-ssl
Features: GPAC_HAS_JPEG GPAC_HAS_PNG 

Originally I found the problem with a recent version on Windows and checked back with the exact commands used above with the same results.
Win 7 x64:

mp4box -version
MP4Box - GPAC version 0.5.1-DEV-rev5498
GPAC Copyright (c) Telecom ParisTech 2000-2012
GPAC Configuration: (static configuration file)
Features: GPAC_64_BITS GPAC_HAS_SPIDERMONKEY GPAC_HAS_JPEG GPAC_HAS_PNG

Discussion

  • Jean Le Feuvre

    Jean Le Feuvre - 2015-02-23

    Sorry for the late follow-up. Have you tried the latest GIT version ? I've been fixing one or two issues with spliting, which could be part of your problem. If still not working, could you upload a sample test file ?

    jean.

     
  • Jean Le Feuvre

    Jean Le Feuvre - 2015-02-24
    • status: open --> pending-postponed
     

Log in to post a comment.