[Libav-user] Joining MP4

Gabriele Greco gabriele.greco at wyscout.com
Fri Oct 13 17:24:18 EEST 2017


Hi guys,

I've a problem joining CERTAIN mp4 files using the concatenation demuxer
and copying the codec informations. This produce a result .mp4 that works
perfectly, till the end of the first part is reached, and then a gray video
(with audio working).

I use libavformat/codec in my code, but I'm able to reproduce the very same
result using ffmpeg stock tools, so I will complete the post with examples
with those tools.

[BRIEF]
I'd like to know if there is a way to detect mp4 files that are not
compatibile with concat muxer since I found a workaround with an extra pass
to fix the problem muxing to TS and then going back to MP4, but this needs
twice the space, and I want to do it only if strictly necessary.

[LONG]
The two files seems identical to me and have the same streams (and ids
inside), ffprobe output:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/Users/gabry/Downloads/171007_BrPA_Kidd_001.mp4':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2017-10-07 17:03:14
    description     : This video is about Untitled Project
    album_artist    : Sean Hanley
    artist          : Sean Hanley
    title           : 171007_BrPA_Kidd_001
  Duration: 00:50:59.68, start: 0.000000, bitrate: 7130 kb/s
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 125 kb/s (default)
    Metadata:
      creation_time   : 2017-10-07 17:03:14
      handler_name    : Core Media Audio
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1280x720 [SAR 1:1 DAR 16:9], 7000 kb/s, 23.98 fps, 23.98 tbr, 24k
tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-10-07 17:03:14
      handler_name    : Core Media Video
    Stream #0:2: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown),
1280x720 [SAR 72:72 DAR 16:9], 90k tbr, 90k tbn, 90k tbc

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/Users/gabry/Downloads/171007_BrPA_Kidd_002.mp4':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2017-10-07 17:21:03
    keywords        : My Movie 3
    album_artist    : Sean Hanley
    description     : This video is about 171007_BrPA_Kidd_002
    artist          : Sean Hanley
    title           : 171007_BrPA_Kidd_002
  Duration: 00:50:55.34, start: 0.000000, bitrate: 7138 kb/s
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 125 kb/s (default)
    Metadata:
      creation_time   : 2017-10-07 17:21:03
      handler_name    : Core Media Audio
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1280x720 [SAR 1:1 DAR 16:9], 7008 kb/s, 23.98 fps, 23.98 tbr, 24k
tbn, 48k tbc (default)
    Metadata:
      creation_time   : 2017-10-07 17:21:03
      handler_name    : Core Media Video
    Stream #0:2: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown),
1280x720 [SAR 72:72 DAR 16:9], 90k tbr, 90k tbn, 90k tbc


I thought the problem was in my code, but running ffmpeg (3.3.1) from the
command line the result is the same, both using a simple files.txt with:

file '171007_BrPA_Kidd_001.mp4'
file '171007_BrPA_Kidd_002.mp4'

... or if I use a more complex specification with (I use unique streams
since sometimes I get audio and video streams inverted in mp4 files, and I
want to remove the MJPEG stream anyway):

file '171007_BrPA_Kidd_001.mp4'
stream
unique_stream_id 0x01
stream
unique_stream_id 0x00
file '171007_BrPA_Kidd_002.mp4'

The result of:

ffmpeg -f concat -safe 0 -i test.txt -c copy out_NOT_WORKING.mp4

... is always a mp4 that works only in the first half.

I can anyway mux a correct mp4 without encoding anything doing this:

ffmpeg -i 171007_BrPA_Kidd_002.mp4 -c copy -bsf:v h264_mp4toannexb 1.ts
ffmpeg -i 171007_BrPA_Kidd_002.mp4 -c copy -bsf:v h264_mp4toannexb 2.ts
ffmpeg -i concat:"1.ts|2.ts" -c copy -bsf:a aac_adtstoasc out_WORKING.mp4

-- 
*Bye,*
* Gabry*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20171013/c4e206dc/attachment.html>


More information about the Libav-user mailing list