From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id C35A74936A for ; Fri, 17 Oct 2025 08:04:03 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'qzM6F53/Wvcx0ZEd9W/2IfcFBfB23q0giNAVKdt2d1c=', expected b'luXdz93RZW70RY0Msf7S3zeI5Bu6A4jx4bZ8Fq0291Y=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1760688223; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=qzM6F53/Wvcx0ZEd9W/2IfcFBfB23q0giNAVKdt2d1c=; b=Mtb5rhuk0FU3rNg8YayesQ3Xj31qqsS9Cu3yweM4FgU7CIkIGYd8miT+eGor32chktA5i M2AaD+eUvObxoevzcc9qsP5i/3iTzAhEm2Jad7B2o+V5qQX1P6wkG0ZcDldnZlPrIFq4I2O GkSD//tqkq+sqRGz+caNaiCRukCPNAQWDkygd+jIhTbXaogFoNu5hFzJAIjt4a/G0kn2B8z V1nsjCovXCjqFg/nx5OLnhIUrgj66xgad737wnnDX1Vnk1IzMYA+rPKETu+2GKAuA3nW1C4 3D7I0t20si+cVy1iUZkbmxnzNsFig2H40iQvDp2kwBcS4IdRCCoK1zkpREcw== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BAD2968F4DC; Fri, 17 Oct 2025 11:03:43 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1760688205; b=PbNwKXi60cc4Ht0RHOM6z2VnqCyDw1mXDaXLIGiWIdZAEZ9cE0bqo8bx9mfnVaGRlMAd5 fyE1Ksm3uo+pmDzmGrbarUF+ZIt3RME7YKovO24zOYCFzSr8ENwYwaXCgDy++GHvL7dyxri f+8j6uoBRp3Mil1OYfzJM1SzoOjo/vHTYi0225mn3CamwwDJklZwmMsaEWNEN15HVz0Tjwg gXrDXhFBAIWaw0D3OvV/XzcYSX9U3fKeg5YTmO3fcjqswyw7Gvp5KI6kilyP8U7APFXNUqr 1u6SeSNnNwafER2JTFx8c94PQYqBN9t1wYTOJUMAZNsH8xBLxY/CNrHMaa7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1760688205; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=DlxrLbvYBqZAJV+wn1P3QQLe4MwqehrU1+U2rehI91o=; b=UJEb2QuVRGyF5jSaBkRqe16ffcFqYslLgdLdTxaxZlCsFimKRlHzsVGxYXSujiLK/ZQZJ 7sNF2KOabSJfD/dPg9Ihwi9rHB56w44a/LriUUIxygbGwOAokEG5wsiCwpTO08F8EUXMgxg G6O+j24MEeyC/RcpH/cSZp/kAUro94qZZYeo4+VxpvQg/au0Mc/gHRFlXUWLGVsRTXgJ+Nd Fm3pWjKWituxQuad9cDpSNTI6Y3ENWfd719jT2lotzM1VzWG3K0qJFiHyx8wON1j0B/K6f8 5OTmwvPPWgZr2YbpugAfW6cthwcogY7Ng/xNgsLwJSXnVdEv/pUONZBv4sPw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1760688198; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=luXdz93RZW70RY0Msf7S3zeI5Bu6A4jx4bZ8Fq0291Y=; b=pO1isiSGBuW4KKqM4SwS+ECRtLLhPvxLKiwkr/xa0i9EnGtV0dld8rkoEtQFs6UMEc1Ub kMNInPb0iNfzhb5wuwz6diiEXmeP0EiOz06XQHjowLGblHYhUdy7PFvto4thgNcWtLIZGE5 V2t2wT6CCm5CANXeJw2hfLk4l4IDzdi9msvxh7z1sCw1bpdElbLVblOOWAqf+78ewNlQgN4 KXLbK0tNL6frBBqC9TdtpreeNQDfVTOk++pD4dX3CR1tIo6uHflbvE09Gu13GxDhmNJEnfz Pr2KuNADEaJwpKeKHs2WTn/DPqAiUgFxHsIFD6S/ahXB5ncOJLmq+Ev0D8Uw== Received: from be883b0c11cf (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 23F9468D553 for ; Fri, 17 Oct 2025 11:03:18 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Oct 2025 08:03:17 -0000 Message-ID: <176068819830.62.6170982165462280074@bf907ddaa564> Message-ID-Hash: YOQVTVUT7IBX527XXJESBN2HGXLNNXDR X-Message-ID-Hash: YOQVTVUT7IBX527XXJESBN2HGXLNNXDR X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avfilter: add raw PCM dump between AVFilter links (PR #20715) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: yibofang via ffmpeg-devel Cc: yibofang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20715 opened by yibofang URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20715 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20715.patch This patch adds the ability to dump raw PCM audio data between AVFilter links. It introduces a configure-time option `--dumpdir=PATH` to control the output directory of dump files (default: /tmp/). This feature is helpful for debugging filter behavior and verifying audio processing. Two filter commands are added: - dump_raw_start - dump_raw_stop The PCM files are written in the format: srcname-dstname-.pcm. Supports both packed and planar formats. File descriptors are automatically managed. Works only on audio links. Example usage: avfilter_process_command(filter, "dump_raw_start", "volume", NULL, 0, 0); Signed-off-by: YiboFang >>From 5fe14bede287bd3a056a953b27d41719c71b86a0 Mon Sep 17 00:00:00 2001 From: YiboFang Date: Wed, 27 Aug 2025 09:37:24 +0800 Subject: [PATCH] avfilter: add raw PCM dump between AVFilter links This patch adds the ability to dump raw PCM audio data between AVFilter links. It introduces a configure-time option `--dumpdir=PATH` to control the output directory of dump files (default: /tmp/). This feature is helpful for debugging filter behavior and verifying audio processing. Two filter commands are added: - dump_raw_start - dump_raw_stop The PCM files are written in the format: srcname-dstname-.pcm. Supports both packed and planar formats. File descriptors are automatically managed. Works only on audio links. Example usage: avfilter_process_command(filter, "dump_raw_start", "volume", NULL, 0, 0); Signed-off-by: YiboFang --- configure | 7 +++ doc/filters.texi | 36 ++++++++++++++ libavfilter/avfilter.c | 110 +++++++++++++++++++++++++++++++++++++++++ libavfilter/avfilter.h | 4 ++ 4 files changed, 157 insertions(+) diff --git a/configure b/configure index 7828381b5d..79ca73b303 100755 --- a/configure +++ b/configure @@ -531,6 +531,7 @@ Developer options (useful when working on FFmpeg itself): --disable-ptx-compression don't compress CUDA PTX code even when possible --disable-resource-compression don't compress resources even when possible --disable-version-tracking don't include the git/release version in the build + --dumpdir=PATH location of pcm dump files to save. NOTE: Object files are built at the place where configure is launched. EOF @@ -2738,6 +2739,7 @@ PATHS_LIST=" prefix shlibdir install_name_dir + dumpdir " CMDLINE_SET=" @@ -4223,6 +4225,9 @@ incdir_default='${prefix}/include' libdir_default='${prefix}/lib' mandir_default='${prefix}/share/man' +# runtime path +dumpdir_default='/tmp/' + # toolchain ar_default="ar" cc_default="gcc" @@ -8327,6 +8332,7 @@ DOCDIR=\$(DESTDIR)$docdir MANDIR=\$(DESTDIR)$mandir PKGCONFIGDIR=\$(DESTDIR)$pkgconfigdir INSTALL_NAME_DIR=$install_name_dir +DUMPDIR=$dumpdir SRC_PATH=$source_path SRC_LINK=$source_link ifndef MAIN_MAKEFILE @@ -8479,6 +8485,7 @@ cat > $TMPH <-.pcm} and will be overwritten if it already exists. +@end table + @section agraphmonitor See @ref{graphmonitor}. diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 169c2baa42..5eaff93b87 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include + #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" @@ -195,6 +198,66 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, return 0; } +static av_cold void link_uninit_dump_pcm(AVFilterLink *link, int stop) +{ + if (link->dump_pcm_fds) { + int i; + for (i = 0; i < link->nb_dump_pcm_fds; i++) { + if (link->dump_pcm_fds[i]) + close(link->dump_pcm_fds[i]); + } + av_free(link->dump_pcm_fds); + link->dump_pcm_fds = NULL; + link->nb_dump_pcm_fds = 0; + } + + if (stop) + link->dump_pcm = 0; +} + +static av_cold int link_init_dump_pcm(AVFilterLink *link) +{ + char path[4096]; + int fd, i; + + link->nb_dump_pcm_fds = av_sample_fmt_is_planar(link->format)? link->ch_layout.nb_channels : 1; + link->dump_pcm_fds = av_malloc_array(link->nb_dump_pcm_fds, sizeof(int)); + if (!link->dump_pcm_fds) + return AVERROR(ENOMEM); + + for (i = 0; i < link->nb_dump_pcm_fds; i++) { + snprintf(path, sizeof(path), FFMPEG_DUMPDIR"%.16s-%.8s-%d.pcm", link->src->name, link->dst->name, i); + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) { + link_uninit_dump_pcm(link, 1); + return AVERROR(errno); + } + link->dump_pcm_fds[i] = fd; + } + + return 0; +} + +static int filter_set_dump_pcm(AVFilterContext *filter, const char *target, int set) +{ + int i; + + for (i = 0; i < filter->nb_outputs; i++) { + AVFilterLink *link = filter->outputs[i]; + if (!target || !strcmp(link->dst->name, target)) { + if (set) { + link->dump_pcm = 1; + } else + link_uninit_dump_pcm(link, 1); + + if (target) + return 0; + } + } + + return target ? AVERROR(EINVAL) : 0; +} + static void link_free(AVFilterLink **link) { FilterLinkInternal *li; @@ -208,6 +271,8 @@ static void link_free(AVFilterLink **link) av_channel_layout_uninit(&(*link)->ch_layout); av_frame_side_data_free(&(*link)->side_data, &(*link)->nb_side_data); + link_uninit_dump_pcm(*link, 1); + av_buffer_unref(&li->l.hw_frames_ctx); av_freep(link); @@ -620,6 +685,10 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha if (res == local_res) av_log(filter, AV_LOG_INFO, "%s", res); return 0; + }else if(!strcmp(cmd, "dump_raw_start")) { + return filter_set_dump_pcm(filter, arg, 1); + }else if(!strcmp(cmd, "dump_raw_stop")) { + return filter_set_dump_pcm(filter, arg, 0); }else if(!strcmp(cmd, "enable")) { return set_enable_expr(fffilterctx(filter), arg); }else if (fffilter(filter->filter)->process_command) { @@ -1064,6 +1133,41 @@ fail: return ret; } +static int link_dump_frame(AVFilterLink *link, AVFrame *frame) +{ + int samples_size, ret; + + if (!link->dump_pcm_fds) { + ret = link_init_dump_pcm(link); + if (ret < 0) + return ret; + } + + samples_size = av_get_bytes_per_sample(frame->format) * frame->nb_samples; + if (av_sample_fmt_is_planar(frame->format)) { + int i; + for (i = 0; i < link->nb_dump_pcm_fds && i < frame->ch_layout.nb_channels; i++) { + if (i < AV_NUM_DATA_POINTERS) { + ret = write(link->dump_pcm_fds[i], frame->data[i], samples_size); + } else + ret = write(link->dump_pcm_fds[i], frame->extended_data[i - AV_NUM_DATA_POINTERS], samples_size); + + if (ret < 0) + goto err; + } + } else { + ret = write(link->dump_pcm_fds[0], frame->data[0], samples_size * frame->ch_layout.nb_channels); + if (ret < 0) + goto err; + + } + + return 0; +err: + link_uninit_dump_pcm(link, 1); + return AVERROR(errno); +} + int ff_filter_frame(AVFilterLink *link, AVFrame *frame) { FilterLinkInternal * const li = ff_link_internal(link); @@ -1104,6 +1208,12 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) link->time_base); } + if (link->dump_pcm && link->type == AVMEDIA_TYPE_AUDIO) { + ret = link_dump_frame(link, frame); + if (ret < 0) + av_log(link->dst, AV_LOG_ERROR, "Dump pcm files failed with %d\n", ret); + } + li->frame_blocked_in = li->frame_wanted_out = 0; li->l.frame_count_in++; li->l.sample_count_in += frame->nb_samples; diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 02b58c42c2..5d86874b53 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -421,6 +421,10 @@ struct AVFilterLink { int sample_rate; ///< samples per second AVChannelLayout ch_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h) + int dump_pcm; ///< flag to dump pcm + int *dump_pcm_fds; ///< dump files + unsigned nb_dump_pcm_fds; ///< number of dump file + /** * Define the time base used by the PTS of the frames/samples * which will pass through this link. -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org