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

Rodger Combs rodger.combs at gmail.com
Tue Mar 15 14:36:41 CET 2016


This allows avformat_find_stream_info to finish without opening a decoder in
more cases.

Since decoders still export some information that the corresponding parsers
don't, this causes some fields to be unset in ffprobe output where the
decoder would previously have only been called in avformat_find_stream_info.
If this is a problem, the parsers should be updated to report that information
as well.
---
 libavcodec/parser.c                                | 12 +++++++
 tests/ref/fate/concat-demuxer-extended-lavf-mxf    |  2 +-
 .../ref/fate/concat-demuxer-extended-lavf-mxf_d10  |  2 +-
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf     |  2 +-
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10 |  2 +-
 tests/ref/fate/concat-demuxer-simple2-lavf-ts      |  2 +-
 tests/ref/seek/vsynth_lena-mpeg1                   | 38 +++++++++++-----------
 7 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index d25d261..34b2c86 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -180,6 +180,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/fate/concat-demuxer-extended-lavf-mxf b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
index 4caec5a..1678089 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
@@ -1 +1 @@
-37b4a84fce71b3f8b129f8b866c5f55a *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
+86707fda1a59f62bbe4cd1b29a2622b0 *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
index 1965050..19d2768 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
@@ -1 +1 @@
-2f5e935f86304c843be1454b1354a4b7 *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
+05ec301b5deaff5ddaffb133777c5261 *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
index c28db28..f2742b4 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
@@ -120,5 +120,5 @@ audio|1|65280|1.360000|65280|1.360000|1920|0.040000|N/A|N/A|3840|206848|K|1
 Strings Metadata|8
 video|0|37|1.480000|34|1.360000|1|0.040000|N/A|N/A|24786|211456|K|1
 Strings Metadata|8
-0|mpeg2video|4|video|1/50|[0][0][0][0]|0x0000|352|288|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|00:00:00:00|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|104857200|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
+0|mpeg2video|unknown|video|1/50|[0][0][0][0]|0x0000|352|288|0|0|1|1:1|11:9|yuv420p|-99|tv|unknown|unknown|unknown|unspecified|N/A|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|104857200|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
 1|pcm_s16le|unknown|audio|1/48000|[0][0][0][0]|0x0000|s16|48000|1|unknown|16|N/A|0/0|0/0|1/48000|0|0.000000|N/A|N/A|768000|N/A|N/A|N/A|N/A|50|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10 b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
index 3b6e3fe..8a6a0f5 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
@@ -78,5 +78,5 @@ video|0|34|1.360000|34|1.360000|1|0.040000|N/A|N/A|150000|1923072|K|1
 Strings Metadata|8
 audio|1|65280|1.360000|65280|1.360000|1920|0.040000|N/A|N/A|7680|2073600|K|1
 Strings Metadata|8
-0|mpeg2video|0|video|1/50|[0][0][0][0]|0x0000|720|608|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|00:00:00:00|1|N/A|25/1|25/1|1/25|0|0.000000|N/A|N/A|30000000|30000000|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
+0|mpeg2video|unknown|video|1/50|[0][0][0][0]|0x0000|720|608|0|0|0|1:1|45:38|yuv422p|-99|tv|unknown|unknown|unknown|unspecified|N/A|1|N/A|25/1|25/1|1/25|0|0.000000|N/A|N/A|30000000|30000000|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
 1|pcm_s16le|unknown|audio|1/48000|[0][0][0][0]|0x0000|s16|48000|2|unknown|16|N/A|0/0|0/0|1/48000|0|0.000000|N/A|N/A|1536000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
diff --git a/tests/ref/fate/concat-demuxer-simple2-lavf-ts b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
index 4a50f52..7e0febb 100644
--- a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
+++ b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
@@ -148,4 +148,4 @@ video|1|168382|1.870911|164782|1.830911|3600|0.040000|N/A|N/A|24800|189692|K
 video|1|171982|1.910911|168382|1.870911|3600|0.040000|N/A|N/A|17454|216388|_
 video|1|175582|1.950911|171982|1.910911|3600|0.040000|N/A|N/A|15033|235000|_
 0|mp2|unknown|audio|1/44100|[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
-1|mpeg2video|4|video|1/50|[2][0][0][0]|0x0002|352|288|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|00:00:00:00|1|N/A|25/1|25/1|1/90000|N/A|N/A|N/A|N/A|N/A|104857200|N/A|N/A|N/A|60|0|0|0|0|0|0|0|0|0|0|0
+1|mpeg2video|unknown|video|1/50|[2][0][0][0]|0x0002|352|288|0|0|1|0:1|0:1|yuv420p|-99|tv|unknown|unknown|unknown|unspecified|N/A|1|N/A|25/1|25/1|1/90000|N/A|N/A|N/A|N/A|N/A|104857200|N/A|N/A|N/A|60|0|0|0|0|0|0|0|0|0|0|0
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.2



More information about the ffmpeg-devel mailing list