From patchwork Thu Jul 7 16:13:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 36700 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp4996454pzh; Thu, 7 Jul 2022 09:13:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ujKTX4a6dWhLgaaiTA1Q2YkT38NOlQaVZGDvkWzKqSNklrZKGNccZ3v9E1xjQGrwWeokV7 X-Received: by 2002:aa7:cc0b:0:b0:437:9c60:127b with SMTP id q11-20020aa7cc0b000000b004379c60127bmr61508523edt.320.1657210417067; Thu, 07 Jul 2022 09:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657210417; cv=none; d=google.com; s=arc-20160816; b=KBY2HlgWbuvcRYoZYzh5UwVIKrCrp/7FjQVGe40nfKuiMWxynqcwBa7WwKWp32aT5G +HWvHC3q/yJRf/VMYfxsUnExfbey6i9Od+Zojn2ozToK1qe2/nHc4PRv8ocG+BvuFYvU Mpn62VKwXWxGjovLdHMHLnAE2TZxI+rbEGRKy11+Xya1l1Hub4Iy/uTHTrwsqsoAmzoq BP3Cc/94doZ3RzMM0jLIb7PQYWRlK1MbEXTj6+vgLiqMvpT/XnQtDGDiDgo8MMJ0/W2V Rl6ZSvyfC1jJByJk+X7BUUVpuYiWfGvmB5gcgC7xSIkVcHuTVmkIfWdhhpuPh+j4qo5P Au0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=WUZdrhtTvKi+M7ngRsAs0BSX7G2VLe4GR2dlDUus5IM=; b=Id6/F4Ru4fOdge8VoVgWiVKdnvF3/u3IzQzTr3/grN5eAAa+C1iA8db1IYW2rs5+9W nrwfiNxRO9G536RrnqCYjNoWqmZ8ftZFd9vxNfYH6FBrW5jlAbfNz9EgRa03nU14IGh8 X6RulLWszwt1r3nv6ZeJ+6e9n9Z4WGq3E65pF2FVPxM0mwGgshnfo5zyDrWNZEF3fuGw ULEm+wfAxgtD4FqW+EMwq/RXDl+2ayTnxn7o52O4mvxbEyQKPId/R/Z2kYFslX2twMTm 9xa4Mua7HF7cZEDW7f8nZ4TZAO3/n2ZgN5CM48Mt803n5gyjZ0h141cHTlMFZltnLlYg U3kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=UOAmZHBL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id js9-20020a17090797c900b0072a477a55e0si614626ejc.369.2022.07.07.09.13.28; Thu, 07 Jul 2022 09:13: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; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=UOAmZHBL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0EE5068B8BD; Thu, 7 Jul 2022 19:13:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [136.243.74.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C3A968B823 for ; Thu, 7 Jul 2022 19:13:17 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id EE03539E6AE; Thu, 7 Jul 2022 18:13:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1657210397; bh=ceIHBhXpdVmA4mDBzER3vhKTUKPfQgk7qV7YjT1Xl80=; h=From:To:Cc:Subject:Date; b=UOAmZHBL92N75OTaR79vdDzygKLfwSzjXD6Alizz3vBfGWjPXOXU3iuIgpzQlrqwj QHfKp/cvc2r4dvEMYdetMptNEvu6hGFtJIdIogPuGw0cgtrBCH8cwlyTjdUH4n5MI9 MaolheTvwn85XMeRbruBshB3e3QzRu9l0Yt9PIRJxdJp4duwLV5o01VWZXceGXq3+q F78OOJ49Ap/IfzsnfHqN2v33GgrwnyU9/pecvuvkkLUtujgCbiPrgJbjXIDvhwOmKK TdkksIL6cd/5PWeeuwXCCkxDN65MYNTJZTTnyxIhLhL0p5mPcRyhFgeYu4BIs00JVH sM/gQiQXZrP2w== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Jul 2022 18:13:06 +0200 Message-Id: <20220707161307.1136-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avdevice/lavfi: output wrapped AVFrames 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 Cc: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TfbyF82GZs6j This avoids an extra copy of potentially quite big video frames. Instead of copying the entire frames data into a rawvideo packet it packs the frame into a wrapped avframe packet and passes it through as-is. Unfortunately, wrapped avframes are set up to be video frames, so the audio frames continue to be copied. Additionally, this enabled passing through video frames that previously were impossible to process, like hardware frames or other special formats that couldn't be packed into a rawvideo packet. --- libavdevice/lavfi.c | 89 +++++++++-------------- libavdevice/version.h | 2 +- tests/ref/fate/filter-metadata-cropdetect | 3 +- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index db5d0b94de..1b282a70cb 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -54,32 +54,10 @@ typedef struct { int *sink_eof; int *stream_sink_map; int *sink_stream_subcc_map; - AVFrame *decoded_frame; int nb_sinks; AVPacket subcc_packet; } LavfiContext; -static int *create_all_formats(int n) -{ - int i, j, *fmts, count = 0; - - for (i = 0; i < n; i++) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i); - if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) - count++; - } - - if (!(fmts = av_malloc_array(count + 1, sizeof(*fmts)))) - return NULL; - for (j = 0, i = 0; i < n; i++) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i); - if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) - fmts[j++] = i; - } - fmts[j] = AV_PIX_FMT_NONE; - return fmts; -} - av_cold static int lavfi_read_close(AVFormatContext *avctx) { LavfiContext *lavfi = avctx->priv_data; @@ -90,7 +68,6 @@ av_cold static int lavfi_read_close(AVFormatContext *avctx) av_freep(&lavfi->sink_stream_subcc_map); av_freep(&lavfi->sinks); avfilter_graph_free(&lavfi->graph); - av_frame_free(&lavfi->decoded_frame); return 0; } @@ -125,15 +102,11 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) LavfiContext *lavfi = avctx->priv_data; AVFilterInOut *input_links = NULL, *output_links = NULL, *inout; const AVFilter *buffersink, *abuffersink; - int *pix_fmts = create_all_formats(AV_PIX_FMT_NB); enum AVMediaType type; int ret = 0, i, n; #define FAIL(ERR) { ret = ERR; goto end; } - if (!pix_fmts) - FAIL(AVERROR(ENOMEM)); - buffersink = avfilter_get_by_name("buffersink"); abuffersink = avfilter_get_by_name("abuffersink"); @@ -264,8 +237,6 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) ret = avfilter_graph_create_filter(&sink, buffersink, inout->name, NULL, NULL, lavfi->graph); - if (ret >= 0) - ret = av_opt_set_int_list(sink, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto end; } else if (type == AVMEDIA_TYPE_AUDIO) { @@ -321,15 +292,12 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) avpriv_set_pts_info(st, 64, time_base.num, time_base.den); par->codec_type = av_buffersink_get_type(sink); if (par->codec_type == AVMEDIA_TYPE_VIDEO) { - int64_t probesize; - par->codec_id = AV_CODEC_ID_RAWVIDEO; + par->codec_id = AV_CODEC_ID_WRAPPED_AVFRAME; par->format = av_buffersink_get_format(sink); par->width = av_buffersink_get_w(sink); par->height = av_buffersink_get_h(sink); - probesize = par->width * par->height * 30 * - av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(par->format)); - avctx->probesize = FFMAX(avctx->probesize, probesize); - st ->sample_aspect_ratio = + avctx->probesize = FFMAX(avctx->probesize, sizeof(AVFrame) * 30); + st ->sample_aspect_ratio = par->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink); } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { par->sample_rate = av_buffersink_get_sample_rate(sink); @@ -348,11 +316,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) if ((ret = create_subcc_streams(avctx)) < 0) goto end; - if (!(lavfi->decoded_frame = av_frame_alloc())) - FAIL(AVERROR(ENOMEM)); - end: - av_free(pix_fmts); avfilter_inout_free(&input_links); avfilter_inout_free(&output_links); return ret; @@ -378,15 +342,20 @@ static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame, return 0; } +static void lavfi_free_frame(void *opaque, uint8_t *data) +{ + AVFrame *frame = (AVFrame*)data; + av_frame_free(&frame); +} + static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) { LavfiContext *lavfi = avctx->priv_data; double min_pts = DBL_MAX; int stream_idx, min_pts_sink_idx = 0; - AVFrame *frame = lavfi->decoded_frame; + AVFrame *frame; AVDictionary *frame_metadata; int ret, i; - int size = 0; AVStream *st; if (lavfi->subcc_packet.size) { @@ -394,12 +363,15 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) return pkt->size; } + frame = av_frame_alloc(); + if (!frame) + return AVERROR(ENOMEM); + /* iterate through all the graph sinks. Select the sink with the * minimum PTS */ for (i = 0; i < lavfi->nb_sinks; i++) { AVRational tb = av_buffersink_get_time_base(lavfi->sinks[i]); double d; - int ret; if (lavfi->sink_eof[i]) continue; @@ -411,7 +383,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) lavfi->sink_eof[i] = 1; continue; } else if (ret < 0) - return ret; + goto fail; d = av_rescale_q_rnd(frame->pts, tb, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); ff_dlog(avctx, "sink_idx:%d time:%f\n", i, d); av_frame_unref(frame); @@ -421,8 +393,10 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) min_pts_sink_idx = i; } } - if (min_pts == DBL_MAX) - return AVERROR_EOF; + if (min_pts == DBL_MAX) { + ret = AVERROR_EOF; + goto fail; + } ff_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx); @@ -431,15 +405,19 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) st = avctx->streams[stream_idx]; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - size = av_image_get_buffer_size(frame->format, frame->width, frame->height, 1); - if ((ret = av_new_packet(pkt, size)) < 0) + pkt->buf = av_buffer_create((uint8_t*)frame, sizeof(*frame), + &lavfi_free_frame, NULL, 0); + if (!pkt->buf) { + ret = AVERROR(ENOMEM); goto fail; + } - av_image_copy_to_buffer(pkt->data, size, (const uint8_t **)frame->data, frame->linesize, - frame->format, frame->width, frame->height, 1); + pkt->data = pkt->buf->data; + pkt->size = pkt->buf->size; + pkt->flags |= AV_PKT_FLAG_TRUSTED; } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - size = frame->nb_samples * av_get_bytes_per_sample(frame->format) * - frame->ch_layout.nb_channels; + int size = frame->nb_samples * av_get_bytes_per_sample(frame->format) * + frame->ch_layout.nb_channels; if ((ret = av_new_packet(pkt, size)) < 0) goto fail; memcpy(pkt->data, frame->data[0], size); @@ -468,10 +446,13 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) pkt->stream_index = stream_idx; pkt->pts = frame->pts; pkt->pos = frame->pkt_pos; - av_frame_unref(frame); - return size; + + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) + av_frame_free(&frame); + + return pkt->size; fail: - av_frame_unref(frame); + av_frame_free(&frame); return ret; } diff --git a/libavdevice/version.h b/libavdevice/version.h index 09c1d778dc..5462173f17 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVDEVICE_VERSION_MINOR 6 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ diff --git a/tests/ref/fate/filter-metadata-cropdetect b/tests/ref/fate/filter-metadata-cropdetect index e7c03ead4e..104acdd77f 100644 --- a/tests/ref/fate/filter-metadata-cropdetect +++ b/tests/ref/fate/filter-metadata-cropdetect @@ -1,4 +1,5 @@ -pts=0 +pts=0| + pts=400 pts=800|tag:lavfi.cropdetect.x1=0|tag:lavfi.cropdetect.x2=719|tag:lavfi.cropdetect.y1=61|tag:lavfi.cropdetect.y2=424|tag:lavfi.cropdetect.w=720|tag:lavfi.cropdetect.h=352|tag:lavfi.cropdetect.x=0|tag:lavfi.cropdetect.y=68 pts=1200|tag:lavfi.cropdetect.x1=0|tag:lavfi.cropdetect.x2=719|tag:lavfi.cropdetect.y1=61|tag:lavfi.cropdetect.y2=424|tag:lavfi.cropdetect.w=720|tag:lavfi.cropdetect.h=352|tag:lavfi.cropdetect.x=0|tag:lavfi.cropdetect.y=68 From patchwork Thu Jul 7 16:13:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 36701 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp4996509pzh; Thu, 7 Jul 2022 09:13:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sKZx7P3uJK+Beg5Xrr87SBwBF/Yzx+XELK1xiMeUxBEAhRyi4twh/J+xIzgfSRUhOilU+p X-Received: by 2002:a05:6402:1e92:b0:43a:7cd0:6bed with SMTP id f18-20020a0564021e9200b0043a7cd06bedmr19026455edf.423.1657210422185; Thu, 07 Jul 2022 09:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657210422; cv=none; d=google.com; s=arc-20160816; b=Cgj8Vz2YPlklPhtBts196AkAu4lrKvr6UrWCr1ZGPmyYPXf1VdPUedASzTy9DqG+CT 3hT6qvSmK5eYr0Ol7fv3aUTgZ0Lz0mX1Ba6qyjkdQWtCT7usVe+YH6bW9wmVgJf4akB8 W9r/1UJWjKjiBK0GhIDy/DHnCH8qvlPsq9pBPfRRf+QTh3tRZTY1AJqCDdckTNYCO4Os OaEtsRSZ/1G0KUUyR5R6NnrUvuJLQNXSAY54r3mAUPu0MBHWJ0Ew4V+3b9F95jEemZaS fphVGSom6PR4QalaBfSFNNdNZlOLEcBUcf1UFM6crSMWYa86iUY5QFvcHOMIYmmAHDA9 QgEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=XRuXlhMy+1bIyYclInDSBcQPVSjzRADy0y4qdOQBbAk=; b=0gMEifLa20/YAoEHuEiv6aXyon807TQ4SlgoU32uV+L0rtc0nWl6FF3MW9ZOZUZGEB LXeyeEOjFGcc/pGfRW//mo2cnGnust6xSRbX83nNFR3gTGFbuPsbfmv3+Rrt10b7XPOA xsfODikdaZr80/KA0uS+9KkUE0E7RjIu2TMGJRHgoQnQoVChN6iY3qdYiaPq4BaZeipp r99S0HKFX2cBD/YgBDfRzYaMjD8N/Gig69yZbJ7kyOINUh/O1yWS/zyYPFiJp8mVAzLO 6KWt3Ei/YgtlC7tkpDvibYSboqYjMeSK0pvp1NKu6NVTnGXUC0Fy1bBNXCRFS5RPUmoT N5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=NjX8Pk4n; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dn18-20020a17090794d200b006f3976ed175si3806483ejc.938.2022.07.07.09.13.40; Thu, 07 Jul 2022 09:13:42 -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; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=NjX8Pk4n; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5E4F68B8D1; Thu, 7 Jul 2022 19:13:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [136.243.74.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D7C168B88B for ; Thu, 7 Jul 2022 19:13:17 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 1B49A39E27C; Thu, 7 Jul 2022 18:13:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1657210397; bh=1nQPcAKKAqvzv0Vuf5xUolsyvwAiPr6eeSf6BqUx7aQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NjX8Pk4nlOXllOWqlgqtAUGm0weojVe4OZgbStpwx9AyFKKKt6i4BsI3zBSpYM47w GIUSaPBHW6vrAucu6gksRV8IRyfqq2H1vfOQQUWxwWiKbO/55MsHR8m/WrRhuf+fGn GnLgrUbVUkNwUYzivDhlh3x3Cb3eNfEggG0B2UzbusLM7TS98DYS17/Lq9DdTosSDg WdszqAXyNmdQVEvV2Y980GJ+TCafPq1vQZDcQXE3Qa2XpWhbVfcnRD5dAHFXanSNPe wDxBOkmH2iAhBwJyFGdv0MoEGqFHbxOJ11qOyX85yNO6wRdihn9nJGg49WZQNulOUA KdjYup8VxDsmg== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Jul 2022 18:13:07 +0200 Message-Id: <20220707161307.1136-2-timo@rothenpieler.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707161307.1136-1-timo@rothenpieler.org> References: <20220707161307.1136-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avdevice/lavfi: pass forward video framerate 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 Cc: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cw/KfPNpNY1s --- libavdevice/lavfi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 1b282a70cb..246f7dff3b 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -287,6 +287,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) for (i = 0; i < lavfi->nb_sinks; i++) { AVFilterContext *sink = lavfi->sinks[lavfi->stream_sink_map[i]]; AVRational time_base = av_buffersink_get_time_base(sink); + AVRational frame_rate = av_buffersink_get_frame_rate(sink); AVStream *st = avctx->streams[i]; AVCodecParameters *const par = st->codecpar; avpriv_set_pts_info(st, 64, time_base.num, time_base.den); @@ -299,6 +300,10 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) avctx->probesize = FFMAX(avctx->probesize, sizeof(AVFrame) * 30); st ->sample_aspect_ratio = par->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink); + if (frame_rate.num > 0 && frame_rate.den > 0) { + st->avg_frame_rate = frame_rate; + st->r_frame_rate = frame_rate; + } } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { par->sample_rate = av_buffersink_get_sample_rate(sink); ret = av_buffersink_get_ch_layout(sink, &par->ch_layout);