Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] release/8.0: libavfilter: backporting bugfix for whisper (PR #20722)
Date: Mon, 20 Oct 2025 05:00:53 -0000
Message-ID: <176093645488.62.5186839454505248468@bf907ddaa564> (raw)

PR #20722 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20722
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20722.patch


>From bb65f51fce43d970e94eeef12dd20d3beabb559e Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
Date: Fri, 15 Aug 2025 20:39:49 +0800
Subject: [PATCH 1/5] avfilter/af_whisper: fix broken output for multibyte
 character

text + 1 can break a multibyte character, e.g., Chinese in UTF-8.
There is no space at the beginning in this case.

(cherry picked from commit 1d06e8ddcd8c14232d0a3c2b1c21e50b232549b4)
---
 libavfilter/af_whisper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_whisper.c b/libavfilter/af_whisper.c
index 186b624504..bd145d6d1d 100644
--- a/libavfilter/af_whisper.c
+++ b/libavfilter/af_whisper.c
@@ -215,7 +215,9 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
 
     for (int i = 0; i < n_segments; ++i) {
         const char *text = whisper_full_get_segment_text(wctx->ctx_wsp, i);
-        char *text_cleaned = av_strireplace(text + 1, "[BLANK_AUDIO]", "");
+        if (av_isspace(text[0]))
+            text++;
+        char *text_cleaned = av_strireplace(text, "[BLANK_AUDIO]", "");
 
         if (av_strnlen(text_cleaned, 1) == 0) {
             av_freep(&text_cleaned);
-- 
2.49.1


>From b784c3eb6d4f989b9e78f2d93e1b4d73018a1f4f Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg@gyani.pro>
Date: Sat, 16 Aug 2025 16:12:10 +0530
Subject: [PATCH 2/5] avfilter/whisper: correct option formatting

(cherry picked from commit 7df92712723dee0ace3596684a90282c0e12a8ef)
---
 libavfilter/af_whisper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_whisper.c b/libavfilter/af_whisper.c
index bd145d6d1d..385180b4ed 100644
--- a/libavfilter/af_whisper.c
+++ b/libavfilter/af_whisper.c
@@ -430,7 +430,8 @@ static int query_formats(const AVFilterContext *ctx,
 #define HOURS 3600000000
 
 static const AVOption whisper_options[] = {
-    { "model", "Path to the whisper.cpp model file", OFFSET(model_path), AV_OPT_TYPE_STRING,.flags = FLAGS }, { "language", "Language for transcription ('auto' for auto-detect)", OFFSET(language), AV_OPT_TYPE_STRING, {.str = "auto"}, .flags = FLAGS },
+    { "model", "Path to the whisper.cpp model file", OFFSET(model_path), AV_OPT_TYPE_STRING,.flags = FLAGS },
+    { "language", "Language for transcription ('auto' for auto-detect)", OFFSET(language), AV_OPT_TYPE_STRING, {.str = "auto"}, .flags = FLAGS },
     { "queue", "Audio queue size", OFFSET(queue), AV_OPT_TYPE_DURATION, {.i64 = 3000000}, 20000, HOURS, .flags = FLAGS },
     { "use_gpu", "Use GPU for processing", OFFSET(use_gpu), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, .flags = FLAGS },
     { "gpu_device", "GPU device to use", OFFSET(gpu_device), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, .flags = FLAGS },
-- 
2.49.1


>From adc819773ba98db56bbff0e4da8187e6ed3d7db9 Mon Sep 17 00:00:00 2001
From: Vittorio Palmisano <vpalmisano@gmail.com>
Date: Fri, 29 Aug 2025 11:32:20 +0200
Subject: [PATCH 3/5] avfilter/af_whisper: fix srt file format

The SRT file format requires commas in the time string, not periods.

(cherry picked from commit 73d411c399df4abe2750b611fc8381979fcbafc6)
---
 libavfilter/af_whisper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/af_whisper.c b/libavfilter/af_whisper.c
index 385180b4ed..663fe446bb 100644
--- a/libavfilter/af_whisper.c
+++ b/libavfilter/af_whisper.c
@@ -246,7 +246,7 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
             if (!av_strcasecmp(wctx->format, "srt")) {
                 buf =
                     av_asprintf
-                    ("%d\n%02ld:%02ld:%02ld.%03ld --> %02ld:%02ld:%02ld.%03ld\n%s\n\n",
+                    ("%d\n%02ld:%02ld:%02ld,%03ld --> %02ld:%02ld:%02ld,%03ld\n%s\n\n",
                      wctx->index, start_t / 3600000,
                      (start_t / 60000) % 60, (start_t / 1000) % 60,
                      start_t % 1000, end_t / 3600000, (end_t / 60000) % 60,
-- 
2.49.1


>From d8049e01d79df68520371fc8e0a93c5dd786df06 Mon Sep 17 00:00:00 2001
From: Vittorio Palmisano <vpalmisano@gmail.com>
Date: Sun, 21 Sep 2025 15:19:51 +0200
Subject: [PATCH 4/5] avfilter/af_whisper: fix int64 printf format

Use PRId64 for printing int64_t values in the SRT output.

(cherry picked from commit f18b1e23890c1179d41c07f2c195c56fb90ea072)
---
 libavfilter/af_whisper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavfilter/af_whisper.c b/libavfilter/af_whisper.c
index 663fe446bb..90b2fc89a0 100644
--- a/libavfilter/af_whisper.c
+++ b/libavfilter/af_whisper.c
@@ -150,7 +150,7 @@ static int init(AVFilterContext *ctx)
     }
 
     av_log(ctx, AV_LOG_INFO,
-           "Whisper filter initialized: model: %s lang: %s queue: %ld ms\n",
+           "Whisper filter initialized: model: %s lang: %s queue: %" PRId64 " ms\n",
            wctx->model_path, wctx->language, wctx->queue / 1000);
 
     return 0;
@@ -194,7 +194,7 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
     const float duration = (float) samples / WHISPER_SAMPLE_RATE;
 
     av_log(ctx, AV_LOG_INFO,
-           "run transcription at %ld ms, %d/%d samples (%.2f seconds)...\n",
+           "run transcription at %" PRId64 " ms, %d/%d samples (%.2f seconds)...\n",
            timestamp_ms, samples, wctx->audio_buffer_fill_size, duration);
 
     struct whisper_full_params params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
@@ -228,7 +228,7 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
         const int64_t t0_ms = whisper_full_get_segment_t0(wctx->ctx_wsp, i) * 10;
         const int64_t t1_ms = whisper_full_get_segment_t1(wctx->ctx_wsp, i) * 10;
 
-        av_log(ctx, AV_LOG_DEBUG, "  [%ld-%ld%s]: \"%s\"\n",
+        av_log(ctx, AV_LOG_DEBUG, "  [%" PRId64 "-%" PRId64 "%s]: \"%s\"\n",
                timestamp_ms + t0_ms, timestamp_ms + t1_ms, turn ? " (turn)" : "", text_cleaned);
 
         if (segments_text) {
@@ -246,13 +246,13 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
             if (!av_strcasecmp(wctx->format, "srt")) {
                 buf =
                     av_asprintf
-                    ("%d\n%02ld:%02ld:%02ld,%03ld --> %02ld:%02ld:%02ld,%03ld\n%s\n\n",
+                    ("%d\n%02" PRId64 ":%02" PRId64 ":%02" PRId64 ",%03" PRId64 " --> %02" PRId64 ":%02" PRId64 ":%02" PRId64 ",%03" PRId64 "\n%s\n\n",
                      wctx->index, start_t / 3600000,
                      (start_t / 60000) % 60, (start_t / 1000) % 60,
                      start_t % 1000, end_t / 3600000, (end_t / 60000) % 60,
                      (end_t / 1000) % 60, end_t % 1000, text_cleaned);
             } else if (!av_strcasecmp(wctx->format, "json")) {
-                buf = av_asprintf("{\"start\":%ld,\"end\":%ld,\"text\":\"%s\"}\n", start_t, end_t, text_cleaned);
+                buf = av_asprintf("{\"start\":%" PRId64 ",\"end\":%" PRId64 ",\"text\":\"%s\"}\n", start_t, end_t, text_cleaned);
             } else
                 buf = av_strdup(text_cleaned);
 
-- 
2.49.1


>From 7cbc26267b6968eb2b8cc5f70e3603b6ee9b2101 Mon Sep 17 00:00:00 2001
From: Vittorio Palmisano <vpalmisano@gmail.com>
Date: Sun, 21 Sep 2025 15:33:17 +0200
Subject: [PATCH 5/5] avfilter/af_whisper: fix srt index

The srt index should be incremented for each segment.

(cherry picked from commit 9970dc32bf85628e53ed0952d87d384080d8976e)
---
 libavfilter/af_whisper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/af_whisper.c b/libavfilter/af_whisper.c
index 90b2fc89a0..3c0eba42f0 100644
--- a/libavfilter/af_whisper.c
+++ b/libavfilter/af_whisper.c
@@ -251,6 +251,8 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
                      (start_t / 60000) % 60, (start_t / 1000) % 60,
                      start_t % 1000, end_t / 3600000, (end_t / 60000) % 60,
                      (end_t / 1000) % 60, end_t % 1000, text_cleaned);
+
+                wctx->index++;
             } else if (!av_strcasecmp(wctx->format, "json")) {
                 buf = av_asprintf("{\"start\":%" PRId64 ",\"end\":%" PRId64 ",\"text\":\"%s\"}\n", start_t, end_t, text_cleaned);
             } else
@@ -265,8 +267,6 @@ static void run_transcription(AVFilterContext *ctx, AVFrame *frame, int samples)
         av_freep(&text_cleaned);
     }
 
-    wctx->index++;
-
     AVDictionary **metadata = &frame->metadata;
     if (metadata && segments_text) {
         av_dict_set(metadata, "lavfi.whisper.text", segments_text, 0);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-10-20  5:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176093645488.62.5186839454505248468@bf907ddaa564 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git