[FFmpeg-trac] #9778(avformat:new): Chained Ogg stream with FLAC audio never sets AVSTREAM_EVENT_FLAG_METADATA_UPDATED flag

FFmpeg trac at avcodec.org
Tue May 10 06:47:06 EEST 2022


#9778: Chained Ogg stream with FLAC audio never sets
AVSTREAM_EVENT_FLAG_METADATA_UPDATED flag
-------------------------------------+-------------------------------------
             Reporter:  John Regan   |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:  avformat     |                  Version:
                                     |  unspecified
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 Summary of the bug:

 If you use libavformat to decode a stream of chained Ogg files with FLAC
 audio, each file with their own metadata - libavformat only returns
 metadata for the first file in the chain.

 If my reading of the specs is correct, this should function similarly to
 chained Ogg with Opus or Vorbis audio, with the effect of updating
 metadata as each Ogg file in the chain is read.

 Attached is a small C program to demo the issue - when a stream metadata
 updates, it prints all tags to stdout.

 Here's the the source code of the demo program. I made sure to renounce
 all ownership of the code, just to make sure that doesn't cause any kind
 of copyright issue. It's pretty trivial.

 {{{
 /*
 This is free and unencumbered software released into the public domain.

 Anyone is free to copy, modify, publish, use, compile, sell, or
 distribute this software, either in source code form or as a compiled
 binary, for any purpose, commercial or non-commercial, and by any
 means.

 In jurisdictions that recognize copyright laws, the author or authors
 of this software dedicate any and all copyright interest in the
 software to the public domain. We make this dedication for the benefit
 of the public at large and to the detriment of our heirs and
 successors. We intend this dedication to be an overt act of
 relinquishment in perpetuity of all present and future rights to this
 software under copyright law.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

 For more information, please refer to <http://unlicense.org/>
 */

 #include <stdio.h>

 #include <libavformat/avformat.h>
 #include <libavutil/dict.h>

 /* program that read frames and prints out metadata
  * on a metadata update */

 static void dump_and_clear_tags(AVStream *stream, int frameNumber) {
     const AVDictionaryEntry *tag = NULL;

     printf("Frame %d: tags found\n", frameNumber);
     while((tag = av_dict_get(stream->metadata, "", tag,
 AV_DICT_IGNORE_SUFFIX))) {
         printf("tag found: %s=%s\n",tag->key,tag->value);
     }
     stream->event_flags = 0;
     av_dict_free(&stream->metadata);
 }


 int main(int argc, const char *argv[]) {
     AVFormatContext *formatContext = NULL;
     AVPacket *packet = NULL;
     int ret = 1;
     int i = 0;

     if(argc < 2) {
         fprintf(stderr,"Usage: %s input.ogg\n",argv[0]);
         goto cleanup;
     }

     if(avformat_open_input(&formatContext, argv[1], NULL, NULL) < 0) {
         fprintf(stderr,"Error opening path %s\n",argv[1]);
         goto cleanup;
     }

     if(avformat_find_stream_info(formatContext, NULL) < 0) {
         fprintf(stderr,"Unable to find stream info\n");
         goto cleanup;
     }

     /* assuming stream 0 is the stream we want, typical in chained ogg */

     if(formatContext->streams[0]->event_flags &
 AVSTREAM_EVENT_FLAG_METADATA_UPDATED) {
         dump_and_clear_tags(formatContext->streams[0],i);
     }

     packet = av_packet_alloc();
     while(av_read_frame(formatContext,packet) == 0) {
         i++;

         if(formatContext->streams[0]->event_flags &
 AVSTREAM_EVENT_FLAG_METADATA_UPDATED) {
             dump_and_clear_tags(formatContext->streams[0],i);
         }

         av_packet_unref(packet);
     }
     printf("Found %d frames\n",i);

     ret = 0;
     cleanup:

     if(formatContext != NULL)
         avformat_close_input(&formatContext);

     if(packet != NULL)
         av_packet_free(&packet);

     return ret;
 }
 }}}

 Example usage, assuming the program has been compiled and linked as
 "demo":

 First generate some Ogg files with FLAC audio, and concatenate:

 {{{
 % ffmpeg -f lavfi -i anullsrc -c:a flac -to 10 -metadata title="First" -f
 ogg 01-flac.ogg
 % ffmpeg -f lavfi -i anullsrc -c:a flac -to 10 -metadata title="Second" -f
 ogg 02-flac.ogg
 % cat 01-flac.ogg 02-flac.ogg > chained-flac.ogg
 }}}

 Then for reference, Ogg files with Opus audio:

 {{{
 % ffmpeg -f lavfi -i anullsrc -c:a libopus -to 10 -metadata title="First"
 -f ogg 01-opus.ogg
 % ffmpeg -f lavfi -i anullsrc -c:a libopus -to 10 -metadata title="Second"
 -f ogg 02-opus.ogg
 % cat 01-opus.ogg 02-opus.ogg > chained-opus.ogg
 }}}

 Execute the demo program with the Ogg-with-Opus file to verify all
 metadata is printed:

 {{{
 % ./demo chained-opus.ogg
 }}}

 This prints:

 {{{
 Frame 0: tags found
 tag found: encoder=Lavc59.18.100 libopus
 tag found: title=First
 Frame 502: tags found
 tag found: encoder=Lavc59.18.100 libopus
 tag found: title=Second
 Found 1002 frames
 }}}

 Now with the Ogg-with-FLAC file - only metadata from the first audio file
 is printed:

 {{{
 % ./demo chained-flac.ogg
 }}}

 This prints:

 {{{
 Frame 0: tags found
 tag found: encoder=Lavc59.18.100 flac
 tag found: title=First
 Found 194 frames
 }}}

 Lastly, the output of ffmpeg -version:

 {{{
 ffmpeg version n5.0 Copyright (c) 2000-2022 the FFmpeg developers
 built with gcc 11.2.0 (GCC)
 configuration: --prefix=/usr --disable-debug --disable-static --disable-
 stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto
 --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-
 ladspa --enable-libaom --enable-libass --enable-libbluray --enable-
 libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi
 --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx
 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb
 --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-
 libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-
 libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-
 libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-
 libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-
 libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg
 --enable-nvdec --enable-nvenc --enable-shared --enable-version3
 libavutil      57. 17.100 / 57. 17.100
 libavcodec     59. 18.100 / 59. 18.100
 libavformat    59. 16.100 / 59. 16.100
 libavdevice    59.  4.100 / 59.  4.100
 libavfilter     8. 24.100 /  8. 24.100
 libswscale      6.  4.100 /  6.  4.100
 libswresample   4.  3.100 /  4.  3.100
 libpostproc    56.  3.100 / 56.  3.100
 }}}
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/9778>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list