From patchwork Tue May 23 13:58:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41796 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600358pzb; Tue, 23 May 2023 06:59:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5irZbuNMgN9KeUP/H0R5f1x1OP4DPFiHBPRF2RZFOUQdxgolrUZHbq6FnfjLD9fY7UmBx2 X-Received: by 2002:a05:6402:2ce:b0:50b:c4fb:770f with SMTP id b14-20020a05640202ce00b0050bc4fb770fmr11287814edx.34.1684850373937; Tue, 23 May 2023 06:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850373; cv=none; d=google.com; s=arc-20160816; b=Lf+3sHWV4QbmS4KYS1O+4yf/a/EJiNn4ISBl0vDz0qUR4qcge1ONFg0e90IgYN2lNo qLnUbE3AAsDRyrrg3lXsxundcTJrSp//sW6eEYnVm3YIsJ1n/dkWiywFiStSleMIjVMn TJoCuAejsNpw6VuEAnMUaGt/g2it+LLt8zahcyzo574+A2XjPcoPMjWTZ3qG+lo/7Vbh Vdc26SVeJmWznDMfbItaQZ/9a+xuZ3EzsiDo+oEFh5Cao8+PUxM0tHnwpDMaE3AjIoI/ vSAxyxNhTUGS7wgrQV6dsQvSOAil2Kj5ybmKgBPNWMo4yejdWxqrlqYUSJgecGhpTN3U gBcA== 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=0SUijrIXTnGHlerIU7yMLVbbSN63gIDTQw7j3sXYWBw=; b=I4AbFg9MMdmPy63T5iMTNVT19de9FeHRgxIStR/hfyr5DCA4D4IbvuwUXkXbMHvlBA ZcAQKmDKcvaMCjNjbH9vpEX1YdtR+00zFaGa36H6NxWTis3N1F3IXYwotzve2VRqLmd2 iygAow/4jBiUu2uhE+d1QMftduZwcrMhn1UT/hGEGOtcBQqEFqIQDu1xvCSZfyxSqTDq VHQ43mNMLGAqMU1RC6wuwQPYse+jbNtriKG6sRh+3h+l6C+EEpkatt466FctjEfCz8Qu I3FHcbFlj2frWl3kqNALbVAz3DaP7UZjpZVDfFcEKNFamQp9wv+I2BWWUgnVQkwSJD/O 2ZCw== 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 o13-20020aa7c50d000000b0050e068438b3si6370623edq.531.2023.05.23.06.59.33; Tue, 23 May 2023 06:59: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 4CF9868C0CB; Tue, 23 May 2023 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 4A31268C023 for ; Tue, 23 May 2023 16:58:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CEC4B2404EC for ; Tue, 23 May 2023 15:58:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id jgDI9RnacQyL for ; Tue, 23 May 2023 15:58:48 +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 5E6FD240177 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 20E683A031B for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:28 +0200 Message-Id: <20230523135842.20388-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/15] fftools/ffmpeg_hw: move hw_device_setup_for_decode() to ffmpeg_dec 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: R4J3BOWKGyAH This function is entangled with decoder setup, so it is more decoding code rather than ffmpeg_hw code. This will allow making more decoder state private in the future. --- fftools/ffmpeg.h | 5 +- fftools/ffmpeg_dec.c | 145 ++++++++++++++++++++++++++++++++++++++++ fftools/ffmpeg_hw.c | 153 ++----------------------------------------- 3 files changed, 153 insertions(+), 150 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 45be3b1823..895edbd6d6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -795,10 +795,13 @@ void enc_stats_write(OutputStream *ost, EncStats *es, uint64_t frame_num); HWDevice *hw_device_get_by_name(const char *name); +HWDevice *hw_device_get_by_type(enum AVHWDeviceType type); int hw_device_init_from_string(const char *arg, HWDevice **dev); +int hw_device_init_from_type(enum AVHWDeviceType type, + const char *device, + HWDevice **dev_out); void hw_device_free_all(void); -int hw_device_setup_for_decode(InputStream *ist); int hw_device_setup_for_encode(OutputStream *ost); /** * Get a hardware device to be used with this filtergraph. diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index e06747d9c4..0a470c4854 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -528,6 +528,151 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat return *p; } +static HWDevice *hw_device_match_by_codec(const AVCodec *codec) +{ + const AVCodecHWConfig *config; + HWDevice *dev; + int i; + for (i = 0;; i++) { + config = avcodec_get_hw_config(codec, i); + if (!config) + return NULL; + if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)) + continue; + dev = hw_device_get_by_type(config->device_type); + if (dev) + return dev; + } +} + +static int hw_device_setup_for_decode(InputStream *ist) +{ + const AVCodecHWConfig *config; + enum AVHWDeviceType type; + HWDevice *dev = NULL; + int err, auto_device = 0; + + if (ist->hwaccel_device) { + dev = hw_device_get_by_name(ist->hwaccel_device); + if (!dev) { + if (ist->hwaccel_id == HWACCEL_AUTO) { + auto_device = 1; + } else if (ist->hwaccel_id == HWACCEL_GENERIC) { + type = ist->hwaccel_device_type; + err = hw_device_init_from_type(type, ist->hwaccel_device, + &dev); + } else { + // This will be dealt with by API-specific initialisation + // (using hwaccel_device), so nothing further needed here. + return 0; + } + } else { + if (ist->hwaccel_id == HWACCEL_AUTO) { + ist->hwaccel_device_type = dev->type; + } else if (ist->hwaccel_device_type != dev->type) { + 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), + av_hwdevice_get_type_name(ist->hwaccel_device_type)); + return AVERROR(EINVAL); + } + } + } else { + if (ist->hwaccel_id == HWACCEL_AUTO) { + auto_device = 1; + } else if (ist->hwaccel_id == HWACCEL_GENERIC) { + type = ist->hwaccel_device_type; + dev = hw_device_get_by_type(type); + + // When "-qsv_device device" is used, an internal QSV device named + // as "__qsv_device" is created. Another QSV device is created too + // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices + // if both "-qsv_device device" and "-init_hw_device qsv=name:device" + // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL. + // To keep back-compatibility with the removed ad-hoc libmfx setup code, + // call hw_device_get_by_name("__qsv_device") to select the internal QSV + // device. + if (!dev && type == AV_HWDEVICE_TYPE_QSV) + dev = hw_device_get_by_name("__qsv_device"); + + if (!dev) + err = hw_device_init_from_type(type, NULL, &dev); + } else { + dev = hw_device_match_by_codec(ist->dec); + if (!dev) { + // No device for this codec, but not using generic hwaccel + // and therefore may well not need one - ignore. + return 0; + } + } + } + + if (auto_device) { + int i; + if (!avcodec_get_hw_config(ist->dec, 0)) { + // Decoder does not support any hardware devices. + return 0; + } + for (i = 0; !dev; i++) { + config = avcodec_get_hw_config(ist->dec, i); + if (!config) + break; + type = config->device_type; + dev = hw_device_get_by_type(type); + if (dev) { + av_log(NULL, AV_LOG_INFO, "Using auto " + "hwaccel type %s with existing device %s.\n", + av_hwdevice_get_type_name(type), dev->name); + } + } + for (i = 0; !dev; i++) { + config = avcodec_get_hw_config(ist->dec, i); + if (!config) + break; + type = config->device_type; + // Try to make a new device of this type. + err = hw_device_init_from_type(type, ist->hwaccel_device, + &dev); + if (err < 0) { + // Can't make a device of this type. + continue; + } + if (ist->hwaccel_device) { + 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(NULL, AV_LOG_INFO, "Using auto " + "hwaccel type %s with new default device.\n", + av_hwdevice_get_type_name(type)); + } + } + if (dev) { + ist->hwaccel_device_type = type; + } else { + av_log(NULL, AV_LOG_INFO, "Auto hwaccel " + "disabled: no device found.\n"); + ist->hwaccel_id = HWACCEL_NONE; + return 0; + } + } + + if (!dev) { + 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; + } + + ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); + if (!ist->dec_ctx->hw_device_ctx) + return AVERROR(ENOMEM); + + return 0; +} + int dec_open(InputStream *ist) { const AVCodec *codec = ist->dec; diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index e67145211c..d28257a1d6 100644 --- a/fftools/ffmpeg_hw.c +++ b/fftools/ffmpeg_hw.c @@ -27,7 +27,7 @@ static int nb_hw_devices; static HWDevice **hw_devices; -static HWDevice *hw_device_get_by_type(enum AVHWDeviceType type) +HWDevice *hw_device_get_by_type(enum AVHWDeviceType type) { HWDevice *found = NULL; int i; @@ -242,9 +242,9 @@ fail: goto done; } -static int hw_device_init_from_type(enum AVHWDeviceType type, - const char *device, - HWDevice **dev_out) +int hw_device_init_from_type(enum AVHWDeviceType type, + const char *device, + HWDevice **dev_out) { AVBufferRef *device_ref = NULL; HWDevice *dev; @@ -297,151 +297,6 @@ void hw_device_free_all(void) nb_hw_devices = 0; } -static HWDevice *hw_device_match_by_codec(const AVCodec *codec) -{ - const AVCodecHWConfig *config; - HWDevice *dev; - int i; - for (i = 0;; i++) { - config = avcodec_get_hw_config(codec, i); - if (!config) - return NULL; - if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)) - continue; - dev = hw_device_get_by_type(config->device_type); - if (dev) - return dev; - } -} - -int hw_device_setup_for_decode(InputStream *ist) -{ - const AVCodecHWConfig *config; - enum AVHWDeviceType type; - HWDevice *dev = NULL; - int err, auto_device = 0; - - if (ist->hwaccel_device) { - dev = hw_device_get_by_name(ist->hwaccel_device); - if (!dev) { - if (ist->hwaccel_id == HWACCEL_AUTO) { - auto_device = 1; - } else if (ist->hwaccel_id == HWACCEL_GENERIC) { - type = ist->hwaccel_device_type; - err = hw_device_init_from_type(type, ist->hwaccel_device, - &dev); - } else { - // This will be dealt with by API-specific initialisation - // (using hwaccel_device), so nothing further needed here. - return 0; - } - } else { - if (ist->hwaccel_id == HWACCEL_AUTO) { - ist->hwaccel_device_type = dev->type; - } else if (ist->hwaccel_device_type != dev->type) { - 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), - av_hwdevice_get_type_name(ist->hwaccel_device_type)); - return AVERROR(EINVAL); - } - } - } else { - if (ist->hwaccel_id == HWACCEL_AUTO) { - auto_device = 1; - } else if (ist->hwaccel_id == HWACCEL_GENERIC) { - type = ist->hwaccel_device_type; - dev = hw_device_get_by_type(type); - - // When "-qsv_device device" is used, an internal QSV device named - // as "__qsv_device" is created. Another QSV device is created too - // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices - // if both "-qsv_device device" and "-init_hw_device qsv=name:device" - // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL. - // To keep back-compatibility with the removed ad-hoc libmfx setup code, - // call hw_device_get_by_name("__qsv_device") to select the internal QSV - // device. - if (!dev && type == AV_HWDEVICE_TYPE_QSV) - dev = hw_device_get_by_name("__qsv_device"); - - if (!dev) - err = hw_device_init_from_type(type, NULL, &dev); - } else { - dev = hw_device_match_by_codec(ist->dec); - if (!dev) { - // No device for this codec, but not using generic hwaccel - // and therefore may well not need one - ignore. - return 0; - } - } - } - - if (auto_device) { - int i; - if (!avcodec_get_hw_config(ist->dec, 0)) { - // Decoder does not support any hardware devices. - return 0; - } - for (i = 0; !dev; i++) { - config = avcodec_get_hw_config(ist->dec, i); - if (!config) - break; - type = config->device_type; - dev = hw_device_get_by_type(type); - if (dev) { - av_log(NULL, AV_LOG_INFO, "Using auto " - "hwaccel type %s with existing device %s.\n", - av_hwdevice_get_type_name(type), dev->name); - } - } - for (i = 0; !dev; i++) { - config = avcodec_get_hw_config(ist->dec, i); - if (!config) - break; - type = config->device_type; - // Try to make a new device of this type. - err = hw_device_init_from_type(type, ist->hwaccel_device, - &dev); - if (err < 0) { - // Can't make a device of this type. - continue; - } - if (ist->hwaccel_device) { - 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(NULL, AV_LOG_INFO, "Using auto " - "hwaccel type %s with new default device.\n", - av_hwdevice_get_type_name(type)); - } - } - if (dev) { - ist->hwaccel_device_type = type; - } else { - av_log(NULL, AV_LOG_INFO, "Auto hwaccel " - "disabled: no device found.\n"); - ist->hwaccel_id = HWACCEL_NONE; - return 0; - } - } - - if (!dev) { - 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; - } - - ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); - if (!ist->dec_ctx->hw_device_ctx) - return AVERROR(ENOMEM); - - return 0; -} - int hw_device_setup_for_encode(OutputStream *ost) { const AVCodecHWConfig *config; From patchwork Tue May 23 13:58:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41794 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600113pzb; Tue, 23 May 2023 06:59:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MvoG8TOD5Nu86KUW/I1xw6jUP1SpAWB9fE+L5Q1Z/362BLSD4oDzi8O3ZPRG038clKYeS X-Received: by 2002:a17:906:b044:b0:96f:4927:7a96 with SMTP id bj4-20020a170906b04400b0096f49277a96mr12054853ejb.70.1684850349481; Tue, 23 May 2023 06:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850349; cv=none; d=google.com; s=arc-20160816; b=VI7yNoXFcmlMGJg1WOLg1iTpgW6MIfRVH10EJC/jPEKQyXbNq0iH/fQNZ+dbmB6T9Z k3dSDtLYS8Qc4EPdM3J4Fl3xsojTfKwDgeCejr+aOXCXiSj4WFWJh1s7/toFTWUIiMz4 gOUzYa0DhQp+wtym+6b2J9NSe+norWlifiRaDbgSAwVdnEvpQWcUAQC+r3OL4h1XQx98 Pmoq/lit88beQIPvfpAjGDJ1D+PFHUS2s9n5xhPjnrDTsECdVEmbEDMbq4oXryzPUMHR bfIa4MDeK9j+l0S4LxBai7OtAIhYXSnZ2Gp+VejcITNJaKqtLwDQ5+gECk55gOYGQsYY 0wOg== 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=h7+4InNIcEdRUBMXId6xfER9pMTdFvLhkXLlEGMRHFw=; b=Psgdnu3FxQPFX8FJ14RaRnM0xs1he1kJzuR3YsM8saiaMo3AVU3i3tx84hZAdHOO7Z HQDD9E1JcKMak0+LnQLfH1zxIOh3S28TXkewVQinWHXHT15M8yvfwr6Ip+gT1vY9Tmdh VOrqhIYAZb9lUI1ps9m8k+k/FS49dHxKQ5UoOZEgdlR+TuHzEXV3nE1LB8OY5S3dygy7 bWIdUvYqVxwAQWZGo4O1qRVVa638F+MDjvzsUK1y+Bgy3MeRTqXFKiK0MIko8ZIKAfH8 hk9oJUdPAhofXWhPoECJbnkAe3BE/xc+nqGLhPRVG6JRObaOq1/WhP/vHwpQKATtRF04 SbjA== 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 n21-20020a170906841500b00965a718330esi5580405ejx.164.2023.05.23.06.59.08; Tue, 23 May 2023 06:59: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 C326668C0A7; Tue, 23 May 2023 16:59:03 +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 DD0EA68BF99 for ; Tue, 23 May 2023 16:58:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 910572406D0 for ; Tue, 23 May 2023 15:58:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id YjbFHjiqKrVj for ; Tue, 23 May 2023 15:58:48 +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 6929E2404EC for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2DAD23A048F for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:29 +0200 Message-Id: <20230523135842.20388-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/15] fftools/ffmpeg_hw: move hw_device_setup_for_encode() to ffmpeg_enc 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: +oIHRXdWZyBC This function is entangled with encoder setup, so it is more encoding code rather than ffmpeg_hw code. This will allow making more encoder state private in the future. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_enc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ fftools/ffmpeg_hw.c | 55 -------------------------------------------- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 895edbd6d6..927e402f7c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -802,7 +802,6 @@ int hw_device_init_from_type(enum AVHWDeviceType type, HWDevice **dev_out); void hw_device_free_all(void); -int hw_device_setup_for_encode(OutputStream *ost); /** * Get a hardware device to be used with this filtergraph. * The returned reference is owned by the callee, the caller diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 9b81d14922..7d99d9270b 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -103,6 +103,61 @@ fail: return AVERROR(ENOMEM); } +static int hw_device_setup_for_encode(OutputStream *ost) +{ + const AVCodecHWConfig *config; + HWDevice *dev = NULL; + AVBufferRef *frames_ref = NULL; + int i; + + if (ost->filter) { + frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter); + if (frames_ref && + ((AVHWFramesContext*)frames_ref->data)->format == + ost->enc_ctx->pix_fmt) { + // Matching format, will try to use hw_frames_ctx. + } else { + frames_ref = NULL; + } + } + + for (i = 0;; i++) { + config = avcodec_get_hw_config(ost->enc_ctx->codec, i); + if (!config) + break; + + if (frames_ref && + config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX && + (config->pix_fmt == AV_PIX_FMT_NONE || + config->pix_fmt == ost->enc_ctx->pix_fmt)) { + av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input " + "frames context (format %s) with %s encoder.\n", + av_get_pix_fmt_name(ost->enc_ctx->pix_fmt), + ost->enc_ctx->codec->name); + ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref); + if (!ost->enc_ctx->hw_frames_ctx) + return AVERROR(ENOMEM); + return 0; + } + + if (!dev && + config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) + dev = hw_device_get_by_type(config->device_type); + } + + if (dev) { + av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using device %s " + "(type %s) with %s encoder.\n", dev->name, + av_hwdevice_get_type_name(dev->type), ost->enc_ctx->codec->name); + ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); + if (!ost->enc_ctx->hw_device_ctx) + return AVERROR(ENOMEM); + } else { + // No device required, or no device available. + } + return 0; +} + static void set_encoder_id(OutputFile *of, OutputStream *ost) { const char *cname = ost->enc_ctx->codec->name; diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index d28257a1d6..4a0b346fe1 100644 --- a/fftools/ffmpeg_hw.c +++ b/fftools/ffmpeg_hw.c @@ -297,61 +297,6 @@ void hw_device_free_all(void) nb_hw_devices = 0; } -int hw_device_setup_for_encode(OutputStream *ost) -{ - const AVCodecHWConfig *config; - HWDevice *dev = NULL; - AVBufferRef *frames_ref = NULL; - int i; - - if (ost->filter) { - frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter); - if (frames_ref && - ((AVHWFramesContext*)frames_ref->data)->format == - ost->enc_ctx->pix_fmt) { - // Matching format, will try to use hw_frames_ctx. - } else { - frames_ref = NULL; - } - } - - for (i = 0;; i++) { - config = avcodec_get_hw_config(ost->enc_ctx->codec, i); - if (!config) - break; - - if (frames_ref && - config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX && - (config->pix_fmt == AV_PIX_FMT_NONE || - config->pix_fmt == ost->enc_ctx->pix_fmt)) { - av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input " - "frames context (format %s) with %s encoder.\n", - av_get_pix_fmt_name(ost->enc_ctx->pix_fmt), - ost->enc_ctx->codec->name); - ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref); - if (!ost->enc_ctx->hw_frames_ctx) - return AVERROR(ENOMEM); - return 0; - } - - if (!dev && - config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) - dev = hw_device_get_by_type(config->device_type); - } - - if (dev) { - av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using device %s " - "(type %s) with %s encoder.\n", dev->name, - av_hwdevice_get_type_name(dev->type), ost->enc_ctx->codec->name); - ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); - if (!ost->enc_ctx->hw_device_ctx) - return AVERROR(ENOMEM); - } else { - // No device required, or no device available. - } - return 0; -} - static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input) { InputStream *ist = avctx->opaque; From patchwork Tue May 23 13:58:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41797 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600434pzb; Tue, 23 May 2023 06:59:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TL1FbvmKUuT7atL2ljD5yHDGy3foHy2+PxP/1S2kk7xqE+u+rmEMmpyzbj4HEnW10lf07 X-Received: by 2002:a17:907:970c:b0:96b:e92:4feb with SMTP id jg12-20020a170907970c00b0096b0e924febmr15646756ejc.60.1684850383692; Tue, 23 May 2023 06:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850383; cv=none; d=google.com; s=arc-20160816; b=lUuC6wyzhcJrueBmgfRUyB0EYXhKNx74NUoV4RJgmJ4XnlkwyoF+P+S8vLvdxdsHvu P5It1SiRlrfWqpRl/VC+kyMq8DrW5zTNhFXaAdzZGcnwR/OGh08FuxMO4A8SQs4XTGHO Z6mBSoUq7X5qYbpOywbxmW4AOlnk5YqY5JMmfz2tSAopHSwxvpYd4kuBDyf82/vyfPJ7 zu2qiqzJjyMuZZN4W8E3jGeM2dgLc/Mvr4CNpPTAQJHEifetnO3buoBegqGhhjdm7gtE W+T27KbGbWV7DbjCY+Frr3oOUX/gJZ3GTbihAMpYeR8pphqkMdAcdseAh/N4s8DdMUjE xm0w== 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=PMrVQKjOcBvYxczqjfDDsmG06v/O4V1FAuADZlSKrRU=; b=q2YnS+pf01bRXNaA3U9XINgfouW2Jk9WLTTYGb0hiKj1doueJflKc5/RblEbuWf+17 VXcUWrzgVCd1u+tN7qNuCs/tzcMfRUU3r/ccJGxyMpetUfv1om/p+DjtcrqqGU29V4Iy gnridB9N2KKViBU+oUjV2M3D4w2RVmHD7foLuUEHbN2JExq0H2S6fevwgtroJYjqft5Z 6Cg16nfWAm3DOKkK/QMt+CT+Uued/rHLgOjGy1CrwI0RcNPUbbJUonfcLfg96RE7Ki3X Ad+o7qHn3+rQow0hew0t379eIKN9lfocYVo3CJUudUTaMsfbLuxAoSaN4u6zXtXa/+iM //0w== 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 ba30-20020a0564021ade00b0050bc3b4200csi856618edb.291.2023.05.23.06.59.43; Tue, 23 May 2023 06:59:43 -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 4D44C68C0F4; Tue, 23 May 2023 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 9959A68C030 for ; Tue, 23 May 2023 16:58:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5D36A2404EE for ; Tue, 23 May 2023 15:58:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6RWKEhWvRuU6 for ; Tue, 23 May 2023 15:58:49 +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 746692404F5 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 38D173A11B4 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:30 +0200 Message-Id: <20230523135842.20388-3-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/15] fftools/ffmpeg_enc: use AVFrame.hw_frames_ctx for encoder hw setup 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: d22qwv8BNmX8 It should be the same as the one that can be extracted from the filter and does not require access to outside data. --- fftools/ffmpeg_enc.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 7d99d9270b..59e9466420 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -103,22 +103,18 @@ fail: return AVERROR(ENOMEM); } -static int hw_device_setup_for_encode(OutputStream *ost) +static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref) { const AVCodecHWConfig *config; HWDevice *dev = NULL; - AVBufferRef *frames_ref = NULL; int i; - if (ost->filter) { - frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter); - if (frames_ref && - ((AVHWFramesContext*)frames_ref->data)->format == - ost->enc_ctx->pix_fmt) { - // Matching format, will try to use hw_frames_ctx. - } else { - frames_ref = NULL; - } + if (frames_ref && + ((AVHWFramesContext*)frames_ref->data)->format == + ost->enc_ctx->pix_fmt) { + // Matching format, will try to use hw_frames_ctx. + } else { + frames_ref = NULL; } for (i = 0;; i++) { @@ -388,7 +384,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) av_dict_set(&ost->encoder_opts, "flags", "+frame_duration", AV_DICT_MULTIKEY); - ret = hw_device_setup_for_encode(ost); + ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Encoding hardware device setup failed: %s\n", av_err2str(ret)); From patchwork Tue May 23 13:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41799 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600690pzb; Tue, 23 May 2023 07:00:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Td3S6AppHE9gKZ0fFIVoUekfEnq8pcC6DfGN8nQb9MDQhrZZl2UYRhH0e4xtAFSdGapCi X-Received: by 2002:a50:ed8d:0:b0:510:55a3:97ad with SMTP id h13-20020a50ed8d000000b0051055a397admr11200122edr.0.1684850406500; Tue, 23 May 2023 07:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850406; cv=none; d=google.com; s=arc-20160816; b=cXu8yeIz2/12sN1tq0hAcHmP3IAZ0ryi4CyyqF9i8IOCILCKwwBmDm+YscPQmtzI3I grnZs/tsNRwJO7w5ZAtN0X4aJgfEhWezap2uazRreR90/AS6Cqk8C21gLfMNuxL9wZf/ SYi8QvopPI6uVnfH1UGd+dfevLBaB5K7o4Vn+dWt47Ez5GmXfnOyP+R4csDCibPbJ4hm tafAc3Btt5zhLbdh0fRaIBceGZ7mZjLdzttL3U2OqawznFYAFdL/Jl0u5tIE6NLLH9cv 9VF3yrWDyNEQd7sR6mnjXek2sbOysAI/n1KRnVn8sLhAtMzlIM7CFgFtzBHTOuQdVjJY hDZQ== 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=+e6H0XDh3QBcTTVpZUPJJfCgnY+4/SJ7oh3TM9OyaBw=; b=W1uZffW6KzC0eW+NIElqIUBhrBncfbQYo55MqoMSJsymMT2j9cd2uofAwEFEdL1z/n 8TktyVY3v0QKN5fa9D8EZljt0Y5KUwIYna9lQJuofT2aKP13q+FknGjORCKXYPaxd20/ AC3IirPqEz3M0FSBsMNyO8fQLJ8jw0jEB/oS/PuLpZ6SNCjate7WuFPCx9NIqNCBLmqk IKwun8NLiWIniAi/ueaAEJ6qjj40DoXle1K2gl+jXmWn1WK6VTorb8drCeGW1pfAzAov aJSFozsaif0q8VJ9rRWDEsdVktoPMtz3L1RMXkrYGGz2P7uHniLBv1VMQgaL9dFc6FKO jGfA== 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 n22-20020a056402515600b0050bca43049fsi500883edd.350.2023.05.23.07.00.05; Tue, 23 May 2023 07:00:06 -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 7D4EF68C140; Tue, 23 May 2023 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 B791568C104 for ; Tue, 23 May 2023 16:59:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CD25F2404F8 for ; Tue, 23 May 2023 15:58:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vfy7ZjblJYxg for ; Tue, 23 May 2023 15:58:50 +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 780D3240591 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 448E73A11DB for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:31 +0200 Message-Id: <20230523135842.20388-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/15] fftools/ffmpeg: fail earlier on text/bitmap subtitles mismatch 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: GRBi4uBMAjBc Checking whether the user requested an unsupported conversion between text and bitmap subtitles can be done immediately when creating the output stream. --- fftools/ffmpeg_enc.c | 18 ------------------ fftools/ffmpeg_mux_init.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 59e9466420..f023657a07 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -345,24 +345,6 @@ int enc_open(OutputStream *ost, AVFrame *frame) dec_ctx->subtitle_header_size); enc_ctx->subtitle_header_size = dec_ctx->subtitle_header_size; } - if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && - enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { - int input_props = 0, output_props = 0; - AVCodecDescriptor const *input_descriptor = - avcodec_descriptor_get(ist->dec->id); - AVCodecDescriptor const *output_descriptor = - avcodec_descriptor_get(enc_ctx->codec_id); - if (input_descriptor) - input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); - if (output_descriptor) - output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); - if (input_props && output_props && input_props != output_props) { - av_log(ost, AV_LOG_ERROR, - "Subtitle encoding currently only possible from text to text " - "or bitmap to bitmap"); - return AVERROR_INVALIDDATA; - } - } break; default: diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b73791acee..56f9d1215c 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -822,6 +822,13 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx) { AVCodecContext *subtitle_enc = ost->enc_ctx; + + AVCodecDescriptor const *input_descriptor = + avcodec_descriptor_get(ost->ist->par->codec_id); + AVCodecDescriptor const *output_descriptor = + avcodec_descriptor_get(subtitle_enc->codec_id); + int input_props = 0, output_props = 0; + char *frame_size = NULL; MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, mux->fc, st); @@ -829,6 +836,16 @@ static void new_stream_subtitle(Muxer *mux, const OptionsContext *o, av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size); exit_program(1); } + if (input_descriptor) + input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); + if (output_descriptor) + output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB); + if (input_props && output_props && input_props != output_props) { + av_log(ost, AV_LOG_ERROR, + "Subtitle encoding currently only possible from text to text " + "or bitmap to bitmap\n"); + exit_program(1); + } } } From patchwork Tue May 23 13:58:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41801 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp601020pzb; Tue, 23 May 2023 07:00:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7t630jKnQcWnwZ53pE4SD+n+I5qSq2jNHrNRQEbeAqSuINxYvd8MgqeAKZvqdvuckTrp3v X-Received: by 2002:aa7:d58d:0:b0:510:f1dc:86c0 with SMTP id r13-20020aa7d58d000000b00510f1dc86c0mr12375352edq.32.1684850429046; Tue, 23 May 2023 07:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850429; cv=none; d=google.com; s=arc-20160816; b=ooEA5wrHgZfhCjguDPo1MNDJUo5Ho87cdtw8xcl63vqg/j33aPckFZfnnKZG8loFGU jC1tnnV3NqRGzJEVymXdZMJQ1jCmz0LM0v4VLuhZciubtrWEASQX9+5NejxwOF/52rSF pTOaHbBMlMaNUsH7LtXPCM1T0bJv0ChRs1Xg7EmuvTN+Ei8VmmDfEz+K1D2hE1Jq6uBF c9vR3Z2iQzUm9nBrJwDQMQyOYoJEx2Xgw+c6+UvJMMldLX7FaFNABWsa//37uX8maTnt rgZCU8bWgPBFbwie1u7R4LZAH+2FhyK2EoRGd//rUyGBUFho7RKSIhSR1nOZsMUIpMqL q0Jw== 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=18rqVDmmLotwyIfk6fzy92sI9W+Maek48sZa3fFUFXQ=; b=S+W1NJNOS9XNridTqePm/TG/ClbFtHbjRxDfVmsW+bDJ5PAEsZw9tldX85Bt8djlU5 VWqwuE+zqI8JzhJQTeyhjwiYenhw+V/YikaeKmbxYIH7HKGvmHk4sMwFubKQ+d49P+vA U6LoWmjG4TGtIiKWcyq1HvA0AWNkAD7Vhlydn9zcvkVULF+8t3iXPScwYZTUxuJlWVu3 VZ1wcb/NoXhkz749jDCkeTUFN9Jdt4smWa1COOUFdnY8/mQZy1lZn/sYtmTumlls3YWS 7XvDjgDpRrF0Rt4chPYr8U600t3mOZOFkI/5VWoS6/Shxgq1WKwxhtOWIOzrmViN6Y8Y r5jA== 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 m25-20020aa7c499000000b00510da860d88si4737204edq.587.2023.05.23.07.00.28; Tue, 23 May 2023 07:00: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 C727C68C121; Tue, 23 May 2023 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 049F968C110 for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 97157240591 for ; Tue, 23 May 2023 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 ij-XmmL-JK0F for ; Tue, 23 May 2023 15:58:51 +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 813E92405EC for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 50FF33A1251 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:32 +0200 Message-Id: <20230523135842.20388-5-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/15] fftools/ffmpeg: drop outdated comments 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: XPuVIez7j/1p --- fftools/ffmpeg.c | 1 - fftools/ffmpeg_demux.c | 1 - 2 files changed, 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c70d38755b..1fc13b3e29 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1431,7 +1431,6 @@ int main(int argc, char **argv) exit_program(1); } - /* file converter / grab */ if (nb_output_files <= 0) { av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n"); exit_program(1); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 401ae1f850..7318abc6d9 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1569,7 +1569,6 @@ int ifile_open(const OptionsContext *o, const char *filename) d->thread_queue_size = o->thread_queue_size; - /* update the current parameters so that they match the one of the input stream */ add_input_streams(o, d); /* dump the file content */ From patchwork Tue May 23 13:58:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41795 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600256pzb; Tue, 23 May 2023 06:59:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iM2x4Mmyg3F9ChPluBf6rEBrchQXWhUO97W+IMsD+eW//GtcTAS4DEvoQNarjs2F2ptI6 X-Received: by 2002:a17:907:6287:b0:965:d18b:f03a with SMTP id nd7-20020a170907628700b00965d18bf03amr14038063ejc.58.1684850363056; Tue, 23 May 2023 06:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850363; cv=none; d=google.com; s=arc-20160816; b=vLlRLihVJsNRN9ihTwNo2FZtDTykWEHuuHf5dh1R0yCiDGaicAhebuBRY7SgIKQVi/ SlF3vmoiqqyYv5/oPdj/Wu9dNp03uUAC6MC/GHTJp9U9sLfat//0j59VhP2iiUmlvdQ1 18wbhoRZuueO4vL+5c/MKODhbmsLZB+oRA57j3sNUVsnq/Zw3o5QOhIbfW557krecjyA c4ARdOsgVY8HGP687UTPz7aS/Li393WfaDHlDZMwvYhe7AER5/uP4jxM5xzTjJjHdWLo KHT2iIqyh9f749S9xlSHzqMkzPhcuzSdOfyuoRQLttbSmebunUUULA/5f3ZA3oKqSJlS Aleg== 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=6YGU1zF5GORGE77RYd1NWN0LLJ+gc14olIjaA+43HIY=; b=McS8NsyFJT/T8xIjCrOcGfpGh1IARoedDhjNPOFnyROUN3WrNs+mxoFnLfkvcP4hO3 YY6KeqerWwhuzMslyIfxaJQeMcZ/CP3+dpIvAzzj6UsMHTbw+PrjbzyjJ850z1ZSlYq2 W20Ky0Lph3XCEyQDk2I+QRsSkftBT4pJ3HtR0CjLyit9RUWc8rZ/kXVeq/Q3UgWSCWl1 HzrFpN4qey5APk0aODx/jFpz8MEJQLEdcmMXJyZq6uMlaL6P31G5mRMQPTreeDVrHji8 nMmBF5ZEU74kSp/93f86bO+H7iljz9YUdQxLOh5PcArFEVvn38TPDHQAVQ39lhl2otAi GEmA== 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 h22-20020a170906829600b00965f171543esi6007147ejx.148.2023.05.23.06.59.22; Tue, 23 May 2023 06:59: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 13B0F68C030; Tue, 23 May 2023 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 42D6768BFFE for ; Tue, 23 May 2023 16:58:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0566D240177 for ; Tue, 23 May 2023 15:58:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 9xy3FBnzVbjh for ; Tue, 23 May 2023 15:58:49 +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 7060C2404EE for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5BD0C3A1267 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:33 +0200 Message-Id: <20230523135842.20388-6-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/15] fftools/ffmpeg_demux: only print demuxing stats if demuxing actually started 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: ih5+qgDymr3g If the transcoding process never got to reading any packets from this input then printing stats is just pointless noise. --- fftools/ffmpeg_demux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 7318abc6d9..ed8d5d165a 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -113,6 +113,8 @@ typedef struct Demuxer { int thread_queue_size; pthread_t thread; int non_blocking; + + int read_started; } Demuxer; typedef struct DemuxMsg { @@ -734,6 +736,8 @@ static int thread_start(Demuxer *d) goto fail; } + d->read_started = 1; + return 0; fail: av_thread_message_queue_free(&d->in_thread_queue); @@ -833,7 +837,7 @@ void ifile_close(InputFile **pf) thread_stop(d); - if (f->ctx) + if (d->read_started) demux_final_stats(d); for (int i = 0; i < f->nb_streams; i++) From patchwork Tue May 23 13:58:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41798 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600524pzb; Tue, 23 May 2023 06:59:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41sPDCdzS0o/g50sgcoRRjRFz0o0HLbPWLaL5NLNIPZtQ0468aTk5wstyfeXxb9vtg9yv9 X-Received: by 2002:a17:906:9b8b:b0:961:be96:b0e6 with SMTP id dd11-20020a1709069b8b00b00961be96b0e6mr14582438ejc.68.1684850394799; Tue, 23 May 2023 06:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850394; cv=none; d=google.com; s=arc-20160816; b=VeAMpunXo7Rvax8r1SC/RRt3CTTQ5tck1J2K8ojtFu97CubwKVfqAkMgoXUS6T1UaE izKY++PFmxILYwmSDeVmAtf5NnLVbARzfHELo83wg+BsJ1jfFptvG9JeIDXZa1yL5g4i XJ5UKD5vh9aJmNn1UdQ72U9ZcmMMWQiCGeoVcu9q2MYORDsn7b8rgFaouDbdpJ8gtTVR 1bfTPNFdH85epedD5qpYtjLVhiBTmFFXYC2WwhZwZM6N8SojuYktzfBrlrHvcoI+NXXO NhxVYa9+ro+v3V7AzTNFrINOOK8/ILprCNeNr7xMmS0aiLFY3/ZqqjHzxKVTOVin/XP2 59Ng== 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=usnkNXVpk2Z8CQ2pbTWF5rZ3mkcU+1hx+49fkyz4XyY=; b=YmlvK2Ysc/mmxCXzPP4heTTLrCLuBkgaJzLS/x9JysFaX6URMnxafjoVW+sdXmBY0E G3TtpPfIf3cxdOiMHhSsMxhb61u++UtJgqVJwXhUaiy24NY55okfgKW9vbgdjaQ+6/na 7nibPqNfnYlvXcbVqFDIeNgNRMZk2CTrhh8bm/Qiliu4KRKPMcKWtDbMLsZXf8JnPz0H PiseeKtPqGyMKVGm2o1m0eDE2kAf3tM7FRZ5bIEzUX/gOMgI89VXBbtHmS2yFt8HIEXs ZFJrje4gU4uxBB37xkcFvw0w03Q8ndYdFqEEZHcW4Mv+4Es7JlaF/qt5NDAqowpIJBaN Hbqw== 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 my2-20020a1709065a4200b0094f3b83a4bfsi774319ejc.177.2023.05.23.06.59.54; Tue, 23 May 2023 06:59: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 6903B68C105; Tue, 23 May 2023 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 BF73068C0BF for ; Tue, 23 May 2023 16:58:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4A35D2404F5 for ; Tue, 23 May 2023 15:58:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Zun1zoHD8DMF for ; Tue, 23 May 2023 15:58:50 +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 755942404F8 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 66AD63A1506 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:34 +0200 Message-Id: <20230523135842.20388-7-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/15] fftools/ffmpeg_demux: initialize nb_streams_warn 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: gK0DUSv66R22 Fixes spurious new-stream warnings for unused streams after 9429624a76107020b5911f8307f366fed386b336 --- fftools/ffmpeg_demux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index ed8d5d165a..bd267aa0ce 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1543,6 +1543,7 @@ int ifile_open(const OptionsContext *o, const char *filename) d->loop = o->loop; d->duration = 0; d->time_base = (AVRational){ 1, 1 }; + d->nb_streams_warn = ic->nb_streams; f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS); From patchwork Tue May 23 13:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41800 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp600885pzb; Tue, 23 May 2023 07:00:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RXtM83Ew5SV68jDJ3mmf3IhH9zNHaF2KxxOzLyD6cXzNxWbOseyperxYy8D92A4XVhwGz X-Received: by 2002:a17:906:4fd2:b0:94e:8431:4767 with SMTP id i18-20020a1709064fd200b0094e84314767mr13748313ejw.38.1684850419642; Tue, 23 May 2023 07:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850419; cv=none; d=google.com; s=arc-20160816; b=eudBCkLeMOyKG8kgc56MMRaQKH3YNgSqMWgLShZacPv2QEPr8GU5jC4Ywt7BUbkUjK eHfJCPZ6kiThYj1L5cJk6eqcr/Lw//1/Csc5gNHau+zvPg7Nr+h9IKb4vtllgAe/J/4L iDBYhTylb2W+L4oa5+iuA2JflnOcTNyM6YaVgpZzL7pF29AYrH1IU7o2FDt0SoGvkquL b0VOAYX//SZH5sfiAVbsXtxBOCvgWeRcKrm8tQZ5uvm8g3viG63Bq7UA2RryvnuAtto1 bGg7A8L1COFRoBm5rzUPnsDUoK8lrympU+gePbg3XOgBP4Q0djXkPo5txeC6QaaNWNpA O0HA== 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=j7bL7m8VLCkeEXcGa++xvd8YEMQig7KuqCOAnCyG48g=; b=Lh5fRmjCtVw9NSphUTbL96q+9qTndQ1hzMDk53eKMyO6S36dOpmdAtPaBMIIyRp2bE woYgRqEQpuENk/50qygW7KiAG8SAv8DIQxAfR8j+d4SZnBCJBh5zlK6ebxbtJKvhxaTs U7iwZm4v+prGlpEIxn6J2/YuoyHdDcY0WRqntQNBL8FvUZ0AJvRTtTdFAzLnbqNZ8WZL bWfNNTg+2wSSqPmvtLSF/g74Bhkj2hGLuitI0t68WW/X5WW8nO69lN71BPnNdEtuFBL5 cn+QqLqGD0NZdtmLn7kDW+IpDBepC/7DPu2Bf72W33XBCJ2/L8rjdWzTYsFVxIxqpfGy cxjw== 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 ti14-20020a170907c20e00b0096f7d567661si157217ejc.414.2023.05.23.07.00.17; Tue, 23 May 2023 07:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A34BC68C159; Tue, 23 May 2023 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 03A1068C090 for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2D6D12405EC for ; Tue, 23 May 2023 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 P8VYN2-DAZSA for ; Tue, 23 May 2023 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 7FFEE2405B5 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 723A83A031B for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:35 +0200 Message-Id: <20230523135842.20388-8-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/15] fftools/ffmpeg_demux: skip unused/attachment streams in final stats 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: W1b5nck+e9sn No useful information can be printed for them. --- fftools/ffmpeg_demux.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index bd267aa0ce..33322ac565 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -781,6 +781,9 @@ static void demux_final_stats(Demuxer *d) DemuxStream *ds = ds_from_ist(ist); enum AVMediaType type = ist->par->codec_type; + if (ist->discard || type == AVMEDIA_TYPE_ATTACHMENT) + continue; + total_size += ds->data_size; total_packets += ds->nb_packets; From patchwork Tue May 23 13:58:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41803 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp601377pzb; Tue, 23 May 2023 07:00:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6UraOnXxJVF2er0TJGh+5WO4eb+Fh7JLWuZVvxJYD1iut4nOPFq/8Sf4vch6n9v5hGtHuC X-Received: by 2002:a17:907:9620:b0:96f:87ae:49eb with SMTP id gb32-20020a170907962000b0096f87ae49ebmr13710740ejc.16.1684850451202; Tue, 23 May 2023 07:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850451; cv=none; d=google.com; s=arc-20160816; b=R0ZWZYVKhp5zFE7dwkYUpxSXSdzzL+IOZdFiIr4mLuR0BmrM/a1gO2CwztSBYbpKeb k/KDmFYeMnEPrRTf723zZBqolfEq8813MKD05HB0y8hrqWGKmfD49aEiEYTR/MP0GPDG eeo5NSSXmpPMcN3QvtxzPDKizYZQF3kB4TMD+kEzcYUAaRJ7xVwa+QRxnaoPWRTGxI72 2KRs999MkOMWbesdwle9UKvK/+k+veM/YEBnXkOcjrvPCIpUN2U/GABRlygRgDFN9hFh xV2/mqRYQeobnke7XLWwveRxH1P1xGnrl/UeQTRmUk9lkVIII06EeQ4lUlSRjcT8ymm8 9nGw== 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=VgnvZEqD6ZZm+JKOVkI8wR6FMQVrqM/aGLe324ISF4I=; b=B8zTv11Ku7X7aB08NFqx+mO8m7u+1RmAE2HCZ1l2Krfv1607YaDexS2l9z7L6wnVXZ hq8DFAHZ2xV+MUeg2MnQUe+dxKZ+fWJDvivBW2CVXaYksLaOqIHfBdgymfj8amFT3JTA MtbgDNTdHO5etEjNjZCJbcFRpeENbfOR7mb2tHLLEAvC7+5c1lYYRpEwRvNS78kiUg4m wAJpzGouN3XLTlHPp1eV2/veHf8hId1dIAj6Q6qD2cJBKbJra0Tf1M9vG8DP3qbWwkPI C/x33JVCpfYvThh+90cOWNgfcHPKoiTJ+eBiK0niyrwx3ovoljo0GIKrgj6cOnR5Qv1K tooA== 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 d24-20020aa7c1d8000000b00510de433475si5914508edp.635.2023.05.23.07.00.50; Tue, 23 May 2023 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 D5BD668C168; Tue, 23 May 2023 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 094BB68C0CD for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2A35C2406CA for ; Tue, 23 May 2023 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 ZdB3J6desXfK for ; Tue, 23 May 2023 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 8A88D2405F9 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7D0FC3A048F for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:36 +0200 Message-Id: <20230523135842.20388-9-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/15] fftools/ffmpeg_dec: add decoder private data 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: 72XL0YX2s3Ev Move InputStream.decoded_frame to it. Analogous to what has been previously done for all the other major components. --- fftools/ffmpeg.h | 5 ++++- fftools/ffmpeg_dec.c | 46 +++++++++++++++++++++++++++++++++++++++++- fftools/ffmpeg_demux.c | 7 ++----- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 927e402f7c..92e56ee80c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -324,6 +324,8 @@ typedef struct FilterGraph { int nb_outputs; } FilterGraph; +typedef struct Decoder Decoder; + typedef struct InputStream { const AVClass *class; @@ -343,10 +345,10 @@ typedef struct InputStream { * concurrently by the demuxing thread. */ AVCodecParameters *par; + Decoder *decoder; AVCodecContext *dec_ctx; const AVCodec *dec; const AVCodecDescriptor *codec_desc; - AVFrame *decoded_frame; AVPacket *pkt; AVRational framerate_guessed; @@ -812,6 +814,7 @@ AVBufferRef *hw_device_for_filter(void); int hwaccel_decode_init(AVCodecContext *avctx); int dec_open(InputStream *ist); +void dec_free(Decoder **pdec); /** * Submit a packet for decoding diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 0a470c4854..f4531684d5 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -31,6 +31,45 @@ #include "ffmpeg.h" +struct Decoder { + AVFrame *frame; +}; + +void dec_free(Decoder **pdec) +{ + Decoder *dec = *pdec; + + if (!dec) + return; + + av_frame_free(&dec->frame); + + av_freep(pdec); +} + +static int dec_alloc(Decoder **pdec) +{ + Decoder *dec; + + *pdec = NULL; + + dec = av_mallocz(sizeof(*dec)); + if (!dec) + return AVERROR(ENOMEM); + + dec->frame = av_frame_alloc(); + if (!dec->frame) + goto fail; + + + *pdec = dec; + + return 0; +fail: + dec_free(&dec); + return AVERROR(ENOMEM); +} + static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) { int i, ret; @@ -373,6 +412,7 @@ static int send_filter_eof(InputStream *ist) int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { + Decoder *d = ist->decoder; AVCodecContext *dec = ist->dec_ctx; const char *type_desc = av_get_media_type_string(dec->codec_type); int ret; @@ -402,7 +442,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) } while (1) { - AVFrame *frame = ist->decoded_frame; + AVFrame *frame = d->frame; update_benchmark(NULL); ret = avcodec_receive_frame(dec, frame); @@ -685,6 +725,10 @@ int dec_open(InputStream *ist) return AVERROR(EINVAL); } + ret = dec_alloc(&ist->decoder); + if (ret < 0) + return ret; + ist->dec_ctx->opaque = ist; ist->dec_ctx->get_format = get_format; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 33322ac565..29691cf68b 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -815,7 +815,8 @@ static void ist_free(InputStream **pist) if (!ist) return; - av_frame_free(&ist->decoded_frame); + dec_free(&ist->decoder); + av_packet_free(&ist->pkt); av_dict_free(&ist->decoder_opts); avsubtitle_free(&ist->prev_sub.subtitle); @@ -1196,10 +1197,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) exit_program(1); } - ist->decoded_frame = av_frame_alloc(); - if (!ist->decoded_frame) - report_and_exit(AVERROR(ENOMEM)); - ist->pkt = av_packet_alloc(); if (!ist->pkt) report_and_exit(AVERROR(ENOMEM)); From patchwork Tue May 23 13:58:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41802 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp601179pzb; Tue, 23 May 2023 07:00:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+adzltHlaecL5adKzgX9KBE6n3L+RroW+5SGgxSTCKILqwLkzhNpvUehZ2EBLsHIaaoke X-Received: by 2002:a17:907:7b9e:b0:96f:b58e:7e21 with SMTP id ne30-20020a1709077b9e00b0096fb58e7e21mr11233025ejc.52.1684850439521; Tue, 23 May 2023 07:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850439; cv=none; d=google.com; s=arc-20160816; b=B2KhKIbkkZUDE1Wq1vNYmidkoevLWkvxztGygU7g6zLH8M6cOnYE81WP4LUwPgvkS1 0q9P/hWvR49FsIVXdraYQ3kCVT+dW7aAuCsUsr6J0o2j7SrvkCXKCfcvplv8ZCRU2xq5 MF+9I322FboniPYZE+Vdd4oyQWOQe3Kjx6woMdOUT6kjp71eQL7DGMJoLyZJgUhy2+HC 0MxPI9JdiFJ61oPXZlQGsgll3rHaoXipKVYrxA2SMCyXu7Z4yjwpzBB6t08tbxBzc+Vu ljc1fY9rhPpP3s24IN7RXV1fEbH10bzjodl5v4k7NNxDNNJ5YT2jCu7vIZVydzvHQlAY Wg1w== 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=fzgvc28s/T+o1chJxIF52vnmvAX9V699M9u7gAc8eZw=; b=YQE+VWdDqBz3CPFARS5ksuCd9dNqzTKAvlZ0dsuFOLfeB3crPDJf8bcoAfF6IAj0Q9 JG+FcokjzyAX7ov5AR4QzMmfxcXp3Blgo5oR4XUuQ8QJhSVqHtrTbrXNI9gOIbXQoWPw Z8yhKFqXNcupZdVqCyWLUyDcyqT37F1DFVq8t+nJSSYb9RJT95Tk3z/0MrG5hteRMbfp x2cy5MLRoFxbIk7XzNrJ5UweZldMwaybyFtsPR1W7jz6wPCG0geMZdjIJRIIhrUYY6lu 0YnWaTRLDrLvZ0O82LvEDB7swT7jjxlPKc5DhgnzhawQAaqYOTvGpvONWosGdW0VAU1n YgXw== 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 dc9-20020a170906c7c900b00966448e2cefsi1491987ejb.395.2023.05.23.07.00.39; Tue, 23 May 2023 07:00: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 D5E2468C110; Tue, 23 May 2023 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 05A3C68C11A for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BFF9A2405B5 for ; Tue, 23 May 2023 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 G5SLcABM4q6s for ; Tue, 23 May 2023 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 963B62406CA for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 87BD43A11B4 for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:37 +0200 Message-Id: <20230523135842.20388-10-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/15] fftools/ffmpeg_dec: move InputStream.pkt to Decoder 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: lD4i3cWU33ED It is purely internal to decoding. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_dec.c | 8 +++++++- fftools/ffmpeg_demux.c | 5 ----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 92e56ee80c..b377871980 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -349,7 +349,6 @@ typedef struct InputStream { AVCodecContext *dec_ctx; const AVCodec *dec; const AVCodecDescriptor *codec_desc; - AVPacket *pkt; AVRational framerate_guessed; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index f4531684d5..23c50cc272 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -33,6 +33,7 @@ struct Decoder { AVFrame *frame; + AVPacket *pkt; }; void dec_free(Decoder **pdec) @@ -43,6 +44,7 @@ void dec_free(Decoder **pdec) return; av_frame_free(&dec->frame); + av_packet_free(&dec->pkt); av_freep(pdec); } @@ -61,6 +63,10 @@ static int dec_alloc(Decoder **pdec) if (!dec->frame) goto fail; + dec->pkt = av_packet_alloc(); + if (!dec->pkt) + goto fail; + *pdec = dec; @@ -418,7 +424,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) int ret; if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE) - return transcode_subtitles(ist, pkt ? pkt : ist->pkt); + return transcode_subtitles(ist, pkt ? pkt : d->pkt); // With fate-indeo3-2, we're getting 0-sized packets before EOF for some // reason. This seems like a semi-critical bug. Don't trigger EOF, and diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 29691cf68b..c65c72f556 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -817,7 +817,6 @@ static void ist_free(InputStream **pist) dec_free(&ist->decoder); - av_packet_free(&ist->pkt); av_dict_free(&ist->decoder_opts); avsubtitle_free(&ist->prev_sub.subtitle); av_frame_free(&ist->sub2video.frame); @@ -1197,10 +1196,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) exit_program(1); } - ist->pkt = av_packet_alloc(); - if (!ist->pkt) - report_and_exit(AVERROR(ENOMEM)); - if (o->bitexact) ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT; From patchwork Tue May 23 13:58:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41804 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp601612pzb; Tue, 23 May 2023 07:01:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6jY4k3+wA9On4U7IPxptQX7DnackEdzbn5e4TDXHxsTo1S6LiR6SAuVBnwBtyx/8azAA7S X-Received: by 2002:a17:907:948f:b0:96b:48d2:77ef with SMTP id dm15-20020a170907948f00b0096b48d277efmr11892359ejc.6.1684850464090; Tue, 23 May 2023 07:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850464; cv=none; d=google.com; s=arc-20160816; b=QjLFAVhw+Di4KStULqjRv/ihTxhr4YOyXU2svTNUGxuvzCTS7o3TbVrpOQHRuepzts 7zVBrqzNRBs+4ICbYMMJuVuYlz5/3lWYUbbmHM2Rev2ybco3ISfaz/K/OH16+TFV1hKr yY0QFbpxta6j+9sGKgMqxLXqgphzIRXlucPiCDNR0MkLFXzOTup+g0ifzsKVvA6ZSTgE yUxY6tU99lwZrF3RdrhM174CbOwKnffPTMURPKIGSZWuAed+nB/5738sa5KXTRNCl/mu QufRqWo3ndeTyg0du85NGN3PfPWbztK22fCnf1K6otQUhOqEPY8CwPtcT2kS41OswBQv A3zg== 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=DikChbcKPDP23do9SxqXgBcZoIO8B/yyBR7Mo/tpm/o=; b=JeH5eccBfNe0cvDZ3vrmrt+AALvAYxzCmx9nkGrqGcC1NyNQFCXlUrNZxwu+RaFiZy 12F9gqr8CnLR15op+1ZR0d5COQyNdrsqjgvbfaDkwBfUSMTx7ccZYxdh7DbJ2tVdoF5i lQRLxsBdcd4i9EwUNgyNZc6dtQwKsWmcpY0dhFtCEhRX/h1iRwe16YYnjsouG5tm9F7V h80pmfCB3kLD8TiIq066onBOATTeBcigPnPxDu91i0YVDTrPUZs3RCJyZNsBSNSzmT0B TqAcRrlWbICyGn2zVEGHR4xXJ3904Cphehhc/KtjL+6MrOp4OwNw2dw2/XLY0bmA/IHn NImA== 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 qo5-20020a170907874500b0096621c999c5si6197792ejc.288.2023.05.23.07.01.03; Tue, 23 May 2023 07:01:04 -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 BC35F68C16B; Tue, 23 May 2023 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 10DC768C105 for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A08412405F9 for ; Tue, 23 May 2023 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 tcTX738sRjfO for ; Tue, 23 May 2023 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 A02B32406CB for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9296C3A031B for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:38 +0200 Message-Id: <20230523135842.20388-11-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/15] fftools/ffmpeg_dec: move timestamp estimation state to Decoder 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: 3d6BwZLUxNI4 It is purely internal to decoding. --- fftools/ffmpeg.h | 10 ----- fftools/ffmpeg_dec.c | 87 +++++++++++++++++++++++++----------------- fftools/ffmpeg_demux.c | 5 --- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b377871980..d9cac95710 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -352,16 +352,6 @@ typedef struct InputStream { AVRational framerate_guessed; - // pts/estimated duration of the last decoded frame - // * in decoder timebase for video, - // * in last_frame_tb (may change during decoding) for audio - int64_t last_frame_pts; - int64_t last_frame_duration_est; - AVRational last_frame_tb; - int last_frame_sample_rate; - - int64_t filter_in_rescale_delta_last; - int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */ AVDictionary *decoder_opts; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 23c50cc272..c952473c16 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -34,6 +34,15 @@ struct Decoder { AVFrame *frame; AVPacket *pkt; + + // pts/estimated duration of the last decoded frame + // * in decoder timebase for video, + // * in last_frame_tb (may change during decoding) for audio + int64_t last_frame_pts; + int64_t last_frame_duration_est; + AVRational last_frame_tb; + int64_t last_filter_in_rescale_delta; + int last_frame_sample_rate; }; void dec_free(Decoder **pdec) @@ -67,6 +76,9 @@ static int dec_alloc(Decoder **pdec) if (!dec->pkt) goto fail; + dec->last_filter_in_rescale_delta = AV_NOPTS_VALUE; + dec->last_frame_pts = AV_NOPTS_VALUE; + dec->last_frame_tb = (AVRational){ 1, 1 }; *pdec = dec; @@ -94,21 +106,22 @@ static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) return ret; } -static AVRational audio_samplerate_update(InputStream *ist, const AVFrame *frame) +static AVRational audio_samplerate_update(void *logctx, Decoder *d, + const AVFrame *frame) { - const int prev = ist->last_frame_tb.den; + const int prev = d->last_frame_tb.den; const int sr = frame->sample_rate; AVRational tb_new; int64_t gcd; - if (frame->sample_rate == ist->last_frame_sample_rate) + if (frame->sample_rate == d->last_frame_sample_rate) goto finish; gcd = av_gcd(prev, sr); if (prev / gcd >= INT_MAX / sr) { - av_log(ist, AV_LOG_WARNING, + av_log(logctx, AV_LOG_WARNING, "Audio timestamps cannot be represented exactly after " "sample rate change: %d -> %d\n", prev, sr); @@ -123,20 +136,20 @@ static AVRational audio_samplerate_update(InputStream *ist, const AVFrame *frame !(frame->time_base.den % tb_new.den)) tb_new = frame->time_base; - if (ist->last_frame_pts != AV_NOPTS_VALUE) - ist->last_frame_pts = av_rescale_q(ist->last_frame_pts, - ist->last_frame_tb, tb_new); - ist->last_frame_duration_est = av_rescale_q(ist->last_frame_duration_est, - ist->last_frame_tb, tb_new); + if (d->last_frame_pts != AV_NOPTS_VALUE) + d->last_frame_pts = av_rescale_q(d->last_frame_pts, + d->last_frame_tb, tb_new); + d->last_frame_duration_est = av_rescale_q(d->last_frame_duration_est, + d->last_frame_tb, tb_new); - ist->last_frame_tb = tb_new; - ist->last_frame_sample_rate = frame->sample_rate; + d->last_frame_tb = tb_new; + d->last_frame_sample_rate = frame->sample_rate; finish: - return ist->last_frame_tb; + return d->last_frame_tb; } -static void audio_ts_process(InputStream *ist, AVFrame *frame) +static void audio_ts_process(void *logctx, Decoder *d, AVFrame *frame) { AVRational tb_filter = (AVRational){1, frame->sample_rate}; AVRational tb; @@ -145,27 +158,27 @@ static void audio_ts_process(InputStream *ist, AVFrame *frame) // on samplerate change, choose a new internal timebase for timestamp // generation that can represent timestamps from all the samplerates // seen so far - tb = audio_samplerate_update(ist, frame); - pts_pred = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : - ist->last_frame_pts + ist->last_frame_duration_est; + tb = audio_samplerate_update(logctx, d, frame); + pts_pred = d->last_frame_pts == AV_NOPTS_VALUE ? 0 : + d->last_frame_pts + d->last_frame_duration_est; if (frame->pts == AV_NOPTS_VALUE) { frame->pts = pts_pred; frame->time_base = tb; - } else if (ist->last_frame_pts != AV_NOPTS_VALUE && + } else if (d->last_frame_pts != AV_NOPTS_VALUE && frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base, AV_ROUND_UP)) { // there was a gap in timestamps, reset conversion state - ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + d->last_filter_in_rescale_delta = AV_NOPTS_VALUE; } frame->pts = av_rescale_delta(frame->time_base, frame->pts, tb, frame->nb_samples, - &ist->filter_in_rescale_delta_last, tb); + &d->last_filter_in_rescale_delta, tb); - ist->last_frame_pts = frame->pts; - ist->last_frame_duration_est = av_rescale_q(frame->nb_samples, - tb_filter, tb); + d->last_frame_pts = frame->pts; + d->last_frame_duration_est = av_rescale_q(frame->nb_samples, + tb_filter, tb); // finally convert to filtering timebase frame->pts = av_rescale_q(frame->pts, tb, tb_filter); @@ -175,6 +188,7 @@ static void audio_ts_process(InputStream *ist, AVFrame *frame) static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) { + const Decoder *d = ist->decoder; const InputFile *ifile = input_files[ist->file_index]; int64_t codec_duration = 0; @@ -202,9 +216,9 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr // when timestamps are available, repeat last frame's actual duration // (i.e. pts difference between this and last frame) - if (frame->pts != AV_NOPTS_VALUE && ist->last_frame_pts != AV_NOPTS_VALUE && - frame->pts > ist->last_frame_pts) - return frame->pts - ist->last_frame_pts; + if (frame->pts != AV_NOPTS_VALUE && d->last_frame_pts != AV_NOPTS_VALUE && + frame->pts > d->last_frame_pts) + return frame->pts - d->last_frame_pts; // try frame/codec duration if (frame->duration > 0) @@ -221,11 +235,13 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr } // last resort is last frame's estimated duration, and 1 - return FFMAX(ist->last_frame_duration_est, 1); + return FFMAX(d->last_frame_duration_est, 1); } static int video_frame_process(InputStream *ist, AVFrame *frame) { + Decoder *d = ist->decoder; + // The following line may be required in some cases where there is no parser // or the parser does not has_b_frames correctly if (ist->par->video_delay < ist->dec_ctx->has_b_frames) { @@ -273,13 +289,13 @@ static int video_frame_process(InputStream *ist, AVFrame *frame) // no timestamp available - extrapolate from previous frame duration if (frame->pts == AV_NOPTS_VALUE) - frame->pts = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : - ist->last_frame_pts + ist->last_frame_duration_est; + frame->pts = d->last_frame_pts == AV_NOPTS_VALUE ? 0 : + d->last_frame_pts + d->last_frame_duration_est; // update timestamp history - ist->last_frame_duration_est = video_duration_estimate(ist, frame); - ist->last_frame_pts = frame->pts; - ist->last_frame_tb = frame->time_base; + d->last_frame_duration_est = video_duration_estimate(ist, frame); + d->last_frame_pts = frame->pts; + d->last_frame_tb = frame->time_base; if (debug_ts) { av_log(ist, AV_LOG_INFO, @@ -404,12 +420,13 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt) static int send_filter_eof(InputStream *ist) { + Decoder *d = ist->decoder; int i, ret; for (i = 0; i < ist->nb_filters; i++) { - int64_t end_pts = ist->last_frame_pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : - ist->last_frame_pts + ist->last_frame_duration_est; - ret = ifilter_send_eof(ist->filters[i], end_pts, ist->last_frame_tb); + int64_t end_pts = d->last_frame_pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : + d->last_frame_pts + d->last_frame_duration_est; + ret = ifilter_send_eof(ist->filters[i], end_pts, d->last_frame_tb); if (ret < 0) return ret; } @@ -506,7 +523,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) ist->samples_decoded += frame->nb_samples; ist->nb_samples = frame->nb_samples; - audio_ts_process(ist, frame); + audio_ts_process(ist, ist->decoder, frame); } else { ret = video_frame_process(ist, frame); if (ret < 0) { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index c65c72f556..e02bdc3b96 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1181,11 +1181,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) exit_program(1); } - ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; - - ist->last_frame_pts = AV_NOPTS_VALUE; - ist->last_frame_tb = (AVRational){ 1, 1 }; - ist->dec_ctx = avcodec_alloc_context3(ist->dec); if (!ist->dec_ctx) report_and_exit(AVERROR(ENOMEM)); From patchwork Tue May 23 13:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41808 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp602708pzb; Tue, 23 May 2023 07:02:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ49OUn9RPkFYkDJ6dMt6nIcMynfndNaESVE5LIFfKaa9vmQ9hqfyE9zXY+gOcVsd8q/iOHm X-Received: by 2002:a05:6402:357:b0:50d:682d:d431 with SMTP id r23-20020a056402035700b0050d682dd431mr12014666edw.16.1684850523956; Tue, 23 May 2023 07:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850523; cv=none; d=google.com; s=arc-20160816; b=Mvpu0shgljTbePZfbjxMm80DqvEfTix285m/WCxwdEfBQuTT0G6uJNaFxwp8cw6Rw4 HwrXpOA5WMkai+NFz2xSFIy2mAkA4sEG8L0NePa5sGa/6SOzk9F8iHD6dFiPEQMw9zuf 2Y426T5nYJxdMonEwFZmZd9+CByiK/8oWOHQCmCKRuxVhTm+yyqvVWIn6aJAnG9AFGJl z7gyDGQwG5/6vDOa7o5UAePH0SjKxY4MozwErNfGQxFrMhOlHM/YveZW46X/ymzpVy9C tFGY9VFxDvk4JCmNvuLVktwSzTjxugewbKxfKElGaGvMDUVaZCxMhmCL+5SmXLMPYjzy eUIA== 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=tvSE1C8njJNBg8RALwsQb/DV4wFywmYMdwhnT8q1NhI=; b=dRySUdxKdM6zcjoeLSLVPoV4ArOTPXrWOOiO/3pDHcp7MN5/YiyknxbgXlVyhhF4m+ kOqQf8r6T6NU4xo8bezm5sENU6GxTe+L/JXeJgLwdnyYKClFcUQk6a8KoW7/Za1TVJB7 dYvMfsDWNK1EK6yvt4k2HdK4VmYs4qfhzxowv6dXM+FxXBoU+iBVXe1ruBvxCoIMSOZ/ RjcXiHy7K7pT0V+IslWqp2cwfDfaFvWVjs9HqnDt4WksjVPHDu/2ayxlofEk47M9fXoj RbBMm3heUR4juBV+4p386uo45HtNc5LwVtil0gfq23sZlCgnvnj+Pnawbzl9Q6Bjhnai A/Cg== 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 t20-20020aa7d4d4000000b0050bc68690bdsi2190690edr.343.2023.05.23.07.02.03; Tue, 23 May 2023 07:02:03 -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 194A968C17E; Tue, 23 May 2023 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 5430368C118 for ; Tue, 23 May 2023 16:59:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0C5D32404EC for ; Tue, 23 May 2023 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 bWom122nXB6q for ; Tue, 23 May 2023 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 AB3E12406CC for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9D4E23A048F for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:39 +0200 Message-Id: <20230523135842.20388-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/15] fftools/ffmpeg: add InputStream.index 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: K+s6zVVDih8K This allows to avoid access to the underlying AVStream in many places. --- fftools/ffmpeg.c | 6 +++--- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_dec.c | 6 +++--- fftools/ffmpeg_demux.c | 1 + fftools/ffmpeg_filter.c | 10 +++++----- fftools/ffmpeg_mux_init.c | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1fc13b3e29..0539a45856 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -539,7 +539,7 @@ OutputStream *ost_iter(OutputStream *prev) InputStream *ist_iter(InputStream *prev) { int if_idx = prev ? prev->file_index : 0; - int ist_idx = prev ? prev->st->index + 1 : 0; + int ist_idx = prev ? prev->index + 1 : 0; for (; if_idx < nb_input_files; if_idx++) { InputFile *f = input_files[if_idx]; @@ -937,7 +937,7 @@ static void print_stream_maps(void) for (int j = 0; j < ist->nb_filters; j++) { if (!filtergraph_is_simple(ist->filters[j]->graph)) { av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", - ist->file_index, ist->st->index, ist->dec ? ist->dec->name : "?", + ist->file_index, ist->index, ist->dec ? ist->dec->name : "?", ist->filters[j]->name); if (nb_filtergraphs > 1) av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index); @@ -967,7 +967,7 @@ static void print_stream_maps(void) av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", ost->ist->file_index, - ost->ist->st->index, + ost->ist->index, ost->file_index, ost->index); if (ost->enc_ctx) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d9cac95710..95334825ef 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -330,6 +330,8 @@ typedef struct InputStream { const AVClass *class; int file_index; + int index; + AVStream *st; int discard; /* true if stream data should be discarded */ int user_set_discard; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index c952473c16..afb2612ae8 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -470,7 +470,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) update_benchmark(NULL); ret = avcodec_receive_frame(dec, frame); update_benchmark("decode_%s %d.%d", type_desc, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (ret == AVERROR(EAGAIN)) { av_assert0(pkt); // should never happen during flushing @@ -528,7 +528,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) ret = video_frame_process(ist, frame); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->st->index); + "data for stream #%d:%d\n", ist->file_index, ist->index); exit_program(1); } } @@ -577,7 +577,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat "%s hwaccel requested for input stream #%d:%d, " "but cannot be initialized.\n", av_hwdevice_get_type_name(config->device_type), - ist->file_index, ist->st->index); + ist->file_index, ist->index); return AV_PIX_FMT_NONE; } continue; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index e02bdc3b96..828a1182f0 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1025,6 +1025,7 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st) ds->ist.st = st; ds->ist.file_index = f->index; + ds->ist.index = st->index; ds->ist.class = &input_stream_class; snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s", diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 640ecec067..f37b867b31 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1073,7 +1073,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name, @@ -1127,7 +1127,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, } snprintf(name, sizeof(name), "trim_in_%d_%d", - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -1180,7 +1180,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, } else av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, - ist->file_index, ist->st->index); + ist->file_index, ist->index); if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt, name, args.str, NULL, @@ -1189,7 +1189,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, last_filter = ifilter->filter; snprintf(name, sizeof(name), "trim for input stream %d:%d", - ist->file_index, ist->st->index); + ist->file_index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -1574,7 +1574,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) ifp->type_src == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", - ifp->ist->file_index, ifp->ist->st->index); + ifp->ist->file_index, ifp->ist->index); return AVERROR_INVALIDDATA; } } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 56f9d1215c..dc33d225df 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -792,7 +792,7 @@ static void new_stream_audio(Muxer *mux, const OptionsContext *o, ist = ost->ist; } - if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) { + if (!ist || (ist->file_index == map->file_idx && ist->index == map->stream_idx)) { if (av_reallocp_array(&ost->audio_channels_map, ost->audio_channels_mapped + 1, sizeof(*ost->audio_channels_map) From patchwork Tue May 23 13:58:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41805 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp601891pzb; Tue, 23 May 2023 07:01:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6brM8XXRl8U3Cn6Ws0I56K6CBi0b0ykcMZoZUnHK2UOLRvAchFIT0CADxgU9wFsp2Wgkri X-Received: by 2002:aa7:d74b:0:b0:50b:cc52:3fd3 with SMTP id a11-20020aa7d74b000000b0050bcc523fd3mr11008708eds.41.1684850478689; Tue, 23 May 2023 07:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850478; cv=none; d=google.com; s=arc-20160816; b=vLGkslE20V5JkYLZ3bBEkkoQFsIoBUYgYj/XYWhctfGu2ugXQV+ekQP/hN/SvqXCX+ /jsQf3PRPC95Gt8HhgvoD0dOe3twW+eigww4rlSuZMohyyjJM1UWTLwUa0s9i8nesU/H XW8aXbpWM6h41UGiPV7W2dFee2Y9BJerTywHQInMqXx+ioZPfuuD9Qb/8OAlV0KNpU8u P1I/RC4JeTjdCBSpY5JIg3lJM8hym1Y1R3XUvEXac0jM1uiTAmyXzw5B4bosqNcqfM0S Q/vTBoA9aDmGJzOva8jy6sXMib39/LZTm8RPmWVVPfK6cg0tSHveIKkVoozOlrA9YrnL uJmw== 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=tNpXxMB6ScC7hDen8GjB5OCcVi2zCFgBiKjEv0p2edE=; b=lziLNwu33GmMj2NdQXRG7pxVK6JixvTgsyCydp/TkucN0UhITxRTIc/VcWRUB8hv4r 2H8ErKUxPN9wp2PDiu0jbD6YdZA9B0ul4Iup+6jKSXfTgBWrEi0eg5a2Pg0rhJn6xzrB unuZhhICxIw3xlXwqaf3EfOQCTB0m3AooKAIsubpjR7gkYAu3hxgvMY89RZk67Vr12Cn 0ZOFB/dPcC0+fElSuFxdWiSY54ZmRHX5u34PFrri6jmZtfZEU+OUFIvTPPOfATW5/Mi+ 9VaArdSpU22V8wggC0PJWjSU6I19ksKxVAbPqH76Y+k5ZIxSSblc569KULRzxrr5OyC/ 9rNA== 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 n13-20020a05640206cd00b0050bdd834874si5687528edy.108.2023.05.23.07.01.17; Tue, 23 May 2023 07:01: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 9901668C162; Tue, 23 May 2023 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 8157468C11A for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2C9E22406CB for ; Tue, 23 May 2023 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 AyH_YpN2Z6jG for ; Tue, 23 May 2023 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 B63032406CD for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A7F843A031B for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:40 +0200 Message-Id: <20230523135842.20388-13-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/15] fftools/ffmpeg_demux: log discontinuity warnings to stream 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: 1m039DelB9gG Allows simplifying the log message. --- fftools/ffmpeg_demux.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 828a1182f0..561b4b0002 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -248,12 +248,10 @@ static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + AV_TIME_BASE/10 < ds->dts) { d->ts_offset_discont -= delta; - av_log(NULL, AV_LOG_WARNING, - "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->par->codec_type), - delta, d->ts_offset_discont); + av_log(ist, AV_LOG_WARNING, + "timestamp discontinuity " + "(stream id=%d): %"PRId64", new offset= %"PRId64"\n", + ist->st->id, delta, d->ts_offset_discont); pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base); if (pkt->pts != AV_NOPTS_VALUE) pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base); From patchwork Tue May 23 13:58:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41806 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp602226pzb; Tue, 23 May 2023 07:01:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FTds4FMyI8RsnlRd1nsigiB80DUjksLcoP8qjQ/kiwRQfSE81mEc/IWIEjulC/8Nx96My X-Received: by 2002:a17:907:86a2:b0:96f:a39c:86d6 with SMTP id qa34-20020a17090786a200b0096fa39c86d6mr10956699ejc.8.1684850497542; Tue, 23 May 2023 07:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850497; cv=none; d=google.com; s=arc-20160816; b=py5d5pyfhsEA+8mbnKF3fFmJZETp/ZPtyeS9WqOzMgMAn3QBFLSYIKrKljXG/UL8Wi T+F9rQ5yN5dVGO0iW40vLFFfglPr34pwoHe7l9HkwyhUq+i7fHfRXQRfyisgT0u7CRuP xMc8Ocs2oUo+ZyUu6oSFeVpNaY+z0uGr+PPkx7XwIXH6UYkahPTIF/8si4bL+zvazfTn tPyAxn5nytgmwDQpUd9vPbmoWQY7htzyttpIXogvzrISCv1o49WM7HsUo9JPtlrD92nb 1fui/T5tBOdFS/HEMTNhpQPplL4TZ8IZAgj5ewG7nR7+52xafqoGCfcvbxH/3hvA/vm+ HiUQ== 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=2ZsOOJAW84Y6rUk34aXOXzIiwo101r1zCnqVt11jy1Q=; b=Qakod+GNXbHfbvpqykdu7RcIQB0rrw0WD3hn/RlzUwXZecMLJqUQvFbcBg0bCVe2TK vcE+wMeY/3Wm8XMifumOcZmsGEeLe5JJkqfXI3BI6P35327gTOuz+943DsqZMR3DB+K4 wvHfrm0hCABvJSCQxOupdUxlWwXhSDR0XKZ5GSXbnt3nuRdGHcYTCM3RJrNIo8MaLwOv Z/ORzsUGlxdZZ5fbJ6pvybPACjoiQ+XrgBt/CiyNZDDK1jtlCfj151ftSGgvsvEGKhyu 68Z9wJ9IndQ1ypwT/uREY9V+YMVXie1uOF8P9md18M0/ckXk19pcuEGe2LI1u/qN6Sww gxOQ== 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 gv39-20020a1709072be700b0096f75d92716si1609987ejc.752.2023.05.23.07.01.32; Tue, 23 May 2023 07:01:37 -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 559D668C175; Tue, 23 May 2023 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 83A0B68C126 for ; Tue, 23 May 2023 16:59:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EA4DE2406CD for ; Tue, 23 May 2023 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 RZD5NvqpIFqc for ; Tue, 23 May 2023 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 C16712406CE for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B2C213A048F for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:41 +0200 Message-Id: <20230523135842.20388-14-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/15] fftools/sync_queue: add debug logging 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: XdwdX7uVIWYX --- fftools/ffmpeg_mux_init.c | 4 ++-- fftools/sync_queue.c | 40 ++++++++++++++++++++++++++++++++++++--- fftools/sync_queue.h | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index dc33d225df..7878789bb4 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1625,7 +1625,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u * - at least one audio encoder requires constant frame sizes */ if ((of->shortest && nb_av_enc > 1) || limit_frames_av_enc || nb_audio_fs) { - of->sq_encode = sq_alloc(SYNC_QUEUE_FRAMES, buf_size_us); + of->sq_encode = sq_alloc(SYNC_QUEUE_FRAMES, buf_size_us, mux); if (!of->sq_encode) return AVERROR(ENOMEM); @@ -1650,7 +1650,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u /* if there are any additional interleaved streams, then ALL the streams * are also synchronized before sending them to the muxer */ if (nb_interleaved > nb_av_enc) { - mux->sq_mux = sq_alloc(SYNC_QUEUE_PACKETS, buf_size_us); + mux->sq_mux = sq_alloc(SYNC_QUEUE_PACKETS, buf_size_us, mux); if (!mux->sq_mux) return AVERROR(ENOMEM); diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c index a7aac04047..c0f33e9235 100644 --- a/fftools/sync_queue.c +++ b/fftools/sync_queue.c @@ -27,6 +27,7 @@ #include "libavutil/mathematics.h" #include "libavutil/mem.h" #include "libavutil/samplefmt.h" +#include "libavutil/timestamp.h" #include "objpool.h" #include "sync_queue.h" @@ -87,6 +88,8 @@ typedef struct SyncQueueStream { struct SyncQueue { enum SyncQueueType type; + void *logctx; + /* no more frames will be sent for any stream */ int finished; /* sync head: the stream with the _smallest_ head timestamp @@ -169,6 +172,11 @@ static void finish_stream(SyncQueue *sq, unsigned int stream_idx) { SyncQueueStream *st = &sq->streams[stream_idx]; + if (!st->finished) + av_log(sq->logctx, AV_LOG_DEBUG, + "sq: finish %u; head ts %s\n", stream_idx, + av_ts2timestr(st->head_ts, &st->tb)); + st->finished = 1; if (st->limiting && st->head_ts != AV_NOPTS_VALUE) { @@ -186,8 +194,14 @@ static void finish_stream(SyncQueue *sq, unsigned int stream_idx) for (unsigned int i = 0; i < sq->nb_streams; i++) { SyncQueueStream *st1 = &sq->streams[i]; if (st != st1 && st1->head_ts != AV_NOPTS_VALUE && - av_compare_ts(st->head_ts, st->tb, st1->head_ts, st1->tb) <= 0) + av_compare_ts(st->head_ts, st->tb, st1->head_ts, st1->tb) <= 0) { + if (!st1->finished) + av_log(sq->logctx, AV_LOG_DEBUG, + "sq: finish secondary %u; head ts %s\n", i, + av_ts2timestr(st1->head_ts, &st1->tb)); + st1->finished = 1; + } } } @@ -197,6 +211,8 @@ static void finish_stream(SyncQueue *sq, unsigned int stream_idx) return; } sq->finished = 1; + + av_log(sq->logctx, AV_LOG_DEBUG, "sq: finish queue\n"); } static void queue_head_update(SyncQueue *sq) @@ -306,6 +322,9 @@ static int overflow_heartbeat(SyncQueue *sq, int stream_idx) if (st1->head_ts != AV_NOPTS_VALUE) ts = FFMAX(st1->head_ts + 1, ts); + av_log(sq->logctx, AV_LOG_DEBUG, "sq: %u overflow heardbeat %s -> %s\n", + i, av_ts2timestr(st1->head_ts, &st1->tb), av_ts2timestr(ts, &st1->tb)); + stream_update_ts(sq, i, ts); } @@ -323,6 +342,7 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) st = &sq->streams[stream_idx]; if (frame_null(sq, frame)) { + av_log(sq->logctx, AV_LOG_DEBUG, "sq: %u EOF\n", stream_idx); finish_stream(sq, stream_idx); return 0; } @@ -347,6 +367,9 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) ts = frame_end(sq, dst, 0); + av_log(sq->logctx, AV_LOG_DEBUG, "sq: send %u ts %s\n", stream_idx, + av_ts2timestr(ts, &st->tb)); + ret = av_fifo_write(st->fifo, &dst, 1); if (ret < 0) { frame_move(sq, frame, dst); @@ -364,8 +387,12 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) else st->frames_sent++; - if (st->frames_sent >= st->frames_max) + if (st->frames_sent >= st->frames_max) { + av_log(sq->logctx, AV_LOG_DEBUG, "sq: %u frames_max %"PRIu64" reached\n", + stream_idx, st->frames_max); + finish_stream(sq, stream_idx); + } return 0; } @@ -531,6 +558,12 @@ static int receive_for_stream(SyncQueue *sq, unsigned int stream_idx, st->samples_queued -= frame_samples(sq, frame); } + av_log(sq->logctx, AV_LOG_DEBUG, + "sq: receive %u ts %s queue head %d ts %s\n", stream_idx, + av_ts2timestr(frame_end(sq, frame, 0), &st->tb), + sq->head_stream, + st_head ? av_ts2timestr(st_head->head_ts, &st_head->tb) : "N/A"); + return 0; } } @@ -630,7 +663,7 @@ void sq_frame_samples(SyncQueue *sq, unsigned int stream_idx, sq->align_mask = av_cpu_max_align() - 1; } -SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us) +SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us, void *logctx) { SyncQueue *sq = av_mallocz(sizeof(*sq)); @@ -639,6 +672,7 @@ SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us) sq->type = type; sq->buf_size_us = buf_size_us; + sq->logctx = logctx; sq->head_stream = -1; sq->head_finished_stream = -1; diff --git a/fftools/sync_queue.h b/fftools/sync_queue.h index bc7cd42390..dc5acfd499 100644 --- a/fftools/sync_queue.h +++ b/fftools/sync_queue.h @@ -50,7 +50,7 @@ typedef struct SyncQueue SyncQueue; * * @param buf_size_us maximum duration that will be buffered in microseconds */ -SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us); +SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us, void *logctx); void sq_free(SyncQueue **sq); /** From patchwork Tue May 23 13:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41807 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp602532pzb; Tue, 23 May 2023 07:01:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KsV94O57c5JU/fdQH6kGRNFE5ptI9HTM5VXnaGdqGfUfJCvwkkDdkutMpWbZUE7e4MvfP X-Received: by 2002:a17:907:9807:b0:96f:e7cf:501b with SMTP id ji7-20020a170907980700b0096fe7cf501bmr6886354ejc.33.1684850514120; Tue, 23 May 2023 07:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850514; cv=none; d=google.com; s=arc-20160816; b=wcMFNoarjEzBLNL08tyyvEcG9r627aQa2ZER3iOUros5XPfO11s5+oqchfztrwEh1/ lPJbQZNBUWkH9PVtmxPgsYy15wSZ1dUWvqeLRjWY750RhukPs10gx8iHp8NKvvWU3ecr CthKUKLFP7e9vihbwXT7TEedUVMAMdS71QORp5JMgIkzfxh0l0wH8AbqJxovkRDkA1TI iHcyLQeKgByFoVh55r7StlkRftJ4rF4RjzO9cibDX9by0uZwnLVLsxREA5vqMTccAmWo gIkmQtJ8PqhOsehAwMR0QhUlxBc5UobZGHdRSe/jpYbkmb3a59svhEeSTUstofCK0XZB YSiA== 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=bA2J/kwTw6KC4SqshPwkqfxWClvEuXznzpuyP/FmiXQ=; b=OMJB92brWPKGOjTdR6xVxwit/lgFMwsRz6n8qJGymeyEpTIfLtn4cnbB4dY5HDQeTw HDqlvYEvTswT6Wn8woHqDBCypRYRFVh7tARcWliZT75CqBgGjCKBxi2ASLbGLDrYzIGZ +1Vg1xAR9nriVvnaqKJleVCv11AIQpLbLPqsdh0Cn47gZOdcS05XlCyc6RHb/NYuHubQ TBJbZySKYD8vrt7UN0ThSJtA6I7ZPWQJsJ4yGsqrMfheFdKHeZZCJhasz3qNCQpi84sN 3ukDAHwfrPGo7JekXL2aJ9h7f9QayhxNQwS9E9nti8d8MIXX8pPL0RBy2P97GEylGLjX rLOQ== 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 s8-20020a1709067b8800b00965a20908edsi103255ejo.422.2023.05.23.07.01.48; Tue, 23 May 2023 07:01: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 156D568C179; Tue, 23 May 2023 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 195FE68C11B for ; Tue, 23 May 2023 16:59:05 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7EA1B2406CE for ; Tue, 23 May 2023 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 MD9mX2UQUW1u for ; Tue, 23 May 2023 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 CB0AA2406CF for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BD6743A031B for ; Tue, 23 May 2023 15:58:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 May 2023 15:58:42 +0200 Message-Id: <20230523135842.20388-15-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230523135842.20388-1-anton@khirnov.net> References: <20230523135842.20388-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/15] fftools/sync_queue: make sure non-limiting streams are not used as queue head 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: 486NIMIumoPT A non-limiting stream could mistakenly end up being the queue head, which would then produce incorrect synchronization, seen e.g. in fate-matroska-flac-extradata-update for certain number of frame threads (e.g. 5). Found-By: James Almer --- fftools/sync_queue.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c index c0f33e9235..bc107ba4fe 100644 --- a/fftools/sync_queue.c +++ b/fftools/sync_queue.c @@ -217,17 +217,26 @@ static void finish_stream(SyncQueue *sq, unsigned int stream_idx) static void queue_head_update(SyncQueue *sq) { + av_assert0(sq->have_limiting); + if (sq->head_stream < 0) { + unsigned first_limiting = UINT_MAX; + /* wait for one timestamp in each stream before determining * the queue head */ for (unsigned int i = 0; i < sq->nb_streams; i++) { SyncQueueStream *st = &sq->streams[i]; - if (st->limiting && st->head_ts == AV_NOPTS_VALUE) + if (!st->limiting) + continue; + if (st->head_ts == AV_NOPTS_VALUE) return; + if (first_limiting == UINT_MAX) + first_limiting = i; } // placeholder value, correct one will be found below - sq->head_stream = 0; + av_assert0(first_limiting < UINT_MAX); + sq->head_stream = first_limiting; } for (unsigned int i = 0; i < sq->nb_streams; i++) {