[FFmpeg-devel] [PATCH 19/21] doc/examples/extract_timed_metadata: added a bare-bones metadata extractor; find only the frames

Erkki Seppälä erkki.seppala.ext at nokia.com
Thu Aug 25 10:31:57 EEST 2016


Thanks for pointing out the use of private API. It seemed that this 
would have needed to add a new function for the API for decoding timed 
metadata frames, but probably a better solution is to use the 
avcodec_receive_packet framework for this as the old API is deprecated 
anyway?

Below is a patch to introduce the functionality (example edited for 
brevity). If this seems like the way to, I'll add this to v2 of the 
patches. (I may squash the first patch with one of the other patches if 
it fits in.)

commit ddfb745109768a169e93c221092161d39c8f8208
Author: Erkki Seppälä <erkki.seppala.ext at nokia.com>
Date:   Thu Aug 25 10:21:15 2016 +0300

     libavcodec/utils: do_decode now supports AVMEDIA_TYPE_DATA

     This allows using avcodec_send_packet with data frames (ie. timed 
metadata)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 138125a..8b55464 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2737,6 +2737,10 @@ static int do_decode(AVCodecContext *avctx, 
AVPacket *pkt)
      } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
          ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,
                                      &got_frame, pkt);
+    } else if (avctx->codec_type == AVMEDIA_TYPE_DATA) {
+        ret = avctx->codec->decode(avctx, 
avctx->internal->buffer_frame, &got_frame, pkt);
+        if (ret == 0 && got_frame)
+            ret = pkt->size;
      } else {
          ret = AVERROR(EINVAL);
      }

commit ebfceb706d8c8d0dbfe64ebe06d218aaa8807e43
Author: Erkki Seppälä <erkki.seppala.ext at nokia.com>
Date:   Thu Aug 25 10:22:19 2016 +0300

     fixup! doc/examples/extract_timed_metadata: added a bare-bones 
metadata extractor; find only the frames

diff --git a/doc/examples/extract_timed_metadata.c 
b/doc/examples/extract_timed_metadata.c
index 48fb877..03da2b7 100644
--- a/doc/examples/extract_timed_metadata.c
+++ b/doc/examples/extract_timed_metadata.c
@@ -184,16 +183,15 @@ int main(int argc, char **argv)

          for (i = 0; metadata_stream_indices[i] >= 0; i++) {
              if (packet.stream_index == metadata_stream_indices[i]) {
-                got_frame = 0;
-
-                ret = dec_ctx[i]->codec->decode(dec_ctx[i], metadata, 
&got_frame, &packet);
+                ret = avcodec_send_packet(dec_ctx[i], &packet);

+                // We always empty decoded frames so we don't handle 
AVERROR(EAGAIN) here
                  if (ret < 0) {
                      av_log(NULL, AV_LOG_ERROR, "Error decoding meta 
data\n");
                      break;
                  }

-                if (got_frame) {
+                while (avcodec_receive_frame(dec_ctx[i], metadata) == 0) {
                      int c;
                      printf("track #%d at %" PRId64 " %d, ",
                             packet.stream_index + 1,


More information about the ffmpeg-devel mailing list