diff mbox series

[FFmpeg-devel,3/3] ffmpeg.c: refactor picking default video stream

Message ID 20201014085311.14728-3-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/3] ffmpeg.c: rename 'area' to 'score' | expand

Checks

Context Check Description
andriy/PPC64_make warning Make failed
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Anton Khirnov Oct. 14, 2020, 8:53 a.m. UTC
Do not bother computing the score for streams that are going to be
skipped.
This is easier to follow.
---
 fftools/ffmpeg_opt.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index afef23919c..eebb678e5e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2218,6 +2218,11 @@  static int open_output_file(OptionsContext *o, const char *filename)
                 double score;
                 ist = input_streams[i];
 
+                if (ist->st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ||
+                    ist->user_set_discard == AVDISCARD_ALL              ||
+                    (qcr == MKTAG('A', 'P', 'I', 'C') && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)))
+                    continue;
+
                 /* base score is just the area in pixels */
                 score = (double)ist->st->codecpar->width * ist->st->codecpar->height;
                 /* add a fractional part favoring higher bitrate among same-area streams */
@@ -2230,14 +2235,10 @@  static int open_output_file(OptionsContext *o, const char *filename)
                 if (ist->st->disposition & AV_DISPOSITION_DEFAULT)
                     score = DBL_MAX;
 
-                if (ist->user_set_discard == AVDISCARD_ALL)
-                    continue;
                 if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
                     score = 1;
-                if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-                    score > best_score) {
-                    if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
-                        continue;
+
+                if (score > best_score) {
                     best_score = score;
                     idx = i;
                 }