From patchwork Sat Jul 23 14:09:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36912 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1047435pzb; Sat, 23 Jul 2022 07:12:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sNaaq/aUcb9DdICdubLjC45YOprfX/lBbefuH+xzbRX4JI/83CG2Dlq1dESS9lTSBTs/n2 X-Received: by 2002:a17:907:2723:b0:72b:5af3:5a11 with SMTP id d3-20020a170907272300b0072b5af35a11mr3594557ejl.584.1658585539971; Sat, 23 Jul 2022 07:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585539; cv=none; d=google.com; s=arc-20160816; b=VGezAxVMV+52t+xNAojIZeqcRDxpZrz/IaZfIcP0nPD15C0Id+hhPzB+30uBbLC+iS 4XVRtL/AXPVjZY0C651ybhnwDdAliAYzzkMs/vb1RneETzSTDOUKT7yXAus+OzRr4juC aimVwJ/sutGRaHi8C7TyT5dA6HH4q7lzSNk+75dUy6NWELvrpG9YBlhtCmRSH9yyU3ww pAgecV7ID4O0gOTtMZgxzxaHvmvR8YFuJQTuE0XxFAOcnwBT7hehalVnhunDaOR491q3 3+s2lhrB3Mf7CQZLW5y386ZMnEPS9LU8/epA8jFXPHyMl8qPXVCZcemyrB+mUEEDoAXr FhTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=iZTPI4b9Y7DowVj0cJ05NCUk3u1IHQfhYa2C59kh9rA=; b=ihbQNnoRpPknvmXREDJOxtz6kwnuU9fyxJnWNqah69hLe/4tQDfxPL6V/Uw/HZ8SbU RrX+tZlGvBv+nIUDWRCyvG8nkS2e+9UsDaMkIPH+Zh04GIf0Cv1uDxDJKaQM4UhnSyhZ w5fiQqcz3DJjgtyCHmpcViu1IqZMcGrMSKseP413fGsXciaYNiFu+52elOsb/KlKSXhG aQSoS6WcesbINdmCZ4MJ5De0SAbZierjjh8rpCBLg0PRHGs1U4GfTx41jVTw1PgQqMiV 43CPTglsD7H6uhZosivMr4eKU8Bhsmt24EiCdFbGgdtUY1Gh574ZulccgD5c8YLzMs7+ b84Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c10-20020aa7c74a000000b00435799ce323si7543268eds.190.2022.07.23.07.12.19; Sat, 23 Jul 2022 07:12:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3050868B8A4; Sat, 23 Jul 2022 17:10:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 895E768B7DC for ; Sat, 23 Jul 2022 17:10:28 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5F33424017E for ; Sat, 23 Jul 2022 16:10:27 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id SPNEiMTnucVk for ; Sat, 23 Jul 2022 16:10:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id BED16240687 for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 9FBCD3A03E5; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:43 +0200 Message-Id: <20220723140952.31814-18-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220723140952.31814-1-anton@khirnov.net> References: <20220723140952.31814-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/27] fftools/ffmpeg_opt: factor auto-mapping video out of open_output_file() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FqBQH+1Lvr7w --- fftools/ffmpeg_opt.c | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e6f2fb597a..4d2cd13107 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2495,6 +2495,50 @@ static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_si return 0; } +static void map_auto_video(OutputFile *of, AVFormatContext *oc, + OptionsContext *o) +{ + InputStream *ist; + + /* video: highest resolution */ + if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) { + int best_score = 0, idx = -1; + int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0); + for (int j = 0; j < nb_input_files; j++) { + InputFile *ifile = input_files[j]; + int file_best_score = 0, file_best_idx = -1; + for (int i = 0; i < ifile->nb_streams; i++) { + int score; + ist = input_streams[ifile->ist_index + i]; + score = ist->st->codecpar->width * ist->st->codecpar->height + + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) + + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); + 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 > file_best_score) { + if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) + continue; + file_best_score = score; + file_best_idx = ifile->ist_index + i; + } + } + if (file_best_idx >= 0) { + if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) + file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT); + if (file_best_score > best_score) { + best_score = file_best_score; + idx = file_best_idx; + } + } + } + if (idx >= 0) + new_video_stream(o, oc, idx); + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -2573,44 +2617,8 @@ static int open_output_file(OptionsContext *o, const char *filename) if (!o->nb_stream_maps) { char *subtitle_codec_name = NULL; /* pick the "best" stream of each type */ - - /* video: highest resolution */ - if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) { - int best_score = 0, idx = -1; - int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0); - for (j = 0; j < nb_input_files; j++) { - InputFile *ifile = input_files[j]; - int file_best_score = 0, file_best_idx = -1; - for (i = 0; i < ifile->nb_streams; i++) { - int score; - ist = input_streams[ifile->ist_index + i]; - score = ist->st->codecpar->width * ist->st->codecpar->height - + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) - + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); - 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 > file_best_score) { - if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) - continue; - file_best_score = score; - file_best_idx = ifile->ist_index + i; - } - } - if (file_best_idx >= 0) { - if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) - file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT); - if (file_best_score > best_score) { - best_score = file_best_score; - idx = file_best_idx; - } - } - } - if (idx >= 0) - new_video_stream(o, oc, idx); - } + if (!o->video_disable) + map_auto_video(of, oc, o); /* audio: most channels */ if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {