From patchwork Wed Aug 3 13:58:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457450pzb; Wed, 3 Aug 2022 06:59:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOo8h1DhQhjQb8tJISpPrzFRTGonbroxorwLChCIJNDfF9zGDVsx9EBWIoK2xdvE4NPsNA X-Received: by 2002:a17:906:fe0b:b0:730:3646:d177 with SMTP id wy11-20020a170906fe0b00b007303646d177mr18291913ejb.688.1659535147648; Wed, 03 Aug 2022 06:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535147; cv=none; d=google.com; s=arc-20160816; b=OO1yHghfwdL29mOrss0lpHRS0uKFC1UYhOrpYJaXkp5/4LTjf8LNTPK63lRTOpniaA fLRbjJQMu/uMCy+38PrmLZStNx+BP9vLln5BpslxcDccK3KIYdp8ia8PJw3apOHmX/Es 2rzcK0RNJauLtG5gED25ynQm1AJmUdDllxxu/ANxbtkwa4lLvTLBzP0O+KTAHcrOVPGS E3JeG16Hljkuqt37gTbHwFDRdr0hDeB7ls5jyPddFMkDEb7oWmv/roYWNDsfRGu3b7Tg BnZSDlcUeL034/YGSFJPaz5MakCYDemB7cFnXbJ0hz5+OBJexAXhTmC1COFNfDI13NXJ mSlw== 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:message-id:date:to:from :delivered-to; bh=TN/96EK/RX3yZA+qgRRi/7KZ1KdF+pNMGUPbavmBPvk=; b=bb+LweVij+YiZsvdNgRENAB5VmCMC3yFteKQ/VrJfMbhMFlaEJlqWJI265tTIW0Asx yFsMeaBtfqHBxtXNKaERB2xrVVpcz7O6K5th+RPekyBJoPZ7KOgtDJUyWGmaDVwrT138 BuWXxs7sTRHVzFMBkSuMbOzkd07dSNeoD6u4YV+g4Y1+0FkUU5bEDP1GvLzCbZXsThjY cZldqcg7141srg9OgTQiTUR+Fqy803czP/edudeco8h7HOE/6ho5NxTr0cEHtvgLX7ww 2QXlYnqU03eX8ZfC2o93fHeukciA4EI/p2Y+UPVR0+0hn7mAv5nmIeVfTRYMcEpt6UE1 hQbw== 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 jg42-20020a170907972a00b007307a8f0c3fsi8374019ejc.381.2022.08.03.06.59.06; Wed, 03 Aug 2022 06:59:07 -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 C618168B7E2; Wed, 3 Aug 2022 16:59:02 +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 1848768B4DC for ; Wed, 3 Aug 2022 16:58:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5985B24068F for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id F4__uKAC0lfN for ; Wed, 3 Aug 2022 15:58:54 +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 94B1F2400F5 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id DD39F3A03EF; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:20 +0200 Message-Id: <20220803135844.16662-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments 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: cpq+DHTxQMlX --- fftools/ffmpeg_opt.c | 79 ++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a8b064e070..0d5323ea73 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2742,6 +2742,48 @@ loop_end: } } +static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) +{ + OutputStream *ost; + int err; + + for (int i = 0; i < o->nb_attachments; i++) { + AVIOContext *pb; + uint8_t *attachment; + const char *p; + int64_t len; + + if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) { + av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n", + o->attachments[i]); + exit_program(1); + } + if ((len = avio_size(pb)) <= 0) { + av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n", + o->attachments[i]); + exit_program(1); + } + if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE || + !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) { + av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n", + o->attachments[i]); + exit_program(1); + } + avio_read(pb, attachment, len); + memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); + + ost = new_attachment_stream(o, oc, -1); + ost->stream_copy = 0; + ost->attachment_filename = o->attachments[i]; + ost->st->codecpar->extradata = attachment; + ost->st->codecpar->extradata_size = len; + + p = strrchr(o->attachments[i], '/'); + av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); + avio_closep(&pb); + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -2831,42 +2873,7 @@ static int open_output_file(OptionsContext *o, const char *filename) map_manual(of, oc, o, &o->stream_maps[i]); } - /* handle attached files */ - for (i = 0; i < o->nb_attachments; i++) { - AVIOContext *pb; - uint8_t *attachment; - const char *p; - int64_t len; - - if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) { - av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n", - o->attachments[i]); - exit_program(1); - } - if ((len = avio_size(pb)) <= 0) { - av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n", - o->attachments[i]); - exit_program(1); - } - if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE || - !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) { - av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n", - o->attachments[i]); - exit_program(1); - } - avio_read(pb, attachment, len); - memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); - - ost = new_attachment_stream(o, oc, -1); - ost->stream_copy = 0; - ost->attachment_filename = o->attachments[i]; - ost->st->codecpar->extradata = attachment; - ost->st->codecpar->extradata_size = len; - - p = strrchr(o->attachments[i], '/'); - av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE); - avio_closep(&pb); - } + of_add_attachments(oc, o); if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->url, 1); From patchwork Wed Aug 3 13:58:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457519pzb; Wed, 3 Aug 2022 06:59:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v+ZqU8dtoreSGUQvCyaskLqv3Dyyzh8p8+MsYv5SthdnrdIzg9DZGB6o23/JFgS0hoSP2x X-Received: by 2002:a05:6402:2804:b0:439:83c2:8be2 with SMTP id h4-20020a056402280400b0043983c28be2mr26518179ede.292.1659535158547; Wed, 03 Aug 2022 06:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535158; cv=none; d=google.com; s=arc-20160816; b=MBpWJKvlIm+IwA9aUTPPNDAClVMRhGk+joN460CgpyjLTajNdovuVq9X264LNaIlxI kIYc2/mR9k7gB4ipjZQtTvoyd5rXM+czT2qzwETtGjoFZq6Hztrk57N3JSOGDdlHV+PT NQq/9WRGYJ2wEn3KvKr77/naYAwnI5ZMWEadL3uy1W8oG5Ynsn2iVX8W7Lg1QXx4ma6k 1M8/NuA5idivyf7rY6lBBGjJ8P6XC95udrBg1xY39CM+kfaxNs/Srvz1wx3D5NYXRGTa 9Y3DXW4mVLn58cpjGVEipkcewbVPTVXMWp1JGWFxVGuzxRS7z41Byj8rWMx69VYkn0J4 HzWw== 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=XsB/W9SCpuDuFY4LdTRFuCDLsuWC9cAO24odP/Onz8I=; b=KNm9w9wVGJ4gAKrbJ2RCe/dtkSFFh3C8VABtK8OKckCktBlVCZ0QMfG0Fl8D6xEI+B 3da/Utd4O7/eP+J55TPl8C8wUoVFylUOWKWDbTrBnYQ3mjvhh+KI1l7JFKFdamHzb3um 8ajT6OrYsk5zMkQaKlx8ziKuLOkJ6yx+vi5iSsv3toMHUQmr5Yfe+wH3Pg7sSjeq/flz bQs0dbTivWZ/wiahybAyXKOMZD81BWTQpTIWYhCm+PV/BECzJ88xcl4Qvep/IgSV88SI xbrUX0OskI11hPZ52yvI/Igbj8VcfXzV8EQaOj9kOmsiwaWqmoQslIUHmKisagJUOGEI 0tJQ== 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 cr12-20020a170906d54c00b007307fd1b9bbsi8926664ejc.589.2022.08.03.06.59.18; Wed, 03 Aug 2022 06:59:18 -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 6439868B7AE; Wed, 3 Aug 2022 16:59:04 +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 6E85A68B4DC for ; Wed, 3 Aug 2022 16:58:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 050C12400F5 for ; Wed, 3 Aug 2022 15:58:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hGMV47hkPNw8 for ; Wed, 3 Aug 2022 15:58:55 +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 A88AA24017E for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id E144A3A03FD; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:21 +0200 Message-Id: <20220803135844.16662-2-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs 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: ViRz0FLLqXQJ --- fftools/ffmpeg_opt.c | 135 ++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 0d5323ea73..ccab98406e 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2784,6 +2784,75 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) } } +static void of_add_programs(AVFormatContext *oc, const OptionsContext *o) +{ + /* process manually set programs */ + for (int i = 0; i < o->nb_program; i++) { + const char *p = o->program[i].u.str; + int progid = i+1; + AVProgram *program; + + while(*p) { + const char *p2 = av_get_token(&p, ":"); + const char *to_dealloc = p2; + char *key; + if (!p2) + break; + + if(*p) p++; + + key = av_get_token(&p2, "="); + if (!key || !*p2) { + av_freep(&to_dealloc); + av_freep(&key); + break; + } + p2++; + + if (!strcmp(key, "program_num")) + progid = strtol(p2, NULL, 0); + av_freep(&to_dealloc); + av_freep(&key); + } + + program = av_new_program(oc, progid); + + p = o->program[i].u.str; + while(*p) { + const char *p2 = av_get_token(&p, ":"); + const char *to_dealloc = p2; + char *key; + if (!p2) + break; + if(*p) p++; + + key = av_get_token(&p2, "="); + if (!key) { + av_log(NULL, AV_LOG_FATAL, + "No '=' character in program string %s.\n", + p2); + exit_program(1); + } + if (!*p2) + exit_program(1); + p2++; + + if (!strcmp(key, "title")) { + av_dict_set(&program->metadata, "title", p2, 0); + } else if (!strcmp(key, "program_num")) { + } else if (!strcmp(key, "st")) { + int st_num = strtol(p2, NULL, 0); + av_program_add_stream_index(oc, progid, st_num); + } else { + av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key); + exit_program(1); + } + av_freep(&to_dealloc); + av_freep(&key); + } + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -3073,71 +3142,7 @@ static int open_output_file(OptionsContext *o, const char *filename) } } - /* process manually set programs */ - for (i = 0; i < o->nb_program; i++) { - const char *p = o->program[i].u.str; - int progid = i+1; - AVProgram *program; - - while(*p) { - const char *p2 = av_get_token(&p, ":"); - const char *to_dealloc = p2; - char *key; - if (!p2) - break; - - if(*p) p++; - - key = av_get_token(&p2, "="); - if (!key || !*p2) { - av_freep(&to_dealloc); - av_freep(&key); - break; - } - p2++; - - if (!strcmp(key, "program_num")) - progid = strtol(p2, NULL, 0); - av_freep(&to_dealloc); - av_freep(&key); - } - - program = av_new_program(oc, progid); - - p = o->program[i].u.str; - while(*p) { - const char *p2 = av_get_token(&p, ":"); - const char *to_dealloc = p2; - char *key; - if (!p2) - break; - if(*p) p++; - - key = av_get_token(&p2, "="); - if (!key) { - av_log(NULL, AV_LOG_FATAL, - "No '=' character in program string %s.\n", - p2); - exit_program(1); - } - if (!*p2) - exit_program(1); - p2++; - - if (!strcmp(key, "title")) { - av_dict_set(&program->metadata, "title", p2, 0); - } else if (!strcmp(key, "program_num")) { - } else if (!strcmp(key, "st")) { - int st_num = strtol(p2, NULL, 0); - av_program_add_stream_index(oc, progid, st_num); - } else { - av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key); - exit_program(1); - } - av_freep(&to_dealloc); - av_freep(&key); - } - } + of_add_programs(oc, o); /* process manually set metadata */ for (i = 0; i < o->nb_metadata; i++) { From patchwork Wed Aug 3 13:58:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37113 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459186pzb; Wed, 3 Aug 2022 07:01:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ueYNImDTv4HhsBwdQ8N6AByEmS6rJiH95RBFM+g/yTXu1FJJjwh8lYupGBwtidEs40Gx4J X-Received: by 2002:a05:6402:430e:b0:43d:1cf6:61ec with SMTP id m14-20020a056402430e00b0043d1cf661ecmr24853639edc.194.1659535304818; Wed, 03 Aug 2022 07:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535304; cv=none; d=google.com; s=arc-20160816; b=zi4nbXdY2nZCbL7t9pymLFfvJGeb6aF/22d4o+vWLGMJkuzwG6v1+PCAZiealqsNlb Ej4nuZi444X6mIVGclqSK2h8XymleCMI53edTRCkjZafCfpKnyHyS+l8NfuAZbhepT+w GXMgaLcjw7SfxQIqpNrY66GYYL+9PKmVDYdBK1xh3l+BL3uFcQt1ET81oUBe9WNq+YaC TtkJExqoCbP248s+8OZyC6/SYdXK+LZvkRXq8OsfxqY99UesFPJaY2LSLk74CplUwkRq wLpeey2e1kkJAmWepWAK3fEKZZ5DcfRLDJ3kLvOnk8xEnzcnaJfbvrxbWC0d6+QLZQUx 836w== 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=KZ0E4kbxsxT5MD/BpMhH02RKGgAdLUBd07Ln9JLkWtI=; b=YV/oZLlOiy2qdt28OTZvjlS1LG32wVcg1ps6+NMYNpOqvbt8ZTe46XQ9errZTlISgQ oJwWGIQAFgqkcd5fcAXFeaDf3H4wkKC+yT/YLzG+JE6jXqoIsn73y+tTQCU8Gm2b42Oj tKqqQH07vJCLD2HlmvCOp+qpaglrVaRHBUsifEFxvJPLit+ftRHkr3RZPk5n+EL5ABr0 PCrUiQfFFls+NavnAsjN+F/nzaDw9VcPPC1PBbJ9owz7mCp0ztrDeuHUdnJ8gqF3lNrS kydRSRUYqIv5cbHfVhh1sPQ6hdhTr9qe1NesB5ULtC0sO+hSBeWxhcuKUELIswhX+IA1 iapg== 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 q1-20020a056402248100b0043cdfee4b1fsi14126051eda.383.2022.08.03.07.01.44; Wed, 03 Aug 2022 07:01:44 -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 6BA8E68B978; Wed, 3 Aug 2022 16:59:18 +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 CFC1F68B7E6 for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B9840240512 for ; Wed, 3 Aug 2022 15:58:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1parcER_FSp5 for ; Wed, 3 Aug 2022 15:58:56 +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 AA3E52404FE for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id E5E3F3A0404; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:22 +0200 Message-Id: <20220803135844.16662-3-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg_opt: move adding metadata 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: J7HrpkeJncPn --- fftools/ffmpeg_opt.c | 125 ++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ccab98406e..aa240107dc 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2853,12 +2853,73 @@ static void of_add_programs(AVFormatContext *oc, const OptionsContext *o) } } +static void of_add_metadata(AVFormatContext *oc, const OptionsContext *o) +{ + for (int i = 0; i < o->nb_metadata; i++) { + AVDictionary **m; + char type, *val; + const char *stream_spec; + int index = 0, ret = 0; + + val = strchr(o->metadata[i].u.str, '='); + if (!val) { + av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n", + o->metadata[i].u.str); + exit_program(1); + } + *val++ = 0; + + parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec); + if (type == 's') { + for (int j = 0; j < oc->nb_streams; j++) { + OutputStream *ost = output_streams[nb_output_streams - oc->nb_streams + j]; + if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) { + if (!strcmp(o->metadata[i].u.str, "rotate")) { + char *tail; + double theta = av_strtod(val, &tail); + if (!*tail) { + ost->rotate_overridden = 1; + ost->rotate_override_value = theta; + } + } else { + av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0); + } + } else if (ret < 0) + exit_program(1); + } + } else { + switch (type) { + case 'g': + m = &oc->metadata; + break; + case 'c': + if (index < 0 || index >= oc->nb_chapters) { + av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index); + exit_program(1); + } + m = &oc->chapters[index]->metadata; + break; + case 'p': + if (index < 0 || index >= oc->nb_programs) { + av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index); + exit_program(1); + } + m = &oc->programs[index]->metadata; + break; + default: + av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); + exit_program(1); + } + av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); + } + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; int i, j, err; OutputFile *of; - OutputStream *ost; AVDictionary *unused_opts = NULL, *format_opts = NULL; const AVDictionaryEntry *e = NULL; @@ -3143,67 +3204,7 @@ static int open_output_file(OptionsContext *o, const char *filename) } of_add_programs(oc, o); - - /* process manually set metadata */ - for (i = 0; i < o->nb_metadata; i++) { - AVDictionary **m; - char type, *val; - const char *stream_spec; - int index = 0, j, ret = 0; - - val = strchr(o->metadata[i].u.str, '='); - if (!val) { - av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n", - o->metadata[i].u.str); - exit_program(1); - } - *val++ = 0; - - parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec); - if (type == 's') { - for (j = 0; j < oc->nb_streams; j++) { - ost = output_streams[nb_output_streams - oc->nb_streams + j]; - if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) { - if (!strcmp(o->metadata[i].u.str, "rotate")) { - char *tail; - double theta = av_strtod(val, &tail); - if (!*tail) { - ost->rotate_overridden = 1; - ost->rotate_override_value = theta; - } - } else { - av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0); - } - } else if (ret < 0) - exit_program(1); - } - } - else { - switch (type) { - case 'g': - m = &oc->metadata; - break; - case 'c': - if (index < 0 || index >= oc->nb_chapters) { - av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index); - exit_program(1); - } - m = &oc->chapters[index]->metadata; - break; - case 'p': - if (index < 0 || index >= oc->nb_programs) { - av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index); - exit_program(1); - } - m = &oc->programs[index]->metadata; - break; - default: - av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); - exit_program(1); - } - av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); - } - } + of_add_metadata(oc, o); err = set_dispositions(of, oc); if (err < 0) { From patchwork Wed Aug 3 13:58:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37100 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457627pzb; Wed, 3 Aug 2022 06:59:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vMxnyHKIeZErRJnYxBBr1GY4bUyhLp+0xkrzV14RU1d+kq+TZibrDky3XG8WUVWJ0eKmY9 X-Received: by 2002:aa7:d0c8:0:b0:43c:f071:992a with SMTP id u8-20020aa7d0c8000000b0043cf071992amr25914815edo.418.1659535169519; Wed, 03 Aug 2022 06:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535169; cv=none; d=google.com; s=arc-20160816; b=RkK3lH9qyN1oraiO8pMSLr7SQHGHM9jEH4x/BkXnLIwpelQgWaVVSRegbe3qIx7Fnn wVYGIAMDREHSXSfsCpxG8UzUUyBdApqoz+91EoUXmN08/9KlobHOokff1HfCX1fxxdnO LO9E8H+8PqnH49pXSBT4SA8wAPEOaADHWeHJIATl6Pj1w+A+iKQ0y7gi5YPmdPc77qtm 0Vxb+/zsM/kexo0CadRrjj8uYcE57lkN3dtthwPseUp9VtCKhe5IB0cEw/5XBVmZOnzP +ZfqOVTcXPy/R5Bgb88b4wBHw5Ozow3zXeIfN/zbSecNGDFMx0lUgVrPe04xqp2Tg7R+ bwsQ== 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=FA/K4RxuTtKHEuoEA0vasgw+g6imeuvFeWtJK7apnTk=; b=QFiPo7dgI5cNkVf6RnuG/eR0zsQjZzqtOQ6wJMJXW62ztZrb0jqhDDZPoWED9L8OxF 1A4zQZ42kPQfQVhmKQ04xstfjQ8WIhMzUbGaJh+XSrZOM2hphVi0+7hefcr4Kygomoxg bARCfGfJVH4UGe59gKYyd+rniT5nLWDsFCpS6KbezDy4kC4hgftbu9w8rSSLF01ArUYL yaQV7WCMPxfcgKfPj5/ISdz/V92/zE6k+pKArbEuncwsfRJ5HF0/8qf+MEgWj5dc1o0r bL1hWu6eRtO+1tF6kqr60MqwZPMv77s5aJuYh5zj984wWq5+/oZCcMG9SN8saHZS2j24 EKmA== 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 gr19-20020a170906e2d300b00718d2d8bfbfsi4717730ejb.316.2022.08.03.06.59.29; Wed, 03 Aug 2022 06:59:29 -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 7854B68B82E; Wed, 3 Aug 2022 16:59:05 +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 9837968B4DC for ; Wed, 3 Aug 2022 16:58:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 33CE624017E for ; Wed, 3 Aug 2022 15:58:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 66QcMH4jy6Qd for ; Wed, 3 Aug 2022 15:58:54 +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 96BE8240179 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id E9E153A041D; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:23 +0200 Message-Id: <20220803135844.16662-4-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_hw: stop logging to the decoder context 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: PlPtFdHwPDxw Only the decoder itself should do that. Use NULL as is done by all other logging code in ffmpeg. --- fftools/ffmpeg_hw.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index 14e702bd92..8acfeaf08f 100644 --- a/fftools/ffmpeg_hw.c +++ b/fftools/ffmpeg_hw.c @@ -339,7 +339,7 @@ int hw_device_setup_for_decode(InputStream *ist) if (ist->hwaccel_id == HWACCEL_AUTO) { ist->hwaccel_device_type = dev->type; } else if (ist->hwaccel_device_type != dev->type) { - av_log(ist->dec_ctx, AV_LOG_ERROR, "Invalid hwaccel device " + av_log(NULL, AV_LOG_ERROR, "Invalid hwaccel device " "specified for decoder: device %s of type %s is not " "usable with hwaccel %s.\n", dev->name, av_hwdevice_get_type_name(dev->type), @@ -390,7 +390,7 @@ int hw_device_setup_for_decode(InputStream *ist) type = config->device_type; dev = hw_device_get_by_type(type); if (dev) { - av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " + av_log(NULL, AV_LOG_INFO, "Using auto " "hwaccel type %s with existing device %s.\n", av_hwdevice_get_type_name(type), dev->name); } @@ -408,12 +408,12 @@ int hw_device_setup_for_decode(InputStream *ist) continue; } if (ist->hwaccel_device) { - av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " + av_log(NULL, AV_LOG_INFO, "Using auto " "hwaccel type %s with new device created " "from %s.\n", av_hwdevice_get_type_name(type), ist->hwaccel_device); } else { - av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " + av_log(NULL, AV_LOG_INFO, "Using auto " "hwaccel type %s with new default device.\n", av_hwdevice_get_type_name(type)); } @@ -421,7 +421,7 @@ int hw_device_setup_for_decode(InputStream *ist) if (dev) { ist->hwaccel_device_type = type; } else { - av_log(ist->dec_ctx, AV_LOG_INFO, "Auto hwaccel " + av_log(NULL, AV_LOG_INFO, "Auto hwaccel " "disabled: no device found.\n"); ist->hwaccel_id = HWACCEL_NONE; return 0; @@ -429,7 +429,7 @@ int hw_device_setup_for_decode(InputStream *ist) } if (!dev) { - av_log(ist->dec_ctx, AV_LOG_ERROR, "No device available " + av_log(NULL, AV_LOG_ERROR, "No device available " "for decoder: device type %s needed for codec %s.\n", av_hwdevice_get_type_name(type), ist->dec->name); return err; From patchwork Wed Aug 3 13:58:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37101 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457709pzb; Wed, 3 Aug 2022 06:59:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR53dpBdaK9OCagBSL4Q0NIT02XYQdBol7ZOOBdScAH6KCR8XhP1vST+OuyXbKtJCawXpHib X-Received: by 2002:a17:906:9bdd:b0:730:5b04:7298 with SMTP id de29-20020a1709069bdd00b007305b047298mr14895287ejc.180.1659535179986; Wed, 03 Aug 2022 06:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535179; cv=none; d=google.com; s=arc-20160816; b=sNZ+BKLXCRX3/Wzg2V6QKaqL5lsxb209oHAw/cZo5R2boPFNxosDAnROLfaGL8PlN9 YbtXkic8jE/HHYafIiTkIjKdm+rOiGoSxZQS8bP1No/ZJCvIueZNuPxlw3/YlM8Y1oYt 6Uux5jJi58FMPdmEmYJx77dOi4KtAWBzwwQvqE4gi9tAmUvFpMa1OEVnVvnKe7wIehGi T9zStfnxadFevBAhVIMUr8vTwNanUSnjakLISbc+QMPciCFxCC8ylCHdiqWHuoMwK/Kr Xn0YyGpoReHBjW85D2Pejjgo08BMSSItggmo/A8ViL7EhCP3ja7i5uLZWlgjV7dv37V/ 6tyA== 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=r6uoiOOIyw3EWAtcKU09R6vveo7qXoOhMCotxchTyPg=; b=jK0GkO9xqJMsYfyZfE87DO6NlQzyTCEUoVqpWsVlReFA0Tgt8Yh5oiiFFDQ4Nak1Ag mTZ4sjKYn/Nx8sNvENj9HdWuJ9wxGEev18bREcWR4xHDbS+QpNHJ0JB6VD8UcDiKT53O pAklbDNQgkDswkzfaep/vDwmJtuRqy0SZJ20EnmioYlR/ENq11FBDbXDNeLO9/TUamgC rlseZEngj0abgJOEr9UFF3xdcPtPHDnDHdtFrTghp4DMysG5balt5YOfAMl891ONz2XJ XgY8c8LY/P7jJ48mwLFV4jmFEoM2fG5hR8UYSDMZqEFJnn6N5chEflEwNigi74jCgSJV Dxwg== 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 he14-20020a1709073d8e00b007306595dfeesi12038882ejc.221.2022.08.03.06.59.39; Wed, 03 Aug 2022 06:59:39 -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 83BD968B88B; Wed, 3 Aug 2022 16:59:06 +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 2F82B68B4DC for ; Wed, 3 Aug 2022 16:58:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BFD7B240179 for ; Wed, 3 Aug 2022 15:58:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id SU-dkcmnAS_g for ; Wed, 3 Aug 2022 15:58:56 +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 A69D524017C for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id EE4013A041E; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:24 +0200 Message-Id: <20220803135844.16662-5-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: stop accessing the decoder context unnecessarily 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: 1G2FQelj5Ur1 The same information is available from AVStream.codecpar. This will allow to stop allocating a decoder unless decoding is actually performed. --- fftools/ffmpeg.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4746742c02..62ff1a98df 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1495,7 +1495,7 @@ static void print_final_stats(int64_t total_size) for (j = 0; j < f->nb_streams; j++) { InputStream *ist = input_streams[f->ist_index + j]; - enum AVMediaType type = ist->dec_ctx->codec_type; + enum AVMediaType type = ist->st->codecpar->codec_type; total_size += ist->data_size; total_packets += ist->nb_packets; @@ -1915,11 +1915,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p if (pkt->dts == AV_NOPTS_VALUE) { opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase); } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size); + int duration = av_get_audio_frame_duration2(ist->st->codecpar, pkt->size); if(!duration) - duration = ist->dec_ctx->frame_size; + duration = ist->st->codecpar->frame_size; opkt->dts = av_rescale_delta(ist->st->time_base, pkt->dts, - (AVRational){1, ist->dec_ctx->sample_rate}, duration, + (AVRational){1, ist->st->codecpar->sample_rate}, duration, &ist->filter_in_rescale_delta_last, ost->mux_timebase); /* dts will be set immediately afterwards to what pts is now */ opkt->pts = opkt->dts - ost_tb_start_time; @@ -2394,6 +2394,7 @@ static int send_filter_eof(InputStream *ist) /* pkt = NULL means EOF (needed to flush decoder buffers) */ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { + const AVCodecParameters *par = ist->st->codecpar; int ret = 0, i; int repeating = 0; int eof_reached = 0; @@ -2426,7 +2427,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (pkt && pkt->dts != AV_NOPTS_VALUE) { ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); - if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed) + if (par->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed) ist->next_pts = ist->pts = ist->dts; } @@ -2440,7 +2441,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo ist->pts = ist->next_pts; ist->dts = ist->next_dts; - switch (ist->dec_ctx->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, &decode_failed); @@ -2537,12 +2538,12 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo /* handle stream copy */ if (!ist->decoding_needed && pkt) { ist->dts = ist->next_dts; - switch (ist->dec_ctx->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: av_assert1(pkt->duration >= 0); - if (ist->dec_ctx->sample_rate) { - ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) / - ist->dec_ctx->sample_rate; + if (par->sample_rate) { + ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) / + par->sample_rate; } else { ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); } @@ -4000,7 +4001,8 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + ifile->ist_index + pkt->stream_index, + av_get_media_type_string(ist->st->codecpar->codec_type), av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), @@ -4076,8 +4078,8 @@ static int process_input(int file_index) pkt->dts *= ist->ts_scale; pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); - if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || - ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && + if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) && pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) { int64_t delta = pkt_dts - ifile->last_ts; @@ -4114,8 +4116,8 @@ static int process_input(int file_index) disable_discontinuity_correction = 0; } - if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || - ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && + if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) && pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) { int64_t delta = pkt_dts - ist->next_dts; @@ -4128,7 +4130,7 @@ static int process_input(int file_index) "timestamp discontinuity for stream #%d:%d " "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n", ist->file_index, ist->st->index, ist->st->id, - av_get_media_type_string(ist->dec_ctx->codec_type), + av_get_media_type_string(ist->st->codecpar->codec_type), delta, ifile->ts_offset); pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if (pkt->pts != AV_NOPTS_VALUE) @@ -4157,7 +4159,8 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + ifile->ist_index + pkt->stream_index, + av_get_media_type_string(ist->st->codecpar->codec_type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base), From patchwork Wed Aug 3 13:58:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37102 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457791pzb; Wed, 3 Aug 2022 06:59:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vS5X/28yRM1A2AcczRADN99qJpOdhf0bA8b62sGiRvs2NTNRMTvY8aDFH7PqYOJSSZNgTc X-Received: by 2002:a05:6402:13c1:b0:43b:e330:9bbf with SMTP id a1-20020a05640213c100b0043be3309bbfmr25680446edx.417.1659535189592; Wed, 03 Aug 2022 06:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535189; cv=none; d=google.com; s=arc-20160816; b=Iquu2/lk2n1lpi5is+AvKv2zTch6VKDpNm9pu9uxZXvfe1TOIINjttFvO0Kn/3SDtG k5VDYDGmGQJ/5JfLxKkkjAn9kkYz52LfnM3Tvl2FiJ6iOUZKcZVUHxagIvq4oeR2r9fI ihrB1qb1Pu/Rb0CWCzzkPA0IWqdzPLfJCY43PfNpmTRuJZTtUSX5OlGs9cPWRbhFnv6i x+0+U0V3LF88W1zfxNO3YtiFJVqftMYscni8Tl1UHZVP8b4AuGX5d3okG2M7EEpPYEeC 3M8HV7V8md3YQ71s/6Um7h2jTk6rUPMF/9ZVqpSwbbYHE4+Qwp7SsEpt5ArnqF8+ezxu 6gng== 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=nDzgVBh0SJCHfG4ZUHwvyoIR7rgS1U6Dj7bY5P1pWTU=; b=OylIgBvvw+v8yAU7n+1xpphS/0V+HR/1l9qYoWPUXjc7m4XlJlghTNN3PuDX7sWhN0 yTww3K3sR4XwqBwGpL35o87kElxbIB2pbZ8xaq2yNC3idjnSmHvKzblP0O+BbZtBMjD6 ayx+psE6PtrSZtzqLeFPGXqkh0fAktq3Z75AL5PU2O34HAKtbEcZ84FhgvDMtvBClzuB RSN6kH8iK/51SIEewgkW7fNiT52H2ZxoaXb9cAtmyievCxQFPSZXSfRBzbsB62Z1iawR TfgzDeuqWwxn+zLiHJBMdSbclb6WirO3KLWYSa6G1QMKFuXyb8EpbvxoAgex0KeTQrU9 uviw== 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 nc22-20020a1709071c1600b0072b66c5cdf0si2222476ejc.481.2022.08.03.06.59.49; Wed, 03 Aug 2022 06:59:49 -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 8BB5A68B8BF; Wed, 3 Aug 2022 16:59:07 +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 A9C9A68B7C2 for ; Wed, 3 Aug 2022 16:58:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4232524017C for ; Wed, 3 Aug 2022 15:58:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id w80LGdEBQj2H for ; Wed, 3 Aug 2022 15:58:56 +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 BE362240506 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id F2B0B3A0449; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:25 +0200 Message-Id: <20220803135844.16662-6-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg_opt: drop redundant decoder selection 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: /qsEXelTC8yt A decoder is already selected above, in choose_decoder(). --- fftools/ffmpeg_opt.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index aa240107dc..12cde4b617 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1078,9 +1078,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: - if(!ist->dec) - ist->dec = avcodec_find_decoder(par->codec_id); - // avformat_find_stream_info() doesn't set this for us anymore. ist->dec_ctx->framerate = st->avg_frame_rate; @@ -1104,8 +1101,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) case AVMEDIA_TYPE_DATA: case AVMEDIA_TYPE_SUBTITLE: { char *canvas_size = NULL; - if(!ist->dec) - ist->dec = avcodec_find_decoder(par->codec_id); MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st); MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st); if (canvas_size && From patchwork Wed Aug 3 13:58:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37119 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp460096pzb; Wed, 3 Aug 2022 07:02:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR720YJA2h3T9P3m/Q7LyXGaTvIFvhx2k74oKdd1t6216Z9hFbN7WS5p7QL0TkNVZw45No72 X-Received: by 2002:a05:6402:43c5:b0:43d:f9ca:4061 with SMTP id p5-20020a05640243c500b0043df9ca4061mr7976702edc.352.1659535374786; Wed, 03 Aug 2022 07:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535374; cv=none; d=google.com; s=arc-20160816; b=fIOCSvcAXeWyod1FjmdTQwWRsb+Ww4jqMLkwMVOJ5qLFhggz6jc3KQuWhW2OL1mlqZ 6cfZ2MkrdttCNgcM/BL0ZB0oFWnd0KZrtD6zMxPwp7ihtaKnY7Aal4MAg9FS8gNjueSA PRkeDynD0LSsrAxohdf8fHAmvK8lKt9BoH2yduOAeFmKKvjw8asUWoULsXaTaYx6kDtV tR0yqe1D5JcUmGkn3emYcEz7aLfYTXEEUAaokRZmItBxVeoiRabD1scPEzcop0DbNDKG 6sFv7cmw9xCqlQUuARuymhFMvAwIR3FZL5Vq/YDFWacVOZoFYSewu5J5N/dh7qNSJ49h MZTg== 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=t2wXVx4m7KWHXurvmKVIdJkZgFymaBbfi0vpj8bptVU=; b=GgMydkPko6XtE4dKn5yiwim0hdpQ5691kkMYVSBbqE8xCnDFhnAIVBnQzqT4CEG6Fz 7OgW4grZkvWV1J8FGt02alMP5Y0T0hRlM8dwh9rkCTFUCkPWaK/DReARdt3T08DPQ7Ey otA4S0H8NSosfnxS8njqTwA4y4QOQEutaPd6z4GtKiliIhg8cha/R14/y8mBdtVqhSFx iJQ72XfSlQOUDW234ziy4bKeElo+2xUfbVWb64erYRBNG5I1A+9SRyHjW/Uo+ig3ReUT fvkXFYT1rExNuPKtG2arCskzlum1/CDaR9AaGNu2NvXAUbxYCffM6Os+Uh7SMLTxCecj 67lw== 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 nd12-20020a170907628c00b0073066a8f85esi10457205ejc.686.2022.08.03.07.02.49; Wed, 03 Aug 2022 07:02:54 -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 668A968B9D7; Wed, 3 Aug 2022 16:59:24 +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 A179A68B8F7 for ; Wed, 3 Aug 2022 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1A237240179 for ; Wed, 3 Aug 2022 15:59:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aFW-VUp1OU-t for ; Wed, 3 Aug 2022 15:59:00 +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 00CF824056A for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 038A23A0451; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:26 +0200 Message-Id: <20220803135844.16662-7-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy 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: dAIihIC1Ejx0 There are currently three possible modes for an output stream: 1) The stream is produced by encoding output from some filtergraph. This is true when ost->enc_ctx != NULL, or equivalently when ost->encoding_needed != 0. 2) The stream is produced by copying some input stream's packets. This is true when ost->enc_ctx == NULL && ost->source_index >= 0. 3) The stream is produced by attaching some file directly. This is true when ost->enc_ctx == NULL && ost->source_index < 0. OutputStream.stream_copy is currently used to identify case 2), and sometimes to confusingly (or even incorrectly) identify case 1). Remove it, replacing its usage with checking enc_ctx/source_index values. --- fftools/ffmpeg.c | 23 +++++++++-------------- fftools/ffmpeg.h | 1 - fftools/ffmpeg_opt.c | 33 ++++++++++++--------------------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 62ff1a98df..0a1dc5bb3b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1566,9 +1566,7 @@ static void print_final_stats(int64_t total_size) static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time) { AVBPrint buf, buf_script; - OutputStream *ost; int64_t total_size = of_filesize(output_files[0]); - AVCodecContext *enc; int vid, i; double bitrate; double speed; @@ -1600,11 +1598,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); for (i = 0; i < nb_output_streams; i++) { - float q = -1; - ost = output_streams[i]; - enc = ost->enc_ctx; - if (!ost->stream_copy) - q = ost->quality / (float) FF_QP2LAMBDA; + const OutputStream * const ost = output_streams[i]; + const AVCodecContext * const enc = ost->enc_ctx; + const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1; if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); @@ -3258,7 +3254,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, // copy estimated duration as a hint to the muxer if (ost->st->duration <= 0 && ist && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - } else if (ost->stream_copy) { + } else if (ost->source_index >= 0) { ret = init_output_stream_streamcopy(ost); if (ret < 0) return ret; @@ -3343,7 +3339,7 @@ static int transcode_init(void) * known after the encoder is initialized. */ for (i = 0; i < nb_output_streams; i++) { - if (!output_streams[i]->stream_copy && + if (output_streams[i]->enc_ctx && (output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) continue; @@ -3417,9 +3413,7 @@ static int transcode_init(void) av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); - if (ost->stream_copy) - av_log(NULL, AV_LOG_INFO, " (copy)"); - else { + if (ost->enc_ctx) { const AVCodec *in_codec = input_streams[ost->source_index]->dec; const AVCodec *out_codec = ost->enc; const char *decoder_name = "?"; @@ -3449,7 +3443,8 @@ static int transcode_init(void) av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))", in_codec_name, decoder_name, out_codec_name, encoder_name); - } + } else + av_log(NULL, AV_LOG_INFO, " (copy)"); av_log(NULL, AV_LOG_INFO, "\n"); } @@ -3959,7 +3954,7 @@ static int process_input(int file_index) OutputStream *ost = output_streams[j]; if (ost->source_index == ifile->ist_index + i && - (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) { + (!ost->enc_ctx || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) { OutputFile *of = output_files[ost->file_index]; output_packet(of, ost->pkt, ost, 1); } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6417db03bd..713de42e2b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -540,7 +540,6 @@ typedef struct OutputStream { char *apad; OSTFinished finished; /* no more packets should be written for this stream */ int unavailable; /* true if the steram is unavailable (possibly temporarily) */ - int stream_copy; // init_output_stream() has been called for this stream // The encoder and the bitstream filters have been initialized and the stream diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 12cde4b617..784209e770 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1555,16 +1555,13 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o avcodec_get_name(ost->st->codecpar->codec_id)); return AVERROR_ENCODER_NOT_FOUND; } - } else if (!strcmp(codec_name, "copy")) - ost->stream_copy = 1; - else { + } else if (strcmp(codec_name, "copy")) { ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1); ost->st->codecpar->codec_id = ost->enc->id; } - ost->encoding_needed = !ost->stream_copy; + ost->encoding_needed = !!ost->enc; } else { /* no encoding supported for other media types */ - ost->stream_copy = 1; ost->encoding_needed = 0; } @@ -1898,7 +1895,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *video_enc = ost->enc_ctx; const char *p = NULL; char *frame_size = NULL; @@ -2087,9 +2084,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->last_frame = av_frame_alloc(); if (!ost->last_frame) exit_program(1); - } - - if (ost->stream_copy) + } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO); return ost; @@ -2107,7 +2102,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *audio_enc = ost->enc_ctx; int channels = 0; char *layout = NULL; @@ -2186,9 +2181,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in } } #endif - } - - if (ost->stream_copy) + } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO); return ost; @@ -2199,7 +2192,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int OutputStream *ost; ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index); - if (!ost->stream_copy) { + if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } @@ -2212,7 +2205,7 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, OutputStream *ost; ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index); - if (!ost->stream_copy) { + if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } @@ -2223,7 +2216,6 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index) { OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index); - ost->stream_copy = 1; ost->finished = 1; return ost; } @@ -2236,7 +2228,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index); st = ost->st; - if (!ost->stream_copy) { + if (ost->enc_ctx) { AVCodecContext *subtitle_enc = ost->enc_ctx; char *frame_size = NULL; @@ -2401,7 +2393,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, ofilter->ost = ost; ofilter->format = -1; - if (ost->stream_copy) { + if (!ost->enc_ctx) { av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, " "which is fed from a complex filtergraph. Filtering and streamcopy " "cannot be used together.\n", ost->file_index, ost->index); @@ -2768,7 +2760,6 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); ost = new_attachment_stream(o, oc, -1); - ost->stream_copy = 0; ost->attachment_filename = o->attachments[i]; ost->st->codecpar->extradata = attachment; ost->st->codecpar->extradata_size = len; @@ -3068,7 +3059,7 @@ static int open_output_file(OptionsContext *o, const char *filename) exit_program(1); } } - } else if (ost->stream_copy && ost->source_index >= 0) { + } else if (ost->source_index >= 0) { InputStream *ist = input_streams[ost->source_index]; ist->processing_needed = 1; } @@ -3193,7 +3184,7 @@ static int open_output_file(OptionsContext *o, const char *filename) continue; ist = input_streams[output_streams[i]->source_index]; av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); - if (!output_streams[i]->stream_copy) { + if (output_streams[i]->enc_ctx) { av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0); } } From patchwork Wed Aug 3 13:58:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458751pzb; Wed, 3 Aug 2022 07:01:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tbayKwq5ePVNXehL1Bnqlv/uLPRJMmkvW0MCC1QkamLgSMIODBGJMJCYkd06pKQCEb/iYx X-Received: by 2002:a05:6402:b85:b0:43c:f8e8:96ba with SMTP id cf5-20020a0564020b8500b0043cf8e896bamr26334122edb.183.1659535272384; Wed, 03 Aug 2022 07:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535272; cv=none; d=google.com; s=arc-20160816; b=U0fSFPT3PzsDJg3uXgx1XTc2i4lGl22C+K8kEck1hENhangE/1IPghUlGpqTboCv3h hOV8jzgvn0lEGiOT8eoPtqI31uVVv4zQpS4UZXckn976R9mufEYR4bRsaOoZKQCsQIj9 qqhcClpKXAi588yLlU//vPnVrFTT3T4YeSxDwv6yvAvFdYnr3AwEVp2n66E+oY9iJuQS E0WsfDyquBL3K2DbkJoDF7b+mDE9THsM75bFHtteysMp25XNMOzkpXeQMg5bavZopqPO Vsl3DdsjOcNKXNp5g1t8VJfm1U6pJ8Rhn5JD8rK/tQDdBbkWtnL+59VxfZc7g0B3dIjw J9lw== 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=qx9Poi7KwUJAYJi7+ItP2qeWkNyRY0ngjr9G4JJaZgI=; b=q+l+vEr7G9DlYKoiWnkK+0HDg7JcZrfNo+/1r7a3w0nm/oHh22I5iAMmzLwiCRL0Cj enizX8ubSb4MSj0BEjU9LLhnmFi6zcMH3ENmkokNYerxzkLb1VoDaPINQikp4ZjsdnQW ASIk9NhBc9FQEXrXx5+4MgtZqYkOqqdNvbInEZYefZ51rlOWvJPI6DEiORnDWk2+/2lX Z3nFAfb9bUT9OQi72IWNADt8jkXtOrSI9xD5xp2VeP7+tL3PrDfiTYBDkag1pYJ4B7/K Q0foOAlEfnuszqzVKmXMiyBFweofEouoylOkpddoJ1up+ccXkrExITxFEFgcPSv2P9E0 CpYQ== 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 hs19-20020a1709073e9300b007309621c10fsi6382576ejc.699.2022.08.03.07.01.11; Wed, 03 Aug 2022 07:01:12 -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 8BE9368B0A6; Wed, 3 Aug 2022 16:59:15 +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 A7C9368B89E for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E0E1F240511 for ; Wed, 3 Aug 2022 15:58:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XXVRIBetsHtu for ; Wed, 3 Aug 2022 15:58:58 +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 D014224050B for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 081553A046F; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:27 +0200 Message-Id: <20220803135844.16662-8-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg: remove OutputStream.encoding_needed 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: GZAWMdROiiVL It is unnecessary, as it is always exactly equivalent to !!ost->enc_ctx --- fftools/ffmpeg.c | 10 +++++----- fftools/ffmpeg.h | 1 - fftools/ffmpeg_opt.c | 8 ++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0a1dc5bb3b..6124197580 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1536,7 +1536,7 @@ static void print_final_stats(int64_t total_size) av_log(NULL, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ", i, j, av_get_media_type_string(type)); - if (ost->encoding_needed) { + if (ost->enc_ctx) { av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded", ost->frames_encoded); if (type == AVMEDIA_TYPE_AUDIO) @@ -1788,7 +1788,7 @@ static void flush_encoders(void) AVCodecContext *enc = ost->enc_ctx; OutputFile *of = output_files[ost->file_index]; - if (!ost->encoding_needed) + if (!enc) continue; // Try to enable encoding with no input frames. @@ -2359,7 +2359,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; - if (!check_output_constraints(ist, ost) || !ost->encoding_needed + if (!check_output_constraints(ist, ost) || !ost->enc_ctx || ost->enc->type != AVMEDIA_TYPE_SUBTITLE) continue; @@ -2568,7 +2568,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; - if (!check_output_constraints(ist, ost) || ost->encoding_needed || + if (!check_output_constraints(ist, ost) || ost->enc_ctx || (!pkt && no_eof)) continue; @@ -3137,7 +3137,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, OutputFile *of = output_files[ost->file_index]; int ret = 0; - if (ost->encoding_needed) { + if (ost->enc_ctx) { const AVCodec *codec = ost->enc; AVCodecContext *dec = NULL; InputStream *ist; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 713de42e2b..69e4758a2d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -464,7 +464,6 @@ typedef struct OutputStream { int index; /* stream index in the output file */ int source_index; /* InputStream index */ AVStream *st; /* stream in the output file */ - int encoding_needed; /* true if encoding needed for this stream */ /* number of frames emitted by the video-encoding sync code */ int64_t vsync_frame_number; /* input pts and corresponding output pts diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 784209e770..ffa320da87 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1559,10 +1559,6 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1); ost->st->codecpar->codec_id = ost->enc->id; } - ost->encoding_needed = !!ost->enc; - } else { - /* no encoding supported for other media types */ - ost->encoding_needed = 0; } return 0; @@ -2433,7 +2429,7 @@ static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_si int limit_frames = 0, limit_frames_av_enc = 0; #define IS_AV_ENC(ost, type) \ - (ost->encoding_needed && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) + (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) #define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT) for (int i = 0; i < oc->nb_streams; i++) { @@ -3043,7 +3039,7 @@ static int open_output_file(OptionsContext *o, const char *filename) for (i = of->ost_index; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; - if (ost->encoding_needed && ost->source_index >= 0) { + if (ost->enc_ctx && ost->source_index >= 0) { InputStream *ist = input_streams[ost->source_index]; ist->decoding_needed |= DECODING_FOR_OST; ist->processing_needed = 1; From patchwork Wed Aug 3 13:58:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37105 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458127pzb; Wed, 3 Aug 2022 07:00:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6YLOPnoKGmeTKwaT8sVA+p6ftqOrDYXEn82XNd1ZtL3FX8ki+67lf4eDQou/KYStYehcV3 X-Received: by 2002:a17:907:1dd2:b0:730:b687:adf1 with SMTP id og18-20020a1709071dd200b00730b687adf1mr2065619ejc.183.1659535220633; Wed, 03 Aug 2022 07:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535220; cv=none; d=google.com; s=arc-20160816; b=EfwpQ8Rcd1dhjvGTZFz2BjpIMWDJgOh/CAkv+o2yEx4sxFVxLXkSQE+iYyHuRalWyB BOfGf5D1cWexZLXwITgu5npA6mgprYEUPfzUxnbJ13fI/wxnV8vUrhRQhCWThTH+bAO+ AoV1gzGG1WlQfFoNndpJLJf7wxUitmZw0NiJy8YQk/tNYUDu2tV5INpJoZk+YDyP5sOT nhSh2mdf+12d1hTUR+eu275TbtwfeuELucFWHCXlBLYAjQXgmfPzYaEFegvO+40xYLIG Q51L/901SMq3g0gS1bIztDQy6GNW2JzyUru+NmbRhE8gUQwMdOW7yKVQPsXask4TBKGs uEEA== 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=1EJRG7FLN4PtylWQ17ICAck7UrRBAIYSjoGa+Fn0XS4=; b=VHXH1fKYbSsfUkMsUOrE+Vk1kuQfPHL6U5gI9WAK4J0EQVIeK9mg+IZC5I3M5wT88m RWC3TpMkV/M8VNKZzwKLITiEsXN7mDMtS5KFFO4V6fvz4I6Lmnd2g/g3KS0JFYRxn9kW aOvCdEzCmMh6o9bqiPgXwSxCJgKTnoNunjwqrLxR/w4He2Z2zNoi81HlwfqpaYMDcR6K arzCOauI94HPGwjb+7qIny3ilKt4QUw0FZB50XPLxsDqNcPtZ/S4WE957UThQxabQCml QB55s3vvIRAisoBJPIinXlCSgtbnZ/CFrelv5cmLwrNvGPUaCGaM8pkidaFvqF9+VEyc NXig== 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 n10-20020a05640205ca00b0043cc3506c6esi14481189edx.217.2022.08.03.07.00.20; Wed, 03 Aug 2022 07:00:20 -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 7F05168B871; Wed, 3 Aug 2022 16:59:10 +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 5164568B884 for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C5745240506 for ; Wed, 3 Aug 2022 15:58:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id llAwF3xPKW7O for ; Wed, 3 Aug 2022 15:58:57 +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 C9062240507 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 0D05A3A0470; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:28 +0200 Message-Id: <20220803135844.16662-9-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: remove OutputStream.sync_ist 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: hNkCgPZimz4n It is not actually used for anything. --- fftools/ffmpeg.c | 4 ---- fftools/ffmpeg.h | 1 - fftools/ffmpeg_opt.c | 18 ++++++------------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6124197580..47f9a6137f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3409,10 +3409,6 @@ static int transcode_init(void) input_streams[ost->source_index]->st->index, ost->file_index, ost->index); - if (ost->sync_ist != input_streams[ost->source_index]) - av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", - ost->sync_ist->file_index, - ost->sync_ist->st->index); if (ost->enc_ctx) { const AVCodec *in_codec = input_streams[ost->source_index]->dec; const AVCodec *out_codec = ost->enc; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 69e4758a2d..b7d62957f8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -468,7 +468,6 @@ typedef struct OutputStream { int64_t vsync_frame_number; /* input pts and corresponding output pts for A/V sync */ - struct InputStream *sync_ist; /* input stream to sync against */ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number /* pts of the first frame encoded for this stream, used for limiting * recording time */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ffa320da87..0cd807c9c8 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1757,7 +1757,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->source_index = source_index; if (source_index >= 0) { - ost->sync_ist = input_streams[source_index]; input_streams[source_index]->discard = 0; input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard; } @@ -2650,7 +2649,6 @@ static void map_manual(OutputFile *of, AVFormatContext *oc, OptionsContext *o, const StreamMap *map) { InputStream *ist; - OutputStream *ost; if (map->disabled) return; @@ -2695,16 +2693,15 @@ loop_end: if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA) return; - ost = NULL; switch (ist->st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break; - case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break; - case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break; - case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break; - case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break; + case AVMEDIA_TYPE_VIDEO: new_video_stream (o, oc, src_idx); break; + case AVMEDIA_TYPE_AUDIO: new_audio_stream (o, oc, src_idx); break; + case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (o, oc, src_idx); break; + case AVMEDIA_TYPE_DATA: new_data_stream (o, oc, src_idx); break; + case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(o, oc, src_idx); break; case AVMEDIA_TYPE_UNKNOWN: if (copy_unknown_streams) { - ost = new_unknown_stream (o, oc, src_idx); + new_unknown_stream (o, oc, src_idx); break; } default: @@ -2719,9 +2716,6 @@ loop_end: exit_program(1); } } - if (ost) - ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index - + map->sync_stream_index]; } } From patchwork Wed Aug 3 13:58:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37120 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp460230pzb; Wed, 3 Aug 2022 07:03:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4RIEc/HAP7hvmYEBpt+TxDaRRCn7WFBZ67aIx52F0dLeC9YzJwOU7c9SRhuyXLucsUDMMW X-Received: by 2002:a17:906:7622:b0:730:9a59:3892 with SMTP id c2-20020a170906762200b007309a593892mr8017118ejn.697.1659535385957; Wed, 03 Aug 2022 07:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535385; cv=none; d=google.com; s=arc-20160816; b=UNdO7exza02KER81ctH7/7Tdf0cqXU1RizmHyYimmn7qmgDS5vv8EB7lObp3CkJfKw pHZOEFkUB9saJ9jsHVDkMmWplqFByx8u5wFaOIIckiPaw7m/7icbNJC2sOJbAzVr0PFw Si7pWg6HhMqnf8tqODFlVYicfyK23zJA4cNz/Zr03zGzRVU/s0Ds6k5THx+qkqIcVPne Gs6aae7eWTcmKJyjowga5vYh2vGhSifXEsnTMnwWYg0csutlUuU3zVASaulLY0puz61J gKO9Bx+MSysCpfdPavX3gEGm0Id5iSGWgE6ClneCPzwyCr7DFVv7seZ9zchLl0YwilMM w06A== 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=Qr5VhUacNVP1ZL88aFHgV/OGTrJozhTD9B5irLsDbXA=; b=GKql6u3z2YUe56vx69oiEltzwHeUxi6GzStUIsnSxVxbLbzv5yKGGhorlChXuwzHmq rngTaEKWkbPIOmjnjiWUv7PVY0zarq1x8907zR7ymMS6D5kn3SCK2vjV6shfMb624MWx wrTsJ/ibq6do8+2eW9WqAyHHc5DGabZewRczET1cn8ACztb/pK3IOmOX7Uktu9EXxjLP Q9EUopBnfvKh43OTA2C1iE2VrJuILs2QWfsaAkew0mw4OJA+/m2RtgVEFYTDfoI38wdF PspcwZ5H6q9NCl3vBFi/jL+zH/uLjI2GmPq+9lX+iJJhHuQ0cMzhENc4d4mte+xZrPQK eTYg== 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 o5-20020a170906974500b00707cb6a6c1fsi3126447ejy.162.2022.08.03.07.03.00; Wed, 03 Aug 2022 07:03:05 -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 65BEB68B9DE; Wed, 3 Aug 2022 16:59:25 +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 2679868B8F7 for ; Wed, 3 Aug 2022 16:59:04 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C03F224017C for ; Wed, 3 Aug 2022 15:59:03 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vt19oo72rLVO for ; Wed, 3 Aug 2022 15:59:03 +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 0A2CB2405F0 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 119E83A048F; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:29 +0200 Message-Id: <20220803135844.16662-10-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: deprecate specifying a sync stream with -map 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: VX66YXd7ZccY It has not had any effect whatsoever for over 10 years. --- doc/ffmpeg.texi | 6 ++---- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_opt.c | 41 +++++++---------------------------------- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 2fb0bc8ffa..20747ebb8e 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1411,14 +1411,12 @@ Set the size of the canvas used to render subtitles. @section Advanced options @table @option -@item -map [-]@var{input_file_id}[:@var{stream_specifier}][?][,@var{sync_file_id}[:@var{stream_specifier}]] | @var{[linklabel]} (@emph{output}) +@item -map [-]@var{input_file_id}[:@var{stream_specifier}][?] | @var{[linklabel]} (@emph{output}) Designate one or more input streams as a source for the output file. Each input stream is identified by the input file index @var{input_file_id} and the input stream index @var{input_stream_id} within the input -file. Both indices start at 0. If specified, -@var{sync_file_id}:@var{stream_specifier} sets which input stream -is used as a presentation sync reference. +file. Both indices start at 0. The first @code{-map} option on the command line specifies the source for output stream 0, the second @code{-map} option specifies diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b7d62957f8..6b09846825 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -52,6 +52,7 @@ // deprecated features #define FFMPEG_OPT_PSNR 1 #define FFMPEG_OPT_MAP_CHANNEL 1 +#define FFMPEG_OPT_MAP_SYNC 1 enum VideoSyncMethod { VSYNC_AUTO = -1, @@ -81,8 +82,6 @@ typedef struct StreamMap { int disabled; /* 1 is this mapping is disabled by a negative map */ int file_index; int stream_index; - int sync_file_index; - int sync_stream_index; char *linklabel; /* name of an output link, for mapping lavfi outputs */ } StreamMap; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 0cd807c9c8..bd3a34960c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -415,9 +415,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg) OptionsContext *o = optctx; StreamMap *m = NULL; int i, negative = 0, file_idx, disabled = 0; - int sync_file_idx = -1, sync_stream_idx = 0; - char *p, *sync; - char *map; +#if FFMPEG_OPT_MAP_SYNC + char *sync; +#endif + char *map, *p; char *allow_unused; if (*arg == '-') { @@ -428,33 +429,13 @@ static int opt_map(void *optctx, const char *opt, const char *arg) if (!map) return AVERROR(ENOMEM); +#if FFMPEG_OPT_MAP_SYNC /* parse sync stream first, just pick first matching stream */ if (sync = strchr(map, ',')) { *sync = 0; - sync_file_idx = strtol(sync + 1, &sync, 0); - if (sync_file_idx >= nb_input_files || sync_file_idx < 0) { - av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx); - exit_program(1); - } - if (*sync) - sync++; - for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++) - if (check_stream_specifier(input_files[sync_file_idx]->ctx, - input_files[sync_file_idx]->ctx->streams[i], sync) == 1) { - sync_stream_idx = i; - break; - } - if (i == input_files[sync_file_idx]->nb_streams) { - av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not " - "match any streams.\n", arg); - exit_program(1); - } - if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) { - av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input " - "stream.\n", arg); - exit_program(1); - } + av_log(NULL, AV_LOG_WARNING, "Specifying a sync stream is deprecated and has no effect\n"); } +#endif if (map[0] == '[') { @@ -499,14 +480,6 @@ static int opt_map(void *optctx, const char *opt, const char *arg) m->file_index = file_idx; m->stream_index = i; - - if (sync_file_idx >= 0) { - m->sync_file_index = sync_file_idx; - m->sync_stream_index = sync_stream_idx; - } else { - m->sync_file_index = file_idx; - m->sync_stream_index = i; - } } } From patchwork Wed Aug 3 13:58:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37107 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458375pzb; Wed, 3 Aug 2022 07:00:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4AzypibrrQTuLjYJlqWdQZy2owhD1ZVFRLh/ztQorMMIse8fAMevfewYtUBOVNg5aHbTC X-Received: by 2002:a05:6402:4024:b0:43d:2067:f068 with SMTP id d36-20020a056402402400b0043d2067f068mr25165075eda.258.1659535241872; Wed, 03 Aug 2022 07:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535241; cv=none; d=google.com; s=arc-20160816; b=Rd10lnpCLYBktGaSscaF1wU2KArgBEEw1iCvFSONNZZtwiXIg3pJREJWNMz7836Oa5 Uhby6G8h/DFR28jNlU+VOeEYoZqjgAG7ovRR2vXHb+m3edIUqi5Bl1hm/taOM0rdz0Ry ErZvYBmYpHDm/+pfZzusP0L0rd/v1TrewFW+xV938IoK1wdNom3iqgqnvvSWv5rqWMJS NMVSh4mFc2r5C4HQ3HZxTnDRkZTJdJIkouF5DI4CkwH9fbuKm/L9iREA9DDnEYCGuJQk isW7Sd4Z92ExKMv1Jw8H31BaZwv7ZUkCfbeMjU0bjc6CtCII1snMt8t3kzYAdN2UUFH6 tRTg== 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=s3MRG9iTls8XKZNvASMJG5ZCrgch5dF24GnkRNLP8vI=; b=vTK9+9FtP2ofirZ2wXlnNM10EjZ3YRD5DbVfwwXHQ4Mj4+o7B0iMd6YYQwmBJQx2mQ NmUjIn8dtXu+ccAA3LT7tE6K9ZFPCL5D/7FvnIgIvDHpqsa3s5D1CmkTpErApyz70qTd e+0pTVdNhnUk+UTwEkEg0UubUcAyqHKK7G+spMsvTNiC5Kw+H1w45ZsXjjJll6p1zHDm Vp+5T2nRL49MgZVBXP1IUwyijaua549a96deblGw90ZLkZYVGPfyRRO+z8dbUuamkFEK Mr5zxkwwYYoZKaTOT3s4BgPVVmDCCCnaZovaRErL1wYWwz2EpRxqFwwLe3B3kjVr7s4A IpbQ== 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 hb30-20020a170907161e00b0072f4876f0basi17876293ejc.128.2022.08.03.07.00.41; Wed, 03 Aug 2022 07:00:41 -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 8630868B8C0; Wed, 3 Aug 2022 16:59:12 +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 9B55768B871 for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7A0D0240592 for ; Wed, 3 Aug 2022 15:59:05 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id kBoLTJ-ERdft for ; Wed, 3 Aug 2022 15:59:04 +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 175B024062A for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 167693A0490; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:30 +0200 Message-Id: <20220803135844.16662-11-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/25] doc/ffmpeg: update -map documentation 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: t6/FLz6yXgMn Make it match reality (current text was not updated for stream specifiers), extend and clarify the text. --- doc/ffmpeg.texi | 58 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 20747ebb8e..42440d93b4 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1413,14 +1413,16 @@ Set the size of the canvas used to render subtitles. @table @option @item -map [-]@var{input_file_id}[:@var{stream_specifier}][?] | @var{[linklabel]} (@emph{output}) -Designate one or more input streams as a source for the output file. Each input -stream is identified by the input file index @var{input_file_id} and -the input stream index @var{input_stream_id} within the input -file. Both indices start at 0. +Create one or more streams in the output file. This option has two forms for +specifying the data source(s): the first selects one or more streams from some +input file (specified with @code{-i}), the second takes an output from some +complex filtergraph (specified with @code{-filter_complex} or +@code{-filter_complex_script}). -The first @code{-map} option on the command line specifies the -source for output stream 0, the second @code{-map} option specifies -the source for output stream 1, etc. +In the first form, an output stream is created for every stream from the input +file with the index @var{input_file_id}. If @var{stream_specifier} is given, +only those streams that match the specifier are used (see the +@ref{Stream specifiers} section for the @var{stream_specifier} syntax). A @code{-} character before the stream identifier creates a "negative" mapping. It disables matching streams from already created mappings. @@ -1434,39 +1436,56 @@ An alternative @var{[linklabel]} form will map outputs from complex filter graphs (see the @option{-filter_complex} option) to the output file. @var{linklabel} must correspond to a defined output link label in the graph. -For example, to map ALL streams from the first input file to output +This option may be specified multiple times, each adding more streams to the +output file. Any given input stream may also be mapped any number of times as a +source for different output streams, e.g. in order to use different encoding +options and/or filters. The streams are created in the output in the same order +in which the @code{-map} options are given on the commandline. + +Using this option disables the default mappings for this output file. + +Examples: + +@table @emph + +@item map everything +To map ALL streams from the first input file to output @example ffmpeg -i INPUT -map 0 output @end example -For example, if you have two audio streams in the first input file, -these streams are identified by "0:0" and "0:1". You can use -@code{-map} to select which streams to place in an output file. For -example: +@item select specific stream +If you have two audio streams in the first input file, these streams are +identified by @var{0:0} and @var{0:1}. You can use @code{-map} to select which +streams to place in an output file. For example: @example ffmpeg -i INPUT -map 0:1 out.wav @end example -will map the input stream in @file{INPUT} identified by "0:1" to -the (single) output stream in @file{out.wav}. +will map the second input stream in @file{INPUT} to the (single) output stream +in @file{out.wav}. -For example, to select the stream with index 2 from input file -@file{a.mov} (specified by the identifier "0:2"), and stream with -index 6 from input @file{b.mov} (specified by the identifier "1:6"), -and copy them to the output file @file{out.mov}: +@item create multiple streams +To select the stream with index 2 from input file @file{a.mov} (specified by the +identifier @var{0:2}), and stream with index 6 from input @file{b.mov} +(specified by the identifier @var{1:6}), and copy them to the output file +@file{out.mov}: @example ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov @end example +@item create multiple streams 2 To select all video and the third audio stream from an input file: @example ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT @end example +@item negative map To map all the streams except the second audio, use negative mappings @example ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT @end example +@item optional map To map the video and audio streams from the first input, and using the trailing @code{?}, ignore the audio mapping if no audio streams exist in the first input: @@ -1474,12 +1493,13 @@ the first input: ffmpeg -i INPUT -map 0:v -map 0:a? OUTPUT @end example +@item map by language To pick the English audio stream: @example ffmpeg -i INPUT -map 0:m:language:eng OUTPUT @end example -Note that using this option disables the default mappings for this output file. +@end table @item -ignore_unknown Ignore input streams with unknown type instead of failing if copying From patchwork Wed Aug 3 13:58:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458241pzb; Wed, 3 Aug 2022 07:00:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vMinRF/CbwKP7C4G9CDGk3pOF5mQaxN4QTbPecYaaa11xv3DzA6XWcBHSJO+U+eOVF1L63 X-Received: by 2002:a05:6402:5413:b0:43c:67c0:d2db with SMTP id ev19-20020a056402541300b0043c67c0d2dbmr26492979edb.267.1659535230986; Wed, 03 Aug 2022 07:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535230; cv=none; d=google.com; s=arc-20160816; b=OAZTckdlYE2XZlt4TG/3oWO58tzOlPCPavMuSjuGV6OxoU+nWynCL761pjR7nWhbaF hSVpzXZ9BmEzRKk0by4x7NH3x7yeoQ0fpBrinpch4sHNR7nxXKwNddmjpr4vnNC13OCH opHWkkJwocsUp4q6oiwgvmzBub0bkxe2a6zxruQmeAlj69M7kganJyx9eoekJ+6uuHuG cOGv62iTcTzUYPxjEKCGS1H8V73c0FYkubv8swQWNZGdpg6qz9ID+5JXn6aDtTjXtWm5 9YmbPyYQhOzy0qAstRKOIBry3+Zg2CSXNhKe/K2n8N8PHlLg00HHEBSmNcq1ZGPSjkQp iCDg== 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=eozwVG6tnwJhHUPdSscOnUaCp27vU1eevGVOzYuHCSk=; b=k6FtVz0n+Lupmn1dDhtP1JIkTnKIWlK7uJOsB+LtiPwI9mrpUorSGL3le4WoqzyGUb mRv2bCp0HY3KOkW9v6jk7RyPOmPxu9FHacEdeWjF2rM9ffsHIrOhEvVITswXX5k9AX0L JKEjyA5ECuMQxA0YSFqUKTSBcp5svtR/o5V05u3uBTRPNHwSEDm8+yzBY/yr18AvOpIU XJXWF20mfqQeISxjdr0YLhQqFWU/smOM3ptjjyd22Tk6HbNWxs3iPbwTnXtDLQ5XEfNz cR4qGCEd9FZV4Ssl/qyT3WURkK0oESLGGtLK0nZSDbBVjRmkNhkrXLqdmsCx9sZxDhp6 r5fg== 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 wg10-20020a17090705ca00b0072f2e1425a3si7694027ejb.774.2022.08.03.07.00.30; Wed, 03 Aug 2022 07:00:30 -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 85CBC68B8B3; Wed, 3 Aug 2022 16:59:11 +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 58CC668B88B for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 44607240507 for ; Wed, 3 Aug 2022 15:58:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EedOK3HT9ESR for ; Wed, 3 Aug 2022 15:58:57 +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 DC5F6240511 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1ADBD3A04A6; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:31 +0200 Message-Id: <20220803135844.16662-12-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg: drop a superfluous stack variable 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: aoqwBTCM0KOs --- fftools/ffmpeg.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 47f9a6137f..f12364fe0a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3904,16 +3904,14 @@ static int process_input(int file_index) return ret; } if (ret < 0 && ifile->loop) { - AVCodecContext *avctx; for (i = 0; i < ifile->nb_streams; i++) { ist = input_streams[ifile->ist_index + i]; - avctx = ist->dec_ctx; if (ist->processing_needed) { ret = process_input_packet(ist, NULL, 1); if (ret>0) return 0; if (ist->decoding_needed) - avcodec_flush_buffers(avctx); + avcodec_flush_buffers(ist->dec_ctx); } } free_input_thread(file_index); From patchwork Wed Aug 3 13:58:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37112 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459055pzb; Wed, 3 Aug 2022 07:01:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Cn0gPRgdW5uvBmiw3itG1qCKf43dnUtUb7pLxQ/xjePQe0rE81wTT+ZJpJfRQ3IqT7QRZ X-Received: by 2002:a17:907:762f:b0:730:95d9:9955 with SMTP id jy15-20020a170907762f00b0073095d99955mr8826355ejc.505.1659535295890; Wed, 03 Aug 2022 07:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535295; cv=none; d=google.com; s=arc-20160816; b=HcfWD3Sods2NnkJGRVBbftdefffbBZsASoZxhAERQB2nR+2ZVLjqetOfW3fm51E9E3 YJ/p7b9e3Lpx7OsWh91AoYoeoQDXL7xTLS6goQSyfAatWmqac4RfFjdUMLzRbnayx3+O ul3pRHwXNJ5JV/2roJSPs8LgV9KubfCexcEXWzfj3sugkrcpkaTwNMXDa2f3UTtKnKZm lwFfMsdE44hP9IrUDhnabPUuxahuzr96rQmNaQGkxoI2JtB3pjdIPYyrWvpZA2Z3vs1Y qgxsxBaB3i11wS/WtY84jtOvbzzX7Q6SExMBc+uHqfKd+f8ZUfREPNN3JEa+cqXBo8WF AY5g== 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=rZRdWy60VUoLIBfDfmlMzqeQRQJ4SmkMF9LIkAWfinI=; b=qZHvzYy7uPe6MfhtoXMQufbn1AmW+XRWOPbrvKqp3RH7FFYJReMsUMPyYfvI1Pssn/ zt2+EYe+30dGOEJbHAB2JV+fljp17m8vz2RoxPybBQ5A9liCXdXiFUsJD+suIIdTB6/n 3p9zIThYaJPL8OCXypOudshHJLaUTAN29ubbPf1Zm0DWGlrEak2fiqd/ZrMQFUJVMCrD hbXWopcXRJEmgwbOJ1+WzlNSOwlfgMao4GJftaa3Ut070DAbvFGIQ+pckJA3Bq9EFrsH N6v0HKpCdVdtYBi72MGfJ8wBB8YXdhRhin+diUbGtEzVj/d3M/v2Sz7nbY61U/FH9FpO RD+w== 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 j36-20020a05640223a400b0043a6defcbafsi14440681eda.219.2022.08.03.07.01.33; Wed, 03 Aug 2022 07:01:35 -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 7EDF568B971; Wed, 3 Aug 2022 16:59:17 +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 AEBBF68B8A0 for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 814F324050B for ; Wed, 3 Aug 2022 15:58:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FAj9OvY2YM6g for ; Wed, 3 Aug 2022 15:58:58 +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 DDDE7240512 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1F76A3A04AB; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:32 +0200 Message-Id: <20220803135844.16662-13-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg: store the input file index in InputFile 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: FrflcuAnfgwG Use it to simplify some code and fix two off-by-one errors. Similar to what was previously done for OutputFile. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6b09846825..23b249780b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -408,6 +408,8 @@ typedef struct InputStream { } InputStream; typedef struct InputFile { + int index; + AVFormatContext *ctx; int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index bd3a34960c..25aa9aaff5 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1383,6 +1383,7 @@ static int open_input_file(OptionsContext *o, const char *filename) f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); f->ctx = ic; + f->index = nb_input_files - 1; f->ist_index = nb_input_streams - ic->nb_streams; f->start_time = o->start_time; f->recording_time = o->recording_time; @@ -1398,11 +1399,11 @@ static int open_input_file(OptionsContext *o, const char *filename) f->readrate = o->readrate ? o->readrate : 0.0; if (f->readrate < 0.0f) { - av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", nb_input_files, f->readrate); + av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate); exit_program(1); } if (f->readrate && f->rate_emu) { - av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", nb_input_files, f->readrate); + av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate); f->rate_emu = 0; } @@ -1435,7 +1436,7 @@ static int open_input_file(OptionsContext *o, const char *filename) if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) { av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for " "input file #%d (%s) is not a decoding option.\n", e->key, - option->help ? option->help : "", nb_input_files - 1, + option->help ? option->help : "", f->index, filename); exit_program(1); } @@ -1445,7 +1446,7 @@ static int open_input_file(OptionsContext *o, const char *filename) "likely reason is either wrong type (e.g. a video option with " "no video streams) or that it is a private option of some decoder " "which was not actually used for any stream.\n", e->key, - option->help ? option->help : "", nb_input_files - 1, filename); + option->help ? option->help : "", f->index, filename); } av_dict_free(&unused_opts); From patchwork Wed Aug 3 13:58:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37108 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458494pzb; Wed, 3 Aug 2022 07:00:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6iV/s2IClwQMkdOzVK1/t7OQfZSDG0wHPnX0JHVarQ8HGMs+0Whxfgnj/HAdudLtHYA1gw X-Received: by 2002:a05:6402:5211:b0:43e:1ac4:4b39 with SMTP id s17-20020a056402521100b0043e1ac44b39mr5628071edd.345.1659535251888; Wed, 03 Aug 2022 07:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535251; cv=none; d=google.com; s=arc-20160816; b=EqT1foZfvcmkl3NxT9mdGueMmfGW5cHLi2SQX8E25TghGFJWnJI9Bbmh1uR4pbVbV2 IrQ0KvnzOdzBrF4nn5OBJ/a0MVUBm8pZpxSta8jcOWSX7NPpmkfa6Oym8vykyKqL4/tr zlpncT+e8wj9SeXg6cBGiLfb5GoJHg34QFV3a4fI9HfBAGYRkcsBmT+VCpACw/61+SnD V7BVHvyC6upYVVKPPFrJRMQXfTQ5qAPP71R8fEgmB3uwdZfjgWEiPpQxUFsBnp4pOHWS leiKW5/ndPnY5tCNgkVzA5HoaxiWKVmLqB/SKHKK+ouwp2mzwDvOcut1siFwiQElxovS vmFg== 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=dizNKIPw7zvLxxLTOsVR1rB3leDirQYMwQngwAsSme4=; b=REtBu7qT5nWh2zNOa/FQBwAm/l8Jyh/FU+3g5r54zIpj31wGV6G66ohxDaDDV7lVe2 APW4vDVsMNsZT+hzZg3rwUWp7yld9cVDom6VdH6fRnmpop+b3dPGpMqIugR2mUGQnVSU gYBUd2dV6oCkr3bVD6KFAVrNMUiIN3ubPW5iO/346tA3GzA2ErkfbDgSyhOytPBhisL3 8nTvaiIKaNUd5rB50RPw0dsgyuIUUbB+2SmxVCgq0iBceowEG7bPqDPL7d6uQd7f/Fig PCXpNXWyCoK72+rdc4nfXgjeMfU0k1bN2/D4+S/QE8Pnr2K4db+0wscRYsRc4qilTFd2 3OcA== 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 gb4-20020a170907960400b006f3916bcfc8si4527982ejc.142.2022.08.03.07.00.51; Wed, 03 Aug 2022 07:00:51 -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 8DEF768B93E; Wed, 3 Aug 2022 16:59:13 +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 9B6AF68B878 for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B67E924056A for ; Wed, 3 Aug 2022 15:59:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ZPYZopWkJ7du for ; Wed, 3 Aug 2022 15:59:04 +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 1B974240685 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 23C133A04C6; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:33 +0200 Message-Id: <20220803135844.16662-14-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: always read input in a thread 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: VzyJmmDJGFqu This will be required by the following architecture changes. --- fftools/ffmpeg.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index f12364fe0a..7ba1f2a8cf 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3713,10 +3713,8 @@ static int init_input_thread(int i) int ret; InputFile *f = input_files[i]; - if (f->thread_queue_size < 0) - f->thread_queue_size = (nb_input_files > 1 ? 8 : 0); - if (!f->thread_queue_size) - return 0; + if (f->thread_queue_size <= 0) + f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); if (f->ctx->pb ? !f->ctx->pb->seekable : strcmp(f->ctx->iformat->name, "lavfi")) @@ -3747,13 +3745,6 @@ static int init_input_threads(void) return 0; } -static int get_input_packet_mt(InputFile *f, AVPacket **pkt) -{ - return av_thread_message_queue_recv(f->in_thread_queue, pkt, - f->non_blocking ? - AV_THREAD_MESSAGE_NONBLOCK : 0); -} - static int get_input_packet(InputFile *f, AVPacket **pkt) { if (f->readrate || f->rate_emu) { @@ -3775,10 +3766,9 @@ static int get_input_packet(InputFile *f, AVPacket **pkt) } } - if (f->thread_queue_size) - return get_input_packet_mt(f, pkt); - *pkt = f->pkt; - return av_read_frame(f->ctx, *pkt); + return av_thread_message_queue_recv(f->in_thread_queue, pkt, + f->non_blocking ? + AV_THREAD_MESSAGE_NONBLOCK : 0); } static int got_eagain(void) @@ -4162,10 +4152,7 @@ static int process_input(int file_index) process_input_packet(ist, pkt, 0); discard_packet: - if (ifile->thread_queue_size) - av_packet_free(&pkt); - else - av_packet_unref(pkt); + av_packet_free(&pkt); return 0; } From patchwork Wed Aug 3 13:58:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37121 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp460367pzb; Wed, 3 Aug 2022 07:03:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Vi/wRDUgWTvkd5ZQoXxnLKDMAdQ84QDdgTWo2ud0AK4xcQeGpHhHwBxSPrdg+tFEx6hK1 X-Received: by 2002:a05:6402:138f:b0:43d:8ed5:c841 with SMTP id b15-20020a056402138f00b0043d8ed5c841mr16682742edv.27.1659535396959; Wed, 03 Aug 2022 07:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535396; cv=none; d=google.com; s=arc-20160816; b=bNqbKPh7l6s7tvZd2JJeuFLqMLsL4LiUftdnxI1WPqCWN/E5PMWXM2/g936JxY+idr yMJwD4lJ4hJxjCh/xsBQ+z6gzvZ6AoGjB6aHxx8ippU/nfUabre4jzYxhtrRQBxHifjl sHFg7QD1bBD4N0MCjfO0HCGEE+UOxYEcM7ZuFM8A6JIPIZdI10dqCdKMRTyimkOH/KVE YRnj6BfAp/GoSDDnoe+CdRUAgTuG48bWwFJALPqEdGO+HimBiGsOIlvshCmPyZ83yna+ Cgfd1KsilxUv3tVAPq7MROZjeUT5EuEpfAceJ8DiU198iJHCPRZHSwvNYlPnO996U4Fk CWzw== 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=lOjHC0sPasuBDPCWrnaoCpahPr2pUEjGLXkH1fdHJ/c=; b=E9FYiID7/uIO7EPx5AXP4OpNKqFE+RLh0X9NfslFKHZ2T7gLgAr+4LvG+qRs+bzc0A OtQgx9BVci/N1iIlGqxdRBAGSCcZjbuaekaXXivMtYKnDdQwRJV3n+KvFmjzXrWzaQeO 4gyKb7Wnui8MZGHM/juNdytwDDOJOOh0SprXH9FmXC7Q+zfC1w+XSQX0Taz9nc9E95ff KVgBJRA0iD8iOY6iafTVTz77hXX1Rn0pJMgoZ6M+nhW/OOSOL4zRksgl3H0cUttemL4/ 5Hxj2qQrpzxxGskqJrcgpx8eeh248vFhgIjFMNXWbMGO4ToP4mkmP1fCbCcA+NmEPJU/ KOQA== 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 u21-20020a50c055000000b0043be90a5cd7si15321307edd.429.2022.08.03.07.03.11; Wed, 03 Aug 2022 07:03:16 -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 4154568B9E8; Wed, 3 Aug 2022 16:59:26 +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 A0B4768B895 for ; Wed, 3 Aug 2022 16:59:04 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3651024017E for ; Wed, 3 Aug 2022 15:59:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id of7arS5UpnZS for ; Wed, 3 Aug 2022 15:59:03 +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 1476B2405F5 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 281CC3A04DA; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:34 +0200 Message-Id: <20220803135844.16662-15-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: drop a write-only variable 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: LYgZkmFfQnXP --- fftools/ffmpeg.c | 1 - fftools/ffmpeg.h | 1 - 2 files changed, 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 7ba1f2a8cf..a377e776c7 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3696,7 +3696,6 @@ static void free_input_thread(int i) av_packet_free(&pkt); pthread_join(f->thread, NULL); - f->joined = 1; av_thread_message_queue_free(&f->in_thread_queue); } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 23b249780b..fc082bfbea 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -437,7 +437,6 @@ typedef struct InputFile { AVThreadMessageQueue *in_thread_queue; pthread_t thread; /* thread reading from this file */ int non_blocking; /* reading packets from the thread should not block */ - int joined; /* the thread has been joined */ int thread_queue_size; /* maximum number of queued packets */ } InputFile; From patchwork Wed Aug 3 13:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37118 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459980pzb; Wed, 3 Aug 2022 07:02:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1svMXoggpfSWNiBuIv501PGuW8mUpUJJyxd+H3zuLhxTkYwMA1AapytHTDqJlOaPeC0+c1B X-Received: by 2002:a17:906:5d16:b0:72f:9f40:d1eb with SMTP id g22-20020a1709065d1600b0072f9f40d1ebmr20082032ejt.403.1659535365581; Wed, 03 Aug 2022 07:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535365; cv=none; d=google.com; s=arc-20160816; b=AEgPjfGa/ddC6iovKFABSaBsfVyfLfdkcSymXVhVV0Q3LQKhvDqanDdzH5NbAif5mr JCVDmnbYz+fDfYVbxjFk0SYm4BWGSJELD9xdx0Mz+v1cBZ0erLviaH2dIed//qnhtzIP 5BxByxQU1mbqaY0+bNrpzBUengLUpyDfOog7j64H8nOhrfgWVsvDIDPe5/hhsQv5seHk Yy549ZDYPV8ru8dbiF+rbybHIwfW8q858MuodgFzjt3rh53jipIfijX7bZmLww0f1WCx tRz5cq9O0O5/Fb+Z97VI5CPx9XyKRnfDesPqfU3VVNIrZigF+YBiI2qOLlujDQ/GvdTQ j+mQ== 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=jztfJDe50aB0ly+H5/kYKbIXRikakgUB8oCHS8bXvsg=; b=vJfxKxHRSFSv+9cCVhuWuNio4BrnC3PbUxZdzKOETH5zmF01UY1Ds9PVsXu5c1vmyw 1CcFKHROMYC1pIVyehhOvCYPzsIzuMkmQ05F3LUshWxZr36LOI081b3FGfvjsLWX7fZ9 xOxBGtGY0wItWeIyyvrUpmC9kcIdUzp+CAjWXeDCoJUuyfENePmtZiJS3BH/pEfaigup MpGwvqjBsa/n062OPCwgiSE5c2bsyhJBwGV9N4YO3KLqkj6veeKY00UqG1/KJdm4CdOj 7kUzi6/E+aNzVj9X4lqaJ9dhEqEGEEueLS9f3YdVDOO4PUL8q+ctHjJipiEj7XMV3UzH BaHQ== 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 s4-20020a17090699c400b00730ab8060e3si2705649ejn.979.2022.08.03.07.02.38; Wed, 03 Aug 2022 07:02:45 -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 6D30368B9C7; Wed, 3 Aug 2022 16:59:23 +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 6924C68B895 for ; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5550924055A for ; Wed, 3 Aug 2022 15:59:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id X3ghKctsAsDE for ; Wed, 3 Aug 2022 15:58:59 +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 DF63E24052D for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2D1253A04EA; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:35 +0200 Message-Id: <20220803135844.16662-16-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: move the input thread into its own 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: 0+vVhW7+fk+t It will contain more demuxing-specific code in the future. --- fftools/Makefile | 1 + fftools/ffmpeg.c | 110 --------------------------------- fftools/ffmpeg.h | 5 ++ fftools/ffmpeg_demux.c | 136 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 110 deletions(-) create mode 100644 fftools/ffmpeg_demux.c diff --git a/fftools/Makefile b/fftools/Makefile index 6285e6eacb..5907f5c57e 100644 --- a/fftools/Makefile +++ b/fftools/Makefile @@ -10,6 +10,7 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) OBJS-ffmpeg += \ + fftools/ffmpeg_demux.o \ fftools/ffmpeg_filter.o \ fftools/ffmpeg_hw.o \ fftools/ffmpeg_mux.o \ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index a377e776c7..0a94b0d05a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -161,8 +161,6 @@ static struct termios oldtty; static int restore_tty; #endif -static void free_input_threads(void); - /* sub2video hack: Convert subtitles to video with alpha to insert them in filter graphs. This is a temporary solution until libavfilter gets real subtitles support. @@ -3636,114 +3634,6 @@ static int check_keyboard_interaction(int64_t cur_time) return 0; } -static void *input_thread(void *arg) -{ - InputFile *f = arg; - AVPacket *pkt = f->pkt, *queue_pkt; - unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; - int ret = 0; - - while (1) { - ret = av_read_frame(f->ctx, pkt); - - if (ret == AVERROR(EAGAIN)) { - av_usleep(10000); - continue; - } - if (ret < 0) { - av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); - break; - } - queue_pkt = av_packet_alloc(); - if (!queue_pkt) { - av_packet_unref(pkt); - av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM)); - break; - } - av_packet_move_ref(queue_pkt, pkt); - ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); - if (flags && ret == AVERROR(EAGAIN)) { - flags = 0; - ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); - av_log(f->ctx, AV_LOG_WARNING, - "Thread message queue blocking; consider raising the " - "thread_queue_size option (current value: %d)\n", - f->thread_queue_size); - } - if (ret < 0) { - if (ret != AVERROR_EOF) - av_log(f->ctx, AV_LOG_ERROR, - "Unable to send packet to main thread: %s\n", - av_err2str(ret)); - av_packet_free(&queue_pkt); - av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); - break; - } - } - - return NULL; -} - -static void free_input_thread(int i) -{ - InputFile *f = input_files[i]; - AVPacket *pkt; - - if (!f || !f->in_thread_queue) - return; - av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); - while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) - av_packet_free(&pkt); - - pthread_join(f->thread, NULL); - av_thread_message_queue_free(&f->in_thread_queue); -} - -static void free_input_threads(void) -{ - int i; - - for (i = 0; i < nb_input_files; i++) - free_input_thread(i); -} - -static int init_input_thread(int i) -{ - int ret; - InputFile *f = input_files[i]; - - if (f->thread_queue_size <= 0) - f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); - - if (f->ctx->pb ? !f->ctx->pb->seekable : - strcmp(f->ctx->iformat->name, "lavfi")) - f->non_blocking = 1; - ret = av_thread_message_queue_alloc(&f->in_thread_queue, - f->thread_queue_size, sizeof(f->pkt)); - if (ret < 0) - return ret; - - if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { - av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); - av_thread_message_queue_free(&f->in_thread_queue); - return AVERROR(ret); - } - - return 0; -} - -static int init_input_threads(void) -{ - int i, ret; - - for (i = 0; i < nb_input_files; i++) { - ret = init_input_thread(i); - if (ret < 0) - return ret; - } - return 0; -} - static int get_input_packet(InputFile *f, AVPacket **pkt) { if (f->readrate || f->rate_emu) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index fc082bfbea..81356fd566 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -710,4 +710,9 @@ int64_t of_filesize(OutputFile *of); AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); +int init_input_threads(void); +int init_input_thread(int i); +void free_input_threads(void); +void free_input_thread(int i); + #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c new file mode 100644 index 0000000000..2629af5950 --- /dev/null +++ b/fftools/ffmpeg_demux.c @@ -0,0 +1,136 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "ffmpeg.h" + +#include "libavutil/error.h" +#include "libavutil/time.h" +#include "libavutil/thread.h" +#include "libavutil/threadmessage.h" + +#include "libavcodec/packet.h" + +#include "libavformat/avformat.h" + +static void *input_thread(void *arg) +{ + InputFile *f = arg; + AVPacket *pkt = f->pkt, *queue_pkt; + unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; + int ret = 0; + + while (1) { + ret = av_read_frame(f->ctx, pkt); + + if (ret == AVERROR(EAGAIN)) { + av_usleep(10000); + continue; + } + if (ret < 0) { + av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); + break; + } + queue_pkt = av_packet_alloc(); + if (!queue_pkt) { + av_packet_unref(pkt); + av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM)); + break; + } + av_packet_move_ref(queue_pkt, pkt); + ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); + if (flags && ret == AVERROR(EAGAIN)) { + flags = 0; + ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); + av_log(f->ctx, AV_LOG_WARNING, + "Thread message queue blocking; consider raising the " + "thread_queue_size option (current value: %d)\n", + f->thread_queue_size); + } + if (ret < 0) { + if (ret != AVERROR_EOF) + av_log(f->ctx, AV_LOG_ERROR, + "Unable to send packet to main thread: %s\n", + av_err2str(ret)); + av_packet_free(&queue_pkt); + av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); + break; + } + } + + return NULL; +} + +void free_input_thread(int i) +{ + InputFile *f = input_files[i]; + AVPacket *pkt; + + if (!f || !f->in_thread_queue) + return; + av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); + while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) + av_packet_free(&pkt); + + pthread_join(f->thread, NULL); + av_thread_message_queue_free(&f->in_thread_queue); +} + +void free_input_threads(void) +{ + int i; + + for (i = 0; i < nb_input_files; i++) + free_input_thread(i); +} + +int init_input_thread(int i) +{ + int ret; + InputFile *f = input_files[i]; + + if (f->thread_queue_size <= 0) + f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); + + if (f->ctx->pb ? !f->ctx->pb->seekable : + strcmp(f->ctx->iformat->name, "lavfi")) + f->non_blocking = 1; + ret = av_thread_message_queue_alloc(&f->in_thread_queue, + f->thread_queue_size, sizeof(f->pkt)); + if (ret < 0) + return ret; + + if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { + av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); + av_thread_message_queue_free(&f->in_thread_queue); + return AVERROR(ret); + } + + return 0; +} + +int init_input_threads(void) +{ + int i, ret; + + for (i = 0; i < nb_input_files; i++) { + ret = init_input_thread(i); + if (ret < 0) + return ret; + } + return 0; +} From patchwork Wed Aug 3 13:58:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37109 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458619pzb; Wed, 3 Aug 2022 07:01:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7RRSlc9PXyEfCJTTNw90B55kUxkepH708QX/0pD7Np4jSY8bFeFCI1TchVEeoOmzRU0CUe X-Received: by 2002:a17:907:94d2:b0:730:87c1:e86c with SMTP id dn18-20020a17090794d200b0073087c1e86cmr10924949ejc.129.1659535261459; Wed, 03 Aug 2022 07:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535261; cv=none; d=google.com; s=arc-20160816; b=WD0lHIu/3KAIcyZK7xX5DUUDcKKnU0IntPA8e/UwbdOKWAkWwmakA7ludf2FnXOoPR FNjzqIqWUg9v7PEuT03vQUwEMh4K21UD2l+8MMrBuW/JOi5Cpi0q4XcKa/K89FzVtMv9 xZuJ2ed12knsrfyNjeohqbWynbWvsADCVJHvUF9/8wYIAS/u+HaAXUaBZfIqEg3O0vNS 6l6fK6HRD1tiCTsPf3JZFfE6G+T2Nbk666BVvai80XlQdj5RpU1Y5HawrsaU2KgaCe2P coO08jxNLPZpoHMKcDUxsK2taXJAjv60ayUWqZPAkyczlhWhmluQ61tFRehRqMIuXo7/ Yn2Q== 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=VAVDVFPTLTwrLOkzt6bcMfmPtVdwvcK0Q0G3f0STZcA=; b=x6QsjzngqdCJ6lJzH//aj8N2HGfZJDyYRTSNl9T1hQOgu3DRFc/C8t/evjbVALNpyI D4I6VlAhA6AD2zmeahp9KVil7VNWmwZr9jM9LGaTGJMg7xXpwKUa9auXx4OkR9bdb+ZR VftFY1Jz4efIEYJ7RqUHN9r4x7/qDxcLyk9ClWnqWbwihGK8UA1ke6SshKFTFOyWiIIN S81FRBtU1ilUz6IhCWLZogVqRPr3SeJu04ydicJ7u9PLBb5Ri7DhW8qyc4Hn0mdcF8AI SFZSgkeblhrEbHhjVYpuay5CAAjsAunXTdQ8iRuWi4Q1EYxc4pmvVazCJfYtIRE+jP1K pe+A== 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 j8-20020a05640211c800b0043d646c3ef9si11034687edw.259.2022.08.03.07.01.01; Wed, 03 Aug 2022 07:01:01 -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 9371668B94D; Wed, 3 Aug 2022 16:59:14 +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 9E51E68B895 for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2E23D240590 for ; Wed, 3 Aug 2022 15:59:05 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AtLuN8xjOy90 for ; Wed, 3 Aug 2022 15:59:04 +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 1D6DA240687 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 317843A054D; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:36 +0200 Message-Id: <20220803135844.16662-17-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: drop the 'h' key handling 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: /8QVhzmPwoeM This undocumented feature runtime-enables dumping input packets. I can think of no reasonable real-world use case that cannot also be accomplished in a different way. Keeping this functionality would interfere with the following commit moving it to the input thread (then setting the variable would require locking or atomics, which would be unnecessarily complicated for a feature that probably nobody uses). --- fftools/ffmpeg.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0a94b0d05a..3911db1948 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3537,15 +3537,6 @@ static int check_keyboard_interaction(int64_t cur_time) if (key == '+') av_log_set_level(av_log_get_level()+10); if (key == '-') av_log_set_level(av_log_get_level()-10); if (key == 's') qp_hist ^= 1; - if (key == 'h'){ - if (do_hex_dump){ - do_hex_dump = do_pkt_dump = 0; - } else if(do_pkt_dump){ - do_hex_dump = 1; - } else - do_pkt_dump = 1; - av_log_set_level(AV_LOG_DEBUG); - } if (key == 'c' || key == 'C'){ char buf[4096], target[64], command[256], arg[256] = {0}; double time; From patchwork Wed Aug 3 13:58:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37115 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459502pzb; Wed, 3 Aug 2022 07:02:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DysFTtsUvtgMdAbF1zjQfJUgfpQaM/MmckQMSaap5L0Tkn8R6/pLmq5Yiy0s3pBU9OUg9 X-Received: by 2002:a17:907:1dd7:b0:730:8dfd:9e13 with SMTP id og23-20020a1709071dd700b007308dfd9e13mr10090969ejc.239.1659535327317; Wed, 03 Aug 2022 07:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535327; cv=none; d=google.com; s=arc-20160816; b=CycSkw2CsMKVdE/hFxOxHGbv7mx9w7WbEjGsWwtyQrHwL1y5EZC4iJkZl8KNDlzzqq HsoD9j/vme+sNIphAZuhSCs/X9adVxnYE9wg+k2Bl2zLXUrnsbO8IXIWViUtH+o/dcDB VSI7FVEQRg9GLnZeuYgt2KbYdf05iP4uv/7UDCq0ckkPftjRNmyG1d6SUhzQnxQbDczN 8boeBHN5qOYPoxNQS3t5hkALAsdVBdqQvMIrsvmQx5CVJ9ZpQ+i/1Alg3Pdf1BFkG7JQ jdLnO7YrCQUMls0iVM4yFsC0/tvg0A7XqiI2I56HNdZN4dJuVb1yEVbIuPCDUKpNg9g2 MA5w== 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=iYlxMg4b/YzUnUjLcjgYExYTESJWG6AixNI+5I2KQiE=; b=f53k6ql6fD1dIVHahq/KkodeITfaIvoRhCcrElpj9jsoSCvtFVW+7M6eYiP5MHXXg6 wj0+DlQggweRbbh27V6uHXMAjKoSYM89Lf/U4O1WBAaaDt00cGonty6RcdDoH/vt4wdi tCfJdnT6rae3CE3D6Igu5K2IH+2SfqOjS3LwRZumczzymgjBLa4gij147dX6OQA+CMEK Z7uo83KTi3JQM+uqpI3OpLWYFi3Mv9nCHDkt3tkmTFXz9rPnzysJZC1KZ5GClLHvdHPC i0SYHCo2KJx6S5kBVbL8D5I6ut8HzFAQhIs/mlbNr82XFR7ujo5L7/x8bDTu3YZ4DaU1 W1jA== 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 ds13-20020a170907724d00b007304f2e50c2si16066681ejc.52.2022.08.03.07.02.06; Wed, 03 Aug 2022 07:02:07 -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 4BE2868B9B0; Wed, 3 Aug 2022 16:59:20 +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 D704A68B895 for ; Wed, 3 Aug 2022 16:59:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 250072404FE for ; Wed, 3 Aug 2022 15:59:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id OLkvKZ1-AB2x for ; Wed, 3 Aug 2022 15:58:59 +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 EDBDF24055A for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 35E713A0592; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:37 +0200 Message-Id: <20220803135844.16662-18-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: handle dumping input packets in input_thread() 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: 6lSMc2c7k9/9 This is a more appropriate place for this. --- fftools/ffmpeg.c | 4 ---- fftools/ffmpeg_demux.c | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3911db1948..1393ca9c1e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3831,10 +3831,6 @@ static int process_input(int file_index) reset_eagain(); - if (do_pkt_dump) { - av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump, - is->streams[pkt->stream_index]); - } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ if (pkt->stream_index >= ifile->nb_streams) { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 2629af5950..f9bd6d47fe 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -45,6 +45,12 @@ static void *input_thread(void *arg) av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } + + if (do_pkt_dump) { + av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump, + f->ctx->streams[pkt->stream_index]); + } + queue_pkt = av_packet_alloc(); if (!queue_pkt) { av_packet_unref(pkt); From patchwork Wed Aug 3 13:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37117 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459839pzb; Wed, 3 Aug 2022 07:02:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vUZymeFaDzcvgL8cY2NmDjpEp2evxb2MkssfYOz0Ue73U2NVTbh4S1nxmwxUO8clDTZDNu X-Received: by 2002:a17:906:6a21:b0:72f:2174:16e6 with SMTP id qw33-20020a1709066a2100b0072f217416e6mr20545052ejc.177.1659535353742; Wed, 03 Aug 2022 07:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535353; cv=none; d=google.com; s=arc-20160816; b=ZYkWQm+TC3prSOknWwCs/AOiDu+oqAEr7nVPomTXUKawHaKShWlejP621dCfsvPJ7e DwWqQo9FrSNGK5PzhOSz49JGXqOT0WyLfPs4GWt/sPoT7KJngMnQixlDu+oD64bLz1Zc Ljkn4nZsBP5GM24i5bPeEpFH7Mxzoa2JbCSKR3ycZkeVAhXezEebEmn6JGRt2lct2Cpo 4uYgTso4sR8aRx6pB6Re3TgWXht0kWHvh8E6VtM+UUaBAF3FA09uXPWfAbOBC+IFIKAo hgcxx7p6f7W53UX3k1Lo3cNoFf/mq8viznb/3fETlK+uTRhGDFE75xcxesceG0s3wzHm Asdw== 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=K9jo3bk9SzPWr4Qd0LE6r3H2+N/cf/j5hOgLOI+H0WI=; b=DEsVLKTDCTaSO1FPCs4v8tJ5Ao6/w7mVI3D34LvLDyXdlHpHYw8S54EKnJ5BTaipNi avyODrcOiHVmQHsXJvBZPLM3z6DDG9A0Pe4ox5PS9Ap9cSBUfhp29sb8RoyL9Rx40ql+ rxAkG9Bm+2GYDSIhOUQf7LIPG1s855xh2g/tPqWhnO97xNHEuzOflKbpdCDbpO7mDZxt Fnkon5GPLlYRQHAQBnZCNew9Zh4sFfk2PXzauVAaZ82Ew3NWuz8DpBoukAWLCl41zdE7 mNzfpCXmjBU902zwzv2KlUUI6XwTDbtB0sqghxqDI5Gr8+GJrlA5za0EcjWLR1Jhz2JV jHVg== 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 qf21-20020a1709077f1500b007262c51b07dsi9324183ejc.724.2022.08.03.07.02.27; Wed, 03 Aug 2022 07:02:33 -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 655E468B9C2; Wed, 3 Aug 2022 16:59:22 +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 70E0F68B89E for ; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B496224052D for ; Wed, 3 Aug 2022 15:59:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4JsodODxBl6l for ; Wed, 3 Aug 2022 15:59:00 +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 EBB70240555 for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3AA9E3A05F9; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:38 +0200 Message-Id: <20220803135844.16662-19-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread 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: 3x2MkAKVKBJ3 This avoids a potential race with the demuxer adding new streams. It is also more efficient, since we no longer do inter-thread transfers of packets that will be just discarded. --- fftools/ffmpeg.c | 22 ---------------------- fftools/ffmpeg_demux.c | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1393ca9c1e..37f52f0208 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3277,21 +3277,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, return ret; } -static void report_new_stream(int input_index, AVPacket *pkt) -{ - InputFile *file = input_files[input_index]; - AVStream *st = file->ctx->streams[pkt->stream_index]; - - if (pkt->stream_index < file->nb_streams_warn) - return; - av_log(file->ctx, AV_LOG_WARNING, - "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", - av_get_media_type_string(st->codecpar->codec_type), - input_index, pkt->stream_index, - pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); - file->nb_streams_warn = pkt->stream_index + 1; -} - static int transcode_init(void) { int ret = 0, i, j, k; @@ -3831,13 +3816,6 @@ static int process_input(int file_index) reset_eagain(); - /* the following test is needed in case new streams appear - dynamically in stream : we ignore them */ - if (pkt->stream_index >= ifile->nb_streams) { - report_new_stream(file_index, pkt); - goto discard_packet; - } - ist = input_streams[ifile->ist_index + pkt->stream_index]; ist->data_size += pkt->size; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index f9bd6d47fe..66cb6ebd5f 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -20,6 +20,7 @@ #include "libavutil/error.h" #include "libavutil/time.h" +#include "libavutil/timestamp.h" #include "libavutil/thread.h" #include "libavutil/threadmessage.h" @@ -27,6 +28,20 @@ #include "libavformat/avformat.h" +static void report_new_stream(InputFile *file, AVPacket *pkt) +{ + AVStream *st = file->ctx->streams[pkt->stream_index]; + + if (pkt->stream_index < file->nb_streams_warn) + return; + av_log(file->ctx, AV_LOG_WARNING, + "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n", + av_get_media_type_string(st->codecpar->codec_type), + file->index, pkt->stream_index, + pkt->pos, av_ts2timestr(pkt->dts, &st->time_base)); + file->nb_streams_warn = pkt->stream_index + 1; +} + static void *input_thread(void *arg) { InputFile *f = arg; @@ -51,6 +66,14 @@ static void *input_thread(void *arg) f->ctx->streams[pkt->stream_index]); } + /* the following test is needed in case new streams appear + dynamically in stream : we ignore them */ + if (pkt->stream_index >= f->nb_streams) { + report_new_stream(f, pkt); + av_packet_unref(pkt); + continue; + } + queue_pkt = av_packet_alloc(); if (!queue_pkt) { av_packet_unref(pkt); From patchwork Wed Aug 3 13:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37114 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459364pzb; Wed, 3 Aug 2022 07:01:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR4agAV184LEc1j92zFXlZMw4IfCG9H3jwn0YZvttIOxu7Te/s8CTzm+9dSkg9cHCH58i6a8 X-Received: by 2002:a17:907:6d16:b0:730:9955:4e30 with SMTP id sa22-20020a1709076d1600b0073099554e30mr8485813ejc.634.1659535315910; Wed, 03 Aug 2022 07:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535315; cv=none; d=google.com; s=arc-20160816; b=vabCwFq8f4Q8cG69kDBdTC/YoHwZ7GP+s4Umq984ehcjXrxgIHQ3SSxjB31sqPgE9T nuWMducZgJb7MbOETn/0lbQlv/IIb0OJwQQ2L0aK57gg3xtoVhTAOX5Z8A6iZOtqMBS/ nmwf3pgKxrcJRTRhB3+bB1qbK3PLkmIJEUFbz35BGgLaYTxCEsMvdSkQaxfSSPuEo+nO 4wrJ9p4SCAuKMhcNuUIhMZw1aqrgSyCgHlQwWg2vRttjIR1YPWYnBqW+aH/KwNX0/8Wu q80Zfu7WDpEanNhi1yfUuv+KVVsxQWIzmrw6lh+tzecQsqxGONnQqvwhCMCpWNi6N2Bi yxyA== 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=ShI+Bw/DMQhN9+uayEMdceLGfoeAOh744yPL3IRgMiM=; b=PfEZFPMAoR5uQ95CHgXacumxfB89JtTNninR8fgqx7Fb7SzU7EtC/hheegHbOMEx3r bV5GZjcu2suYA4RV3YrgqoJJU29jNL8ZVesxhNtapgDBEjB2ch81gBAPJSAsQXgdNBy8 Y1LoxhMlltEoXw3oA466faWbg27UsVZoGrFHgQU0cjWFxrJhBtQvsOVNK9tykl/c9BF4 CIzVBwkGhABmTeZvWQGVP0tms10KIlRkZlIbIn9u2LSOIr3Y0WqpWeFGkLOXGUn0Hvt8 93OXXKhZk9FJVBvqLeKibmzT9+f/X8j67ysxsIyUZAjl1lKA3DV4yj/Tzojqy5IFHws0 +l5Q== 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 m18-20020a056402511200b0043d69430478si5167947edd.308.2022.08.03.07.01.55; Wed, 03 Aug 2022 07:01:55 -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 665CF68B9A8; Wed, 3 Aug 2022 16:59:19 +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 D353768B878 for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 206352405F0 for ; Wed, 3 Aug 2022 15:59:06 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WJ_8xSSDkB8Z for ; Wed, 3 Aug 2022 15:59:05 +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 1E0BB240688 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3F4B43A0656; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:39 +0200 Message-Id: <20220803135844.16662-20-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c 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: KU8mNJDPC8mj Also rename it to use the ifile_* namespace. --- fftools/ffmpeg.c | 30 ++---------------------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 37f52f0208..497a847101 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3610,32 +3610,6 @@ static int check_keyboard_interaction(int64_t cur_time) return 0; } -static int get_input_packet(InputFile *f, AVPacket **pkt) -{ - if (f->readrate || f->rate_emu) { - int i; - int64_t file_start = copy_ts * ( - (f->ctx->start_time != AV_NOPTS_VALUE ? f->ctx->start_time * !start_at_zero : 0) + - (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0) - ); - float scale = f->rate_emu ? 1.0 : f->readrate; - for (i = 0; i < f->nb_streams; i++) { - InputStream *ist = input_streams[f->ist_index + i]; - int64_t stream_ts_offset, pts, now; - if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue; - stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start); - pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE); - now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset; - if (pts > now) - return AVERROR(EAGAIN); - } - } - - return av_thread_message_queue_recv(f->in_thread_queue, pkt, - f->non_blocking ? - AV_THREAD_MESSAGE_NONBLOCK : 0); -} - static int got_eagain(void) { int i; @@ -3752,7 +3726,7 @@ static int process_input(int file_index) int disable_discontinuity_correction = copy_ts; is = ifile->ctx; - ret = get_input_packet(ifile, &pkt); + ret = ifile_get_packet(ifile, &pkt); if (ret == AVERROR(EAGAIN)) { ifile->eagain = 1; @@ -3777,7 +3751,7 @@ static int process_input(int file_index) if (ret < 0) av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n"); else - ret = get_input_packet(ifile, &pkt); + ret = ifile_get_packet(ifile, &pkt); if (ret == AVERROR(EAGAIN)) { ifile->eagain = 1; return ret; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 81356fd566..f983d077d9 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -710,6 +710,7 @@ int64_t of_filesize(OutputFile *of); AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); +int ifile_get_packet(InputFile *f, AVPacket **pkt); int init_input_threads(void); int init_input_thread(int i); void free_input_threads(void); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 66cb6ebd5f..1e95be349c 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -163,3 +163,29 @@ int init_input_threads(void) } return 0; } + +int ifile_get_packet(InputFile *f, AVPacket **pkt) +{ + if (f->readrate || f->rate_emu) { + int i; + int64_t file_start = copy_ts * ( + (f->ctx->start_time != AV_NOPTS_VALUE ? f->ctx->start_time * !start_at_zero : 0) + + (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0) + ); + float scale = f->rate_emu ? 1.0 : f->readrate; + for (i = 0; i < f->nb_streams; i++) { + InputStream *ist = input_streams[f->ist_index + i]; + int64_t stream_ts_offset, pts, now; + if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue; + stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start); + pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE); + now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset; + if (pts > now) + return AVERROR(EAGAIN); + } + } + + return av_thread_message_queue_recv(f->in_thread_queue, pkt, + f->non_blocking ? + AV_THREAD_MESSAGE_NONBLOCK : 0); +} From patchwork Wed Aug 3 13:58:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37116 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459625pzb; Wed, 3 Aug 2022 07:02:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR4kEJeFjHqPvLo7YwzRcx8kXnSMxp0ylJV7Ee6Nvom2MJSZyoLqSUFcJ2HTORLYZeq2FguR X-Received: by 2002:a17:906:98d5:b0:730:4f6b:ce28 with SMTP id zd21-20020a17090698d500b007304f6bce28mr15357516ejb.736.1659535337746; Wed, 03 Aug 2022 07:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535337; cv=none; d=google.com; s=arc-20160816; b=RS6psK7yG1bstZvEvX+QiQCOV19DQdi/ePZ8czFP4FtJmpA2jm5DTnGVlMNJj7FVud 1726Sa7GoH9o21yRrHD31yU9Ff7dkLC8f9wlks1VV0YVbZEz38KrA5eSfNs0YsxfWtZJ OC9u6AFZnktXSpF75/3/rIY4YR+iz/vPSU9i9YlealQkZ8yX4sKgDY2BEOkwdzlSs6bP Zx38J0Pd7//u7B16EPlQiwRQc1bTQTaRaz4phTvVQdmo6aNbyV9rCi63hgVZ0pD3Xiko 1mfBftqidto8LroHfyxh2VVaOLLw0w4gHhxWOY6wPITp5ArleGlKAY8qmodzf0O0BzEV LJeg== 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=vktvzHkyTK0g61gi3ijlNTEh8NZscUDVQbziBjBF+2Q=; b=FQZ4kwGtPI1HglXL9O3bkTvoJc7M34eUA+XRUqSU+/1LgWe7/JXTqe/IgfWjbRlEwR Sa6QofjFKY5kej7ckUyEDHLdxU4znU3GXzQ/k4R9zqs3LsUZaPXW0ss7li1rIOApcC3B 9IczpSv/B4sNnlDx5JJU0aDO8qW5HHUCPjW2g8olA9fMvOc77UYMiT/TO2FLAAHNmUyo 7t5LvqyfTgDUiRwd6dol8+D8Q8G42T6wXeglP62v6ZKvV82mo0hP3YMRXfcKoU4Lo8zm /IxEvZAa2Uxm4RuUP0dgrN7v6W2kZpGYH54Zoh6Oicspomqp1dKBVd6zIoMkrVzEYAIt 4TNQ== 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 hq12-20020a1709073f0c00b007309e910729si3988721ejc.580.2022.08.03.07.02.17; Wed, 03 Aug 2022 07:02:17 -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 5DAB668B9B5; Wed, 3 Aug 2022 16:59:21 +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 E792168B89E for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 88024240506 for ; Wed, 3 Aug 2022 15:59:06 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wYnIzWpj-yDd for ; Wed, 3 Aug 2022 15:59:05 +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 2320224068C for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 438C43A06A9; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:40 +0200 Message-Id: <20220803135844.16662-21-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move seek_to_start() to ffmpeg_demux.c 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: SIf2GF821fH9 Reduces the diff in the following commit. --- fftools/ffmpeg.c | 79 ------------------------------------------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 79 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 79 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 497a847101..90e25973d3 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3628,85 +3628,6 @@ static void reset_eagain(void) output_streams[i]->unavailable = 0; } -// set duration to max(tmp, duration) in a proper time base and return duration's time_base -static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base, - AVRational time_base) -{ - int ret; - - if (!*duration) { - *duration = tmp; - return tmp_time_base; - } - - ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base); - if (ret < 0) { - *duration = tmp; - return tmp_time_base; - } - - return time_base; -} - -static int seek_to_start(InputFile *ifile, AVFormatContext *is) -{ - InputStream *ist; - AVCodecContext *avctx; - int i, ret, has_audio = 0; - int64_t duration = 0; - - ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0); - if (ret < 0) - return ret; - - for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; - avctx = ist->dec_ctx; - - /* duration is the length of the last frame in a stream - * when audio stream is present we don't care about - * last video frame length because it's not defined exactly */ - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) - has_audio = 1; - } - - for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; - avctx = ist->dec_ctx; - - if (has_audio) { - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) { - AVRational sample_rate = {1, avctx->sample_rate}; - - duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base); - } else { - continue; - } - } else { - if (ist->framerate.num) { - duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base); - } else if (ist->st->avg_frame_rate.num) { - duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base); - } else { - duration = 1; - } - } - if (!ifile->duration) - ifile->time_base = ist->st->time_base; - /* the total duration of the stream, max_pts - min_pts is - * the duration of the stream without the last frame */ - if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration) - duration += ist->max_pts - ist->min_pts; - ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base, - ifile->time_base); - } - - if (ifile->loop > 0) - ifile->loop--; - - return ret; -} - /* * Return * - 0 -- one packet was read and processed diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index f983d077d9..2a9c34eb93 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -715,5 +715,6 @@ int init_input_threads(void); int init_input_thread(int i); void free_input_threads(void); void free_input_thread(int i); +int seek_to_start(InputFile *ifile, AVFormatContext *is); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 1e95be349c..ff9313b040 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -42,6 +42,85 @@ static void report_new_stream(InputFile *file, AVPacket *pkt) file->nb_streams_warn = pkt->stream_index + 1; } +// set duration to max(tmp, duration) in a proper time base and return duration's time_base +static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base, + AVRational time_base) +{ + int ret; + + if (!*duration) { + *duration = tmp; + return tmp_time_base; + } + + ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base); + if (ret < 0) { + *duration = tmp; + return tmp_time_base; + } + + return time_base; +} + +int seek_to_start(InputFile *ifile, AVFormatContext *is) +{ + InputStream *ist; + AVCodecContext *avctx; + int i, ret, has_audio = 0; + int64_t duration = 0; + + ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0); + if (ret < 0) + return ret; + + for (i = 0; i < ifile->nb_streams; i++) { + ist = input_streams[ifile->ist_index + i]; + avctx = ist->dec_ctx; + + /* duration is the length of the last frame in a stream + * when audio stream is present we don't care about + * last video frame length because it's not defined exactly */ + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) + has_audio = 1; + } + + for (i = 0; i < ifile->nb_streams; i++) { + ist = input_streams[ifile->ist_index + i]; + avctx = ist->dec_ctx; + + if (has_audio) { + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) { + AVRational sample_rate = {1, avctx->sample_rate}; + + duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base); + } else { + continue; + } + } else { + if (ist->framerate.num) { + duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base); + } else if (ist->st->avg_frame_rate.num) { + duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base); + } else { + duration = 1; + } + } + if (!ifile->duration) + ifile->time_base = ist->st->time_base; + /* the total duration of the stream, max_pts - min_pts is + * the duration of the stream without the last frame */ + if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration) + duration += ist->max_pts - ist->min_pts; + ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base, + ifile->time_base); + } + + if (ifile->loop > 0) + ifile->loop--; + + return ret; +} + static void *input_thread(void *arg) { InputFile *f = arg; From patchwork Wed Aug 3 13:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37122 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp460450pzb; Wed, 3 Aug 2022 07:03:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t3ps4nVWhbYzhTq1cx2XFP225zxnBlSzlF87uo5yzYTOOUFASH9e40vwKtCO4LqSlyd3BN X-Received: by 2002:a05:6402:40c3:b0:43b:d65a:cbf7 with SMTP id z3-20020a05640240c300b0043bd65acbf7mr26475169edb.380.1659535403910; Wed, 03 Aug 2022 07:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535403; cv=none; d=google.com; s=arc-20160816; b=MZLdAcU3YB1XUw6WXXDPG5dtkEaI6Wk95oZg/IOcNPlvbBrnAfqsCifk5LWrlnExJG RyoJgPGEEfNyEsGqi7EiI0x0X6hs1J6SnhTSJSyFqoIxN7Oc8SywMmSb1qVp5G9wAykK SSae+1jYqvumQLBg4Uw/1pV7BWm11ChAFXfdB4CFxJT0MNVd5yOeJOXteAOVTwurq2I4 JMGkaohO3NDAtNFysOHcsdXUK9M1UMp4y469e3oBZgGoal77wjh0igoVk1tx8fbynmeD KaAy7hFlbDH3I8JZx55A/ZfyLfWk/XEaxk27tPHqLwLK5xct0c4PQ++HNAJpWgSVxc63 vryg== 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=/Uxu6jCIs1I1eTeTdKDOwy5iWCDvdkzqrS3jHBYTpgw=; b=AgUwGjU1HWywWynzwOgOmoez3dTjmev+LJDXoiNnimpg+2uoDiOlIWaYfUYl77Mbtt BA7PJMc+Zekifhmf4DQbkGpYg9ocmMwI0CrDoDXt1ilc4qDHjaLo8fiTNxkkATEIZxoq Wnk8RoiRl0Zas/kPi6jfn5g/jMVjsscC4ghUN7jH0gXbKjwJnpi+97jzY9O1BYHfPjzb pbi/+pMh8rAFpwADAf93ynH1TO51l00Hy5q+oy6msOL12VWkQKun7e7OEC0auyA+04Ad 7g1Yq3bj5Of25TnpxiJP4+Y5Rq/vJYzil8lR/TPcotL9S74jGKruHLiAn/XYG/Hz+Ain nPQQ== 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 hq12-20020a1709073f0c00b007309e910729si3990230ejc.580.2022.08.03.07.03.23; Wed, 03 Aug 2022 07:03:23 -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 49A9968B8D7; Wed, 3 Aug 2022 16:59:27 +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 044AB68B884 for ; Wed, 3 Aug 2022 16:59:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 93ABC240555 for ; Wed, 3 Aug 2022 15:59:04 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cY35a3Zs88bC for ; Wed, 3 Aug 2022 15:59:02 +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 054B8240593 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 487643A06E5; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:41 +0200 Message-Id: <20220803135844.16662-22-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg: move -stream_loop handling to the demuxer thread 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: IKaEa1YoMlsG -stream_loop is currently handled by destroying the demuxer thread, seeking, then recreating it anew. This is very messy and conflicts with the future goal of moving each major ffmpeg component into its own thread. Handle -stream_loop directly in the demuxer thread. Looping requires the demuxer to know the duration of the file, which takes into account the duration of the last decoded audio frame (if any). Use a thread message queue to communicate this information from the main thread to the demuxer thread. --- fftools/ffmpeg.c | 61 ++++++++------- fftools/ffmpeg.h | 23 +++++- fftools/ffmpeg_demux.c | 166 +++++++++++++++++++++++++---------------- 3 files changed, 158 insertions(+), 92 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 90e25973d3..0218f330b9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3628,6 +3628,37 @@ static void reset_eagain(void) output_streams[i]->unavailable = 0; } +static void decode_flush(InputFile *ifile) +{ + for (int i = 0; i < ifile->nb_streams; i++) { + InputStream *ist = input_streams[ifile->ist_index + i]; + int ret; + + if (!ist->processing_needed) + continue; + + do { + ret = process_input_packet(ist, NULL, 1); + } while (ret > 0); + + if (ist->decoding_needed) { + /* report last frame duration to the demuxer thread */ + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + LastFrameDuration dur; + + dur.stream_idx = i; + dur.duration = av_rescale_q(ist->nb_samples, + (AVRational){ 1, ist->dec_ctx->sample_rate}, + ist->st->time_base); + + av_thread_message_queue_send(ifile->audio_duration_queue, &dur, 0); + } + + avcodec_flush_buffers(ist->dec_ctx); + } + } +} + /* * Return * - 0 -- one packet was read and processed @@ -3641,7 +3672,7 @@ static int process_input(int file_index) AVFormatContext *is; InputStream *ist; AVPacket *pkt; - int ret, thread_ret, i, j; + int ret, i, j; int64_t duration; int64_t pkt_dts; int disable_discontinuity_correction = copy_ts; @@ -3653,30 +3684,10 @@ static int process_input(int file_index) ifile->eagain = 1; return ret; } - if (ret < 0 && ifile->loop) { - for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; - if (ist->processing_needed) { - ret = process_input_packet(ist, NULL, 1); - if (ret>0) - return 0; - if (ist->decoding_needed) - avcodec_flush_buffers(ist->dec_ctx); - } - } - free_input_thread(file_index); - ret = seek_to_start(ifile, is); - thread_ret = init_input_thread(file_index); - if (thread_ret < 0) - return thread_ret; - if (ret < 0) - av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n"); - else - ret = ifile_get_packet(ifile, &pkt); - if (ret == AVERROR(EAGAIN)) { - ifile->eagain = 1; - return ret; - } + if (ret == 1) { + /* the input file is looped: flush the decoders */ + decode_flush(ifile); + return AVERROR(EAGAIN); } if (ret < 0) { if (ret != AVERROR_EOF) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2a9c34eb93..aa97f35310 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -407,6 +407,11 @@ typedef struct InputStream { int got_output; } InputStream; +typedef struct LastFrameDuration { + int stream_idx; + int64_t duration; +} LastFrameDuration; + typedef struct InputFile { int index; @@ -438,6 +443,11 @@ typedef struct InputFile { pthread_t thread; /* thread reading from this file */ int non_blocking; /* reading packets from the thread should not block */ int thread_queue_size; /* maximum number of queued packets */ + + /* when looping the input file, this queue is used by decoders to report + * the last frame duration back to the demuxer thread */ + AVThreadMessageQueue *audio_duration_queue; + int audio_duration_queue_size; } InputFile; enum forced_keyframes_const { @@ -710,11 +720,18 @@ int64_t of_filesize(OutputFile *of); AVChapter * const * of_get_chapters(OutputFile *of, unsigned int *nb_chapters); +/** + * Get next input packet from the demuxer. + * + * @param pkt the packet is written here when this function returns 0 + * @return + * - 0 when a packet has been read successfully + * - 1 when stream end was reached, but the stream is looped; + * caller should flush decoders and read from this demuxer again + * - a negative error code on failure + */ int ifile_get_packet(InputFile *f, AVPacket **pkt); int init_input_threads(void); -int init_input_thread(int i); void free_input_threads(void); -void free_input_thread(int i); -int seek_to_start(InputFile *ifile, AVFormatContext *is); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index ff9313b040..e02d2d9656 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -28,6 +28,11 @@ #include "libavformat/avformat.h" +typedef struct DemuxMsg { + AVPacket *pkt; + int looping; +} DemuxMsg; + static void report_new_stream(InputFile *file, AVPacket *pkt) { AVStream *st = file->ctx->streams[pkt->stream_index]; @@ -42,61 +47,54 @@ static void report_new_stream(InputFile *file, AVPacket *pkt) file->nb_streams_warn = pkt->stream_index + 1; } -// set duration to max(tmp, duration) in a proper time base and return duration's time_base -static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base, - AVRational time_base) +static void ifile_duration_update(InputFile *f, InputStream *ist, + int64_t last_duration) { - int ret; - - if (!*duration) { - *duration = tmp; - return tmp_time_base; + /* the total duration of the stream, max_pts - min_pts is + * the duration of the stream without the last frame */ + if (ist->max_pts > ist->min_pts && + ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration) + last_duration += ist->max_pts - ist->min_pts; + + if (!f->duration || + av_compare_ts(f->duration, f->time_base, + last_duration, ist->st->time_base) < 0) { + f->duration = last_duration; + f->time_base = ist->st->time_base; } - - ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base); - if (ret < 0) { - *duration = tmp; - return tmp_time_base; - } - - return time_base; } -int seek_to_start(InputFile *ifile, AVFormatContext *is) +static int seek_to_start(InputFile *ifile) { + AVFormatContext *is = ifile->ctx; InputStream *ist; - AVCodecContext *avctx; - int i, ret, has_audio = 0; - int64_t duration = 0; + int ret; ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0); if (ret < 0) return ret; - for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; - avctx = ist->dec_ctx; - + if (ifile->audio_duration_queue_size) { /* duration is the length of the last frame in a stream * when audio stream is present we don't care about * last video frame length because it's not defined exactly */ - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) - has_audio = 1; - } + int got_durations = 0; - for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; - avctx = ist->dec_ctx; + while (got_durations < ifile->audio_duration_queue_size) { + LastFrameDuration dur; + ret = av_thread_message_queue_recv(ifile->audio_duration_queue, &dur, 0); + if (ret < 0) + return ret; + got_durations++; - if (has_audio) { - if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) { - AVRational sample_rate = {1, avctx->sample_rate}; + ist = input_streams[ifile->ist_index + dur.stream_idx]; + ifile_duration_update(ifile, ist, dur.duration); + } + } else { + for (int i = 0; i < ifile->nb_streams; i++) { + int64_t duration = 0; + ist = input_streams[ifile->ist_index + i]; - duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base); - } else { - continue; - } - } else { if (ist->framerate.num) { duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base); } else if (ist->st->avg_frame_rate.num) { @@ -104,15 +102,9 @@ int seek_to_start(InputFile *ifile, AVFormatContext *is) } else { duration = 1; } + + ifile_duration_update(ifile, ist, duration); } - if (!ifile->duration) - ifile->time_base = ist->st->time_base; - /* the total duration of the stream, max_pts - min_pts is - * the duration of the stream without the last frame */ - if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration) - duration += ist->max_pts - ist->min_pts; - ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base, - ifile->time_base); } if (ifile->loop > 0) @@ -124,11 +116,13 @@ int seek_to_start(InputFile *ifile, AVFormatContext *is) static void *input_thread(void *arg) { InputFile *f = arg; - AVPacket *pkt = f->pkt, *queue_pkt; + AVPacket *pkt = f->pkt; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; while (1) { + DemuxMsg msg = { NULL }; + ret = av_read_frame(f->ctx, pkt); if (ret == AVERROR(EAGAIN)) { @@ -136,6 +130,18 @@ static void *input_thread(void *arg) continue; } if (ret < 0) { + if (f->loop) { + /* signal looping to the consumer thread */ + msg.looping = 1; + ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0); + if (ret >= 0) + ret = seek_to_start(f); + if (ret >= 0) + continue; + + /* fallthrough to the error path */ + } + av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } @@ -153,17 +159,17 @@ static void *input_thread(void *arg) continue; } - queue_pkt = av_packet_alloc(); - if (!queue_pkt) { + msg.pkt = av_packet_alloc(); + if (!msg.pkt) { av_packet_unref(pkt); av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM)); break; } - av_packet_move_ref(queue_pkt, pkt); - ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); + av_packet_move_ref(msg.pkt, pkt); + ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags); if (flags && ret == AVERROR(EAGAIN)) { flags = 0; - ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); + ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags); av_log(f->ctx, AV_LOG_WARNING, "Thread message queue blocking; consider raising the " "thread_queue_size option (current value: %d)\n", @@ -174,7 +180,7 @@ static void *input_thread(void *arg) av_log(f->ctx, AV_LOG_ERROR, "Unable to send packet to main thread: %s\n", av_err2str(ret)); - av_packet_free(&queue_pkt); + av_packet_free(&msg.pkt); av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } @@ -183,19 +189,20 @@ static void *input_thread(void *arg) return NULL; } -void free_input_thread(int i) +static void free_input_thread(int i) { InputFile *f = input_files[i]; - AVPacket *pkt; + DemuxMsg msg; if (!f || !f->in_thread_queue) return; av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); - while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) - av_packet_free(&pkt); + while (av_thread_message_queue_recv(f->in_thread_queue, &msg, 0) >= 0) + av_packet_free(&msg.pkt); pthread_join(f->thread, NULL); av_thread_message_queue_free(&f->in_thread_queue); + av_thread_message_queue_free(&f->audio_duration_queue); } void free_input_threads(void) @@ -206,7 +213,7 @@ void free_input_threads(void) free_input_thread(i); } -int init_input_thread(int i) +static int init_input_thread(int i) { int ret; InputFile *f = input_files[i]; @@ -218,17 +225,38 @@ int init_input_thread(int i) strcmp(f->ctx->iformat->name, "lavfi")) f->non_blocking = 1; ret = av_thread_message_queue_alloc(&f->in_thread_queue, - f->thread_queue_size, sizeof(f->pkt)); + f->thread_queue_size, sizeof(DemuxMsg)); if (ret < 0) return ret; + if (f->loop) { + int nb_audio_dec = 0; + + for (int i = 0; i < f->nb_streams; i++) { + InputStream *ist = input_streams[f->ist_index + i]; + nb_audio_dec += !!(ist->decoding_needed && + ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); + } + + if (nb_audio_dec) { + ret = av_thread_message_queue_alloc(&f->audio_duration_queue, + nb_audio_dec, sizeof(LastFrameDuration)); + if (ret < 0) + goto fail; + f->audio_duration_queue_size = nb_audio_dec; + } + } + if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); - av_thread_message_queue_free(&f->in_thread_queue); - return AVERROR(ret); + ret = AVERROR(ret); + goto fail; } return 0; +fail: + av_thread_message_queue_free(&f->in_thread_queue); + return ret; } int init_input_threads(void) @@ -245,6 +273,9 @@ int init_input_threads(void) int ifile_get_packet(InputFile *f, AVPacket **pkt) { + DemuxMsg msg; + int ret; + if (f->readrate || f->rate_emu) { int i; int64_t file_start = copy_ts * ( @@ -264,7 +295,14 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) } } - return av_thread_message_queue_recv(f->in_thread_queue, pkt, - f->non_blocking ? - AV_THREAD_MESSAGE_NONBLOCK : 0); + ret = av_thread_message_queue_recv(f->in_thread_queue, &msg, + f->non_blocking ? + AV_THREAD_MESSAGE_NONBLOCK : 0); + if (ret < 0) + return ret; + if (msg.looping) + return 1; + + *pkt = msg.pkt; + return 0; } From patchwork Wed Aug 3 13:58:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457875pzb; Wed, 3 Aug 2022 06:59:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYebjzzwWsSmNi7Uv3j9l5iQvJBiIJh0rwfrCJwXitUnCLvZpRS9ei7KPfQMWbRZYTotS9 X-Received: by 2002:a17:907:d8b:b0:72f:4645:1730 with SMTP id go11-20020a1709070d8b00b0072f46451730mr21011676ejc.724.1659535199391; Wed, 03 Aug 2022 06:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535199; cv=none; d=google.com; s=arc-20160816; b=OcDZ15QOrgzTeh8l1AGTcSNUtd/5KF7MjLIYqf0RlVgli5N9qWxNu4hNA7fccv4XxH VMyn1Fs87sDZHJbIsQJfYFuz6u+PvQOxJ30d3Teifq5IjDd037sOfjV9FoS127EbKug4 TWf/51Y/mmoj64zT+BDErsL40LW81JzZPPOqKyTxJWxJTxNkPGU/C45z+UX6BxvfDKhA o+n3a63o+vCnrUnGqP8bUPrObkJazGjVTpAwJCBX+Rod+zl7sLlTsl/yXR2WLuEgjEHp E9+YeyB9kkdrZzSa9bU5XeUJ7hVOjxWBlRj//kminX97wHHrTeCLSefPlz0rup9uKWc0 DS+g== 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=0XRM6/+kizNBUT3xzGWu7pHqC/43EhOdGJEVmpIKgCY=; b=VT/20sxLnss1GhPF3h0K7HqMfr9qC+sJkucwSX0YKsIfDIWdybRCz9foeqrAp/4WBI YSxkzETwFkIE2UkpVj14T+wEyoCuxo0P6QS+cJGXNTkZztvKAfA+5OGBojTA/TqDkxSt 88qNTdsVlDDCIjKCl92RQvfct0V9aVjkLjd+vf3CTa2+kpLwkRoq1OdFoD1e8uze002i Ex88rhaRwKqE0ImA82BcVwP3njf4O7mdflxp+nKpxekQRrzcFJW1Nfa2FI9Z17bO3m9r tD06xZAGvwbfj9kjg16KPKgTk+tQq8UHXV7oEAL1rLfd3iCMp6cyCxUMF7lP86q639Ov IFLA== 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 cy12-20020a0564021c8c00b0043565c5a2fbsi13625467edb.89.2022.08.03.06.59.58; Wed, 03 Aug 2022 06:59:59 -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 8E44268B8C3; Wed, 3 Aug 2022 16:59:08 +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 E053068B7C2 for ; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7EB792400F5 for ; Wed, 3 Aug 2022 15:59:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Y6MSlJO_DO1k for ; Wed, 3 Aug 2022 15:59:00 +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 04D9D240592 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 4CD173A075F; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:42 +0200 Message-Id: <20220803135844.16662-23-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_demux: factorize signalling end of demuxing 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: kIICAHbtSxxt --- fftools/ffmpeg_demux.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index e02d2d9656..be734be581 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -18,6 +18,7 @@ #include "ffmpeg.h" +#include "libavutil/avassert.h" #include "libavutil/error.h" #include "libavutil/time.h" #include "libavutil/timestamp.h" @@ -142,7 +143,6 @@ static void *input_thread(void *arg) /* fallthrough to the error path */ } - av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } @@ -162,7 +162,7 @@ static void *input_thread(void *arg) msg.pkt = av_packet_alloc(); if (!msg.pkt) { av_packet_unref(pkt); - av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM)); + ret = AVERROR(ENOMEM); break; } av_packet_move_ref(msg.pkt, pkt); @@ -181,11 +181,13 @@ static void *input_thread(void *arg) "Unable to send packet to main thread: %s\n", av_err2str(ret)); av_packet_free(&msg.pkt); - av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } } + av_assert0(ret < 0); + av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); + return NULL; } From patchwork Wed Aug 3 13:58: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: 37111 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp459012pzb; Wed, 3 Aug 2022 07:01:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DBvKBUx8nu+zDxVTmgK89HxTnhDYMzlLfYBfwIq9r1SF1oT33rj0kiku8D19LkR1zXLDA X-Received: by 2002:a17:907:a078:b0:730:750b:bb91 with SMTP id ia24-20020a170907a07800b00730750bbb91mr13105578ejc.332.1659535282126; Wed, 03 Aug 2022 07:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535282; cv=none; d=google.com; s=arc-20160816; b=bcJnAcfmRptNLaMUgRcfoB9yWwZBqDBeO4cDW8xchapEHDSbd2zfxfh1TCDMa3caap huzgOj+l3aDEOgboxinqSfLQet/nu7kEVoySbAOXoSCwqHEqMpTW1wKfgmrGd9rthOn2 lYJ1BL+MUtzeX2nO3QV5kUOsU9F7eN44X/xfkjWcb5dGyLP3OffhyFDySvc34moB6PTQ IErTHjS2S9KFpoXeI0qZpughlUVixZS5fuh3RcweVZ1PM1h1Qc7NI17Xae7QY93sA7Ty 8mU8nZXfFnaoSaw6T3IVMO38qyFvrQyIj2ThsfEzhMTDT0tmGIEPHDjR00SjH0xRncL6 hhQw== 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=fdrsxp6lm9im6a7P+7G26AEY/RibG1lB/INy3cnIrVQ=; b=zUTrqwhFI4LKYno+59nl1jONtccdVua7fvDAe0Kf+yxQozlt7puPLzrku9uD60tPXo 6CZzDv/4F9n7jesB+QLaMd4WwIMgN0oA2b2kDEIpf+lbvZL+XXQzANnWy3KiM8D6MfE7 9P8gDzLJIXHw567PUY7tR93lfzAaHu8WJOFonxiaSblPYz8p8f5/aFqs7GZBzXknx26b OwRFPD9HOYyUgng5CDLyAHOSWFHd7Yf5zKwONMbvdo7RNzptwybjs26fIQ4XwS0Sixfx 7La/5Q2SxPfclL8mBGTcq0Z41d0ydGDV1AMJQDpagXT3r4117vtqVEpUtMN7DxFxWSCx NRMw== 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 f18-20020a056402355200b0043c233945f4si8698362edd.477.2022.08.03.07.01.21; Wed, 03 Aug 2022 07:01:22 -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 9184C68B95E; Wed, 3 Aug 2022 16:59:16 +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 A0F6C68B896 for ; Wed, 3 Aug 2022 16:59:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B09FF240593 for ; Wed, 3 Aug 2022 15:59:05 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id w5BLaMEgzg0B for ; Wed, 3 Aug 2022 15:59:05 +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 2332F24068D for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 514E03A07D1; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:43 +0200 Message-Id: <20220803135844.16662-24-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_demux: do not store demux packet in the context 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: 5eo1B3I01uom Its use is local to input_thread(). --- fftools/ffmpeg.c | 1 - fftools/ffmpeg.h | 2 -- fftools/ffmpeg_demux.c | 11 ++++++++++- fftools/ffmpeg_opt.c | 3 --- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0218f330b9..a9eda3c33e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -593,7 +593,6 @@ static void ffmpeg_cleanup(int ret) free_input_threads(); for (i = 0; i < nb_input_files; i++) { avformat_close_input(&input_files[i]->ctx); - av_packet_free(&input_files[i]->pkt); av_freep(&input_files[i]); } for (i = 0; i < nb_input_streams; i++) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index aa97f35310..2ac7cbe522 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -437,8 +437,6 @@ typedef struct InputFile { float readrate; int accurate_seek; - AVPacket *pkt; - AVThreadMessageQueue *in_thread_queue; pthread_t thread; /* thread reading from this file */ int non_blocking; /* reading packets from the thread should not block */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index be734be581..af54ea3de1 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -117,10 +117,16 @@ static int seek_to_start(InputFile *ifile) static void *input_thread(void *arg) { InputFile *f = arg; - AVPacket *pkt = f->pkt; + AVPacket *pkt; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; + pkt = av_packet_alloc(); + if (!pkt) { + ret = AVERROR(ENOMEM); + goto finish; + } + while (1) { DemuxMsg msg = { NULL }; @@ -185,9 +191,12 @@ static void *input_thread(void *arg) } } +finish: av_assert0(ret < 0); av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); + av_packet_free(&pkt); + return NULL; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 25aa9aaff5..97f14b2a5b 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1407,9 +1407,6 @@ static int open_input_file(OptionsContext *o, const char *filename) f->rate_emu = 0; } - f->pkt = av_packet_alloc(); - if (!f->pkt) - exit_program(1); f->thread_queue_size = o->thread_queue_size; /* check if all codec options have been used */ From patchwork Wed Aug 3 13:58:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37104 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp458005pzb; Wed, 3 Aug 2022 07:00:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR4o9oi1cfi3lDpM+OTFDal01WluHAi3YzSRaJ8FkNvDEpwiY9B1SpSeDCXDaiuPnArWo/Wc X-Received: by 2002:a17:906:cc0c:b0:730:8bbb:69ac with SMTP id ml12-20020a170906cc0c00b007308bbb69acmr10786149ejb.392.1659535209425; Wed, 03 Aug 2022 07:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535209; cv=none; d=google.com; s=arc-20160816; b=Aaril2qXdjf1AZfU/u5bcAu+N8OL9JcBS5S9dPm0sx04avq7rxMurmftB7XlzIixqO 45DNZWsiuFUM7Qq4TFHAMlPghQkqhyPC70Mw3BxKzM8D4fTpCjTqWUcUoCpu2rS7YpZk FYYlyQlCtCJAwBnf+KLNp8ZfLF83BDKTQKeVVWKAXhTeXpc9DfyJHXnpf8cSE5nwfvMV SZDXlXh52dCLhNZWdnGzze58GZuBlV9QZ7o6830JXItoy19UdrLMtNhK2j1BzdJtDSfv wM0Krfrtl5q7oOTI0G7t08/bwyLfgbra1WwMhwgUYRflz+geKasiITt/siUvYMlxp7IQ IJmQ== 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=2mLmImSZeoD4Iqnxiw+sMZyqC/B8h+c6G8fEyMSIDqg=; b=rj1bnoeJPcw8dklx1zUaFUYN3iOixQkUkNYUQ61AO6eg5p2vGMn3NiDMAu3hV5miQS 3G1fhFTIYiL7efIHDPztNZ8NNGXF9beAt44ByUaLcWc73TJ+8u3f6j3hAxpLIbtwDB9B ClJQF6VspYuq6z6vXPSdWvjFWu4G6ERU3fs9OVVxk0Ap3fiSHHSOKbCzu4TidJnzlrDd CWwuTSF2dekLbNy9L3nR6DTdTIo9f3wlJZn1iztqp/crwhopcC5MvnsaLgWTZPa3nGPc yHFFIkrpZ8I9v7tnKPmZa7su8IPIBipjlymOfCv20LyoSYuDYyH2OyUQPFeDr8XyacI8 6reQ== 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 a21-20020a1709066d5500b00730a1a86524si3406961ejt.112.2022.08.03.07.00.08; Wed, 03 Aug 2022 07:00:09 -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 8EFA668B906; Wed, 3 Aug 2022 16:59:09 +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 E8D7D68B7EB for ; Wed, 3 Aug 2022 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0387324017E for ; Wed, 3 Aug 2022 15:59:02 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0WAp0JOHfEUj for ; Wed, 3 Aug 2022 15:59:01 +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 00F5C240590 for ; Wed, 3 Aug 2022 15:58:55 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 55B423A0A45; Wed, 3 Aug 2022 15:58:52 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:44 +0200 Message-Id: <20220803135844.16662-25-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg: move handling corrupt packets to the input thread 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: s1gMDyW11Anx --- fftools/ffmpeg.c | 7 ------- fftools/ffmpeg_demux.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index a9eda3c33e..09a4d20028 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3729,13 +3729,6 @@ static int process_input(int file_index) if (ist->discard) goto discard_packet; - if (pkt->flags & AV_PKT_FLAG_CORRUPT) { - av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, - "%s: corrupt input packet in stream %d\n", is->url, pkt->stream_index); - if (exit_on_error) - exit_program(1); - } - if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index af54ea3de1..097a6e3d1d 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -165,6 +165,17 @@ static void *input_thread(void *arg) continue; } + if (pkt->flags & AV_PKT_FLAG_CORRUPT) { + av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, + "%s: corrupt input packet in stream %d\n", + f->ctx->url, pkt->stream_index); + if (exit_on_error) { + av_packet_unref(pkt); + ret = AVERROR_INVALIDDATA; + break; + } + } + msg.pkt = av_packet_alloc(); if (!msg.pkt) { av_packet_unref(pkt);