From patchwork Sun Sep 15 05:15:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus B Spencer X-Patchwork-Id: 51607 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp626431vqy; Sat, 14 Sep 2024 22:34:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUGMP2fqFPbpKDkSJ0MA/6OWz7Qjt0gFLO3yh8dovx8Gq45YqpU+AoA2pb56YAIi809z8ga7F0DK615Fak4796X@gmail.com X-Google-Smtp-Source: AGHT+IHQsSx0dPGJhHq1QQ1GkfhvFA3CDZhwBzUHwdUlQbUjO0n625Xd2+emz9T8YrkkzXoFHHa8 X-Received: by 2002:a17:906:fe4a:b0:a86:7179:849e with SMTP id a640c23a62f3a-a902910747dmr431349366b.0.1726378450571; Sat, 14 Sep 2024 22:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726378450; cv=none; d=google.com; s=arc-20240605; b=LfKtaAJigihtB1tblJj9tXwOgCXVnnnxpjA79tFNDalW4URCvfSJ/wtOYqwCrPddZH mHLD8Nc5PDjPWR/L65Gn4AM6AuyclSXU61PvjxRkWfns5VYm1cTkhXpmA0SEbkl6hg6p sX6ZNt6rCb80R/yLh9FYLGMc7bgRGBCyIFW7Qs5nNXdXVnZ8Eq+6k51EIjcr+4rDHeBY uN85cpk3Q6uReZG/TW/iDNerHzrjGZ6I9WWVwtyYLQmvfOI9sbhwCBn5779lPl6RkugQ 0zHtplpxbkGYEPZ560G6JTFnxcUP8icS2T4qwGxv+K8oxSs+w7ltBScbgCZKyG8+RLOP NFsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=VZlXrhDZL21GWQRX0kc2BQfCxxMs7XqgijxxzSK9z9g=; fh=JuegC/vje050XLj6U2KtH3S0d9hYf9AYxo0tX+p7f28=; b=SPq6ycgsehyB5uj5ePMZ3qbJ6SVFPZxIp4mUvZDWOT+MDzJ0++oTWRTDVNPVwJ3s9u +9e5SbBPdHH506uooSqOSe/VYLcFuvx0F13dybYXOcSQczAUMJALuMOooYsf6+0yj6a6 MaU320ryfK1igIV8yxKHVMNQUEbTE8Wk0HKPgaqY2OvVZEyj1zQXG6bjsAFMlJOXES3P hPYcatjbbjzT6R2rI9GF6U5+jmYBeJbCp8ofkMNuSpwSZS0gN9augcDwop9T8D1zIFb1 AHFhKcciQPXTMu9i0MjLprLbyoy32Uxo7EycZ4seWHtlNaCZ3AJub1uv4xCFqUyZR9n3 79Qg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@marcusspencer.xyz header.s=protonmail header.b=kTgNo0k5; 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=marcusspencer.xyz Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5c42bcaab88si1841734a12.486.2024.09.14.22.34.10; Sat, 14 Sep 2024 22:34:10 -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=@marcusspencer.xyz header.s=protonmail header.b=kTgNo0k5; 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=marcusspencer.xyz Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CB6A68D9AA; Sun, 15 Sep 2024 08:17:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40110.protonmail.ch (mail-40110.protonmail.ch [185.70.40.110]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76F3568C886 for ; Sun, 15 Sep 2024 08:17:10 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marcusspencer.xyz; s=protonmail; t=1726377428; x=1726636628; bh=+DoPjCx01VV2MzNkkCorFI/F4Z2Vm7CJ2zda2+o5HSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=kTgNo0k55fEfc4vzZ9has2h67trr9is3W2UlFWzZ2KZDoOjVaJiUJUuKVQZzefsRm 72MTGQVJUfM0JNoVuWxTaNOECjFk8C0vPTZ7NxVTNPCRVTOT5bGqkCBLi2L94PlZxL oRdxs4KrgfzhefPFgYqna5I3BrbH/sRdfhFxK12bAB/Q6ABPBP8jngKcBSDpwDbskb fwZ0d91n8NW++7KduvoRNL9qpcPqgRedeXCopMYsIx/76EftpZ4GDXkxy8nc6Uab1K Jq4qButDmfQYtE9u/hmnyHVtesL2KQcNBbxFwutyUwCsgEgOKqS90weZDtFipKNyvD gelxyymIsSaHA== X-Pm-Submission-Id: 4X5x9t1GMDz4wwdX From: Marcus B Spencer To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Sep 2024 00:15:40 -0500 Message-ID: <20240915051656.1321991-1-marcus@marcusspencer.xyz> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/img2enc: seperate getting frame filename 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: Marcus B Spencer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dIMf5UahHVa9 Seperate the action of getting the frame filename in write_packet into the function ff_img_get_frame_filename. This for img2-like muxers that need this functionality. Signed-off-by: Marcus B Spencer --- libavformat/img2.h | 5 +++++ libavformat/img2enc.c | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libavformat/img2.h b/libavformat/img2.h index e98902c96f..292b90bdbf 100644 --- a/libavformat/img2.h +++ b/libavformat/img2.h @@ -76,4 +76,9 @@ extern const AVOption ff_img_options[]; int ff_img_read_header(AVFormatContext *s1); int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt); + +int ff_img_get_frame_filename(AVFormatContext *s, char *filename, + size_t filename_len, int start_img_number, + int img_number); + #endif diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index 526a11e5ee..ec2941e293 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -137,6 +137,28 @@ static int write_and_close(AVFormatContext *s, AVIOContext **pb, const unsigned return ff_format_io_close(s, pb); } +int ff_img_get_frame_filename(AVFormatContext *s, char *filename, + size_t filename_len, int start_img_number, + int img_number) +{ + if (av_get_frame_filename2(filename, filename_len, s->url, + img_number, + AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) { + if (img_number == start_img_number) { + av_log(s, AV_LOG_WARNING, "The specified filename '%s' does not contain an image sequence pattern or a pattern is invalid.\n", s->url); + av_log(s, AV_LOG_WARNING, + "Use a pattern such as %%03d for an image sequence or " + "use the -update option (with -frames:v 1 if needed) to write a single image.\n"); + av_strlcpy(filename, s->url, filename_len); + } else { + av_log(s, AV_LOG_ERROR, "Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?\n"); + return AVERROR(EINVAL); + } + } + + return 0; +} + static int write_packet(AVFormatContext *s, AVPacket *pkt) { VideoMuxData *img = s->priv_data; @@ -164,20 +186,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames."); return AVERROR(EINVAL); } - } else if (av_get_frame_filename2(filename, sizeof(filename), s->url, - img->img_number, - AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) { - if (img->img_number == img->start_img_number) { - av_log(s, AV_LOG_WARNING, "The specified filename '%s' does not contain an image sequence pattern or a pattern is invalid.\n", s->url); - av_log(s, AV_LOG_WARNING, - "Use a pattern such as %%03d for an image sequence or " - "use the -update option (with -frames:v 1 if needed) to write a single image.\n"); - av_strlcpy(filename, s->url, sizeof(filename)); - } else { - av_log(s, AV_LOG_ERROR, "Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?\n"); - return AVERROR(EINVAL); - } - } + } else if ((ret = ff_img_get_frame_filename(s, filename, sizeof(filename), + img->start_img_number, + img->img_number)) < 0) + return ret; + for (i = 0; i < 4; i++) { av_dict_copy(&options, img->protocol_opts, 0); snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename);