[FFmpeg-devel] [PATCH 2/2] lavc/parser: export resolution and format in AVCodecContext if not already set

Rodger Combs rodger.combs at gmail.com
Wed Apr 13 10:26:04 CEST 2016


This allows avformat_find_stream_info to finish without opening a decoder in
more cases.
---
 libavcodec/parser.c              | 12 ++++++++++++
 tests/ref/seek/vsynth_lena-mpeg1 | 38 +++++++++++++++++++-------------------
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 2c8fc69..1e0aa67 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -182,6 +182,18 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
     index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
                                     poutbuf_size, buf, buf_size);
     av_assert0(index > -0x20000000); // The API does not allow returning AVERROR codes
+#define FILL(name) if(s->name > 0 && avctx->name <= 0) avctx->name = s->name
+    if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+        FILL(coded_width);
+        FILL(coded_height);
+        FILL(width);
+        FILL(height);
+        if (s->format >= 0 && avctx->pix_fmt < 0)
+            avctx->pix_fmt = s->format;
+    } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+        if (s->format >= 0 && avctx->sample_fmt < 0)
+            avctx->sample_fmt = s->format;
+    }
     /* update the file pointer */
     if (*poutbuf_size) {
         /* fill the data for the current frame */
diff --git a/tests/ref/seek/vsynth_lena-mpeg1 b/tests/ref/seek/vsynth_lena-mpeg1
index 0ec751a..bbbdc2c 100644
--- a/tests/ref/seek/vsynth_lena-mpeg1
+++ b/tests/ref/seek/vsynth_lena-mpeg1
@@ -1,46 +1,46 @@
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:      0 size:  9779
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: NOPTS    pos: 124255 size: 11796
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 124255 size: 11796
 ret: 0         st: 0 flags:0  ts: 0.788334
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: NOPTS    pos:  76706 size: 10792
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  76706 size: 10792
 ret:-1         st: 0 flags:1  ts:-0.317499
 ret:-1         st:-1 flags:0  ts: 2.576668
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: NOPTS    pos: 124255 size: 11796
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 124255 size: 11796
 ret: 0         st: 0 flags:0  ts: 0.365002
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: NOPTS    pos:  37721 size:  9873
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  37721 size:  9873
 ret:-1         st: 0 flags:1  ts:-0.740831
 ret:-1         st:-1 flags:0  ts: 2.153336
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: NOPTS    pos:  76706 size: 10792
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  76706 size: 10792
 ret: 0         st: 0 flags:0  ts:-0.058330
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:      0 size:  9779
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st: 0 flags:1  ts: 2.835837
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: NOPTS    pos: 177099 size: 12057
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 177099 size: 12057
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: NOPTS    pos: 177099 size: 12057
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 177099 size: 12057
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: NOPTS    pos:  37721 size:  9873
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  37721 size:  9873
 ret: 0         st: 0 flags:0  ts:-0.481662
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:      0 size:  9779
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st: 0 flags:1  ts: 2.412505
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: NOPTS    pos: 177099 size: 12057
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 177099 size: 12057
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: NOPTS    pos: 124255 size: 11796
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 124255 size: 11796
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:      0 size:  9779
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st: 0 flags:0  ts:-0.904994
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: NOPTS    pos:      0 size:  9779
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:  9779
 ret: 0         st: 0 flags:1  ts: 1.989173
-ret: 0         st: 0 flags:1 dts: 1.920000 pts: NOPTS    pos: 177099 size: 12057
+ret: 0         st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 177099 size: 12057
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: NOPTS    pos:  76706 size: 10792
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:  76706 size: 10792
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret:-1         st: 0 flags:0  ts: 2.671674
 ret: 0         st: 0 flags:1  ts: 1.565841
-ret: 0         st: 0 flags:1 dts: 1.440000 pts: NOPTS    pos: 124255 size: 11796
+ret: 0         st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 124255 size: 11796
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: NOPTS    pos:  37721 size:  9873
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:  37721 size:  9873
 ret:-1         st:-1 flags:1  ts:-0.645825
-- 
2.7.3



More information about the ffmpeg-devel mailing list