[FFmpeg-devel] [PATCH] avformat/concat: fix missing metadata

Steven Hartland stevenmhartland at gmail.com
Sat Jul 2 13:44:38 EEST 2022


I'm using concat to join multiple files from a GoPro camera including the
three metadata streams, with the early return it fails as the metadata
stream information is missing so map fails.

Example of the command line is:
ffmpeg \
        -y \
        -safe 0 \
        -f concat \
        -i list.txt \
        -c copy \
        -c:v libx264 \
        -vf scale=1920:1080 \
        -crf 24 \
        -copy_unknown \
        -map_metadata 0 \
        -movflags use_metadata_tags \
        -map 0:v \
        -map 0:a \
        -map 0:m:handler_name:" GoPro TCD" \
        -map 0:m:handler_name:" GoPro MET" \
        -map 0:m:handler_name:" GoPro SOS" \
        test/concat.mp4

Here is the error without the change:

ffmpeg version N-107034-g77b529fbd2 Copyright (c) 2000-2022 the FFmpeg
developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/home/steveh/ffmpeg_build
--pkg-config-flags=--static
--extra-cflags=-I/home/steveh/ffmpeg_build/include
--extra-ldflags=-L/home/steveh/ffmpeg_build/lib --extra-libs='-lpthread
-lm' --ld=g++ --bindir=/home/steveh/bin --enable-gpl --enable-gnutls
--enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype
--enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
--enable-nonfree
  libavutil      57. 25.100 / 57. 25.100
  libavcodec     59. 32.102 / 59. 32.102
  libavformat    59. 24.100 / 59. 24.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 40.100 /  8. 40.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55be9e9aac00] Auto-inserting h264_mp4toannexb
bitstream filter
[concat @ 0x55be9e9a1140] Could not find codec parameters for stream 2
(Unknown: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize'
(5000000) options
[concat @ 0x55be9e9a1140] Could not find codec parameters for stream 4
(Unknown: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize'
(5000000) options
Input #0, concat, from 'list.txt':
  Duration: N/A, start: 0.000000, bitrate: 60098 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc,
bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 59932 kb/s, 23.98 fps,
23.98 tbr, 24k tbn
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AVC
      vendor_id       : [0][0][0][0]
      encoder         : GoPro AVC encoder
      timecode        : 15:38:07:03
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AAC
      vendor_id       : [0][0][0][0]
      timecode        : 15:38:07:03
  Stream #0:2: Unknown: none
  Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 38 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro MET
  Stream #0:4: Unknown: none
Stream map '0:m:handler_name:   GoPro TCD' matches no streams.
To ignore this, add a trailing '?' to the map.

With this change it works as expected:
ffmpeg version N-107034-g77b529fbd2 Copyright (c) 2000-2022 the FFmpeg
developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/home/steveh/ffmpeg_build
--pkg-config-flags=--static
--extra-cflags=-I/home/steveh/ffmpeg_build/include
--extra-ldflags=-L/home/steveh/ffmpeg_build/lib --extra-libs='-lpthread
-lm' --ld=g++ --bindir=/home/steveh/bin --enable-gpl --enable-gnutls
--enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype
--enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
--enable-nonfree
  libavutil      57. 25.100 / 57. 25.100
  libavcodec     59. 32.102 / 59. 32.102
  libavformat    59. 24.100 / 59. 24.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 40.100 /  8. 40.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x557f730b3c00] Auto-inserting h264_mp4toannexb
bitstream filter
Input #0, concat, from 'list.txt':
  Duration: N/A, start: 0.000000, bitrate: 60108 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc,
bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 59932 kb/s, 23.98 fps,
23.98 tbr, 24k tbn
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AVC
      vendor_id       : [0][0][0][0]
      encoder         : GoPro AVC encoder
      timecode        : 15:38:07:03
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AAC
      vendor_id       : [0][0][0][0]
      timecode        : 15:38:07:03
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro TCD
      timecode        : 15:38:07:03
  Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 38 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro MET
  Stream #0:4(eng): Data: none (fdsc / 0x63736466), 9 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro SOS
[mp4 @ 0x557f732f6240] You requested a copy of the original timecode track
so timecode metadata are now ignored
Output #0, mp4, to 'test/concat.mp4':
  Metadata:
    encoder         : Lavf59.24.100
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc,
bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 59932 kb/s,
23.98 fps, 23.98 tbr, 24k tbn
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AVC
      vendor_id       : [0][0][0][0]
      encoder         : GoPro AVC encoder
      timecode        : 15:38:07:03
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro AAC
      vendor_id       : [0][0][0][0]
      timecode        : 15:38:07:03
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro TCD
      timecode        : 15:38:07:03
  Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 38 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro MET
  Stream #0:4(eng): Data: none (fdsc / 0x63736466), 9 kb/s
    Metadata:
      creation_time   : 2022-05-31T15:39:02.000000Z
      handler_name    :         GoPro SOS
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
  Stream #0:3 -> #0:3 (copy)
  Stream #0:4 -> #0:4 (copy)
Press [q] to stop, [?] for help
frame=   24 fps= 16 q=-1.0 size=     768kB time=00:00:01.00
bitrate=6275.1kbits/s speed=0.668x
...

I believe the reason for the failure is that this early return prevents the
metadata from being preserved.


On Sun, 19 Jun 2022 at 21:18, Marton Balint <cus at passwd.hu> wrote:

>
>
> On Sun, 12 Jun 2022, Steven Hartland wrote:
>
> > Remove return after copying extradata as this prevents metadata
> > being duplicated correctly.
>
> The return there originated from commit
> b24d6c53037aaaa20fbd59cbd25c392229450660 and seems very much intentional
> to not overwrite stream parameters after every packet.
>
> So what is the issue you are trying to fix? Some parameters change after
> the avformat_find_stream_info() returned?
>
> Regards,
> Marton
>
> >
> > Signed-off-by: Steven Hartland <stevenmhartland at gmail.com>
> > ---
> > libavformat/concatdec.c                       | 1 -
> > tests/ref/fate/concat-demuxer-simple2-lavf-ts | 2 +-
> > 2 files changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> > index e57da59e04..11ed2bd4c3 100644
> > --- a/libavformat/concatdec.c
> > +++ b/libavformat/concatdec.c
> > @@ -182,7 +182,6 @@ static int copy_stream_props(AVStream *st, AVStream
> > *source_st)
> >         }
> >         memcpy(st->codecpar->extradata, source_st->codecpar->extradata,
> >                source_st->codecpar->extradata_size);
> > -        return 0;
> >     }
> >     if ((ret = avcodec_parameters_copy(st->codecpar,
> source_st->codecpar))
> > < 0)
> >         return ret;
> > diff --git a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
> > b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
> > index 9603ca21d0..d98e8b71e1 100644
> > --- a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
> > +++ b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
> > @@ -211,5 +211,5 @@
> >
> video|1|171982|1.910911|168382|1.870911|3600|0.040000|17440|206988|__|MPEGTS
> > Str
> >
> >
> video|1|175582|1.950911|171982|1.910911|3600|0.040000|15019|224848|__|MPEGTS
> > Stream ID|224
> >
> >
> -0|mp2|unknown|audio|[3][0][0][0]|0x0003|s16p|44100|1|mono|0|N/A|0/0|0/0|1/90000|0|0.000000|N/A|N/A|64000|N/A|N/A|N/A|N/A|89|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|this
> > is stream 0
> >
> +0|mp2|unknown|audio|[3][0][0][0]|0x0003|fltp|44100|1|mono|0|N/A|0/0|0/0|1/90000|0|0.000000|N/A|N/A|64000|N/A|N/A|N/A|N/A|89|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|this
> > is stream 0
> >
> 1|mpeg2video|4|video|[2][0][0][0]|0x0002|352|288|0|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/90000|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|60|22|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|this
> > is stream 1|CPB properties|0|0|0|49152|-1
> > --
> > 2.25.1
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> >
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list