Spaces:
Sleeping
Sleeping
examples : add FFmpeg v7.0 support to ffmpeg-transcode.cpp (#3038)
Browse filesFFmpeg introduced a new channel layout API that uses `AVChannelLayout`
interface in v6.0. It subsequently dropped the old bitmask-based API
in v7.0.
This updates decode_audio() to support the new channel layout API,
so that we can compile `whisper-cli` and `whisper-server` with FFmpeg
v7.0 or later.
Tested on on Ubuntu 24.10 with FFmpeg v7.0.2.
Signed-off-by: Fujimoto Seiji <[email protected]>
examples/ffmpeg-transcode.cpp
CHANGED
|
@@ -249,6 +249,20 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
|
| 249 |
/* prepare resampler */
|
| 250 |
swr = swr_alloc();
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
av_opt_set_int(swr, "in_channel_count", codec->channels, 0);
|
| 253 |
av_opt_set_int(swr, "out_channel_count", 1, 0);
|
| 254 |
av_opt_set_int(swr, "in_channel_layout", codec->channel_layout, 0);
|
|
@@ -257,6 +271,7 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
|
| 257 |
av_opt_set_int(swr, "out_sample_rate", WAVE_SAMPLE_RATE, 0);
|
| 258 |
av_opt_set_sample_fmt(swr, "in_sample_fmt", codec->sample_fmt, 0);
|
| 259 |
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
|
|
|
|
| 260 |
|
| 261 |
swr_init(swr);
|
| 262 |
if (!swr_is_initialized(swr)) {
|
|
|
|
| 249 |
/* prepare resampler */
|
| 250 |
swr = swr_alloc();
|
| 251 |
|
| 252 |
+
#if LIBAVCODEC_VERSION_MAJOR > 60
|
| 253 |
+
AVChannelLayout in_ch_layout = codec->ch_layout;
|
| 254 |
+
AVChannelLayout out_ch_layout = AV_CHANNEL_LAYOUT_MONO;
|
| 255 |
+
|
| 256 |
+
/* Set the source audio layout as-is */
|
| 257 |
+
av_opt_set_chlayout(swr, "in_chlayout", &in_ch_layout, 0);
|
| 258 |
+
av_opt_set_int(swr, "in_sample_rate", codec->sample_rate, 0);
|
| 259 |
+
av_opt_set_sample_fmt(swr, "in_sample_fmt", codec->sample_fmt, 0);
|
| 260 |
+
|
| 261 |
+
/* Convert it into 16khz Mono */
|
| 262 |
+
av_opt_set_chlayout(swr, "out_chlayout", &out_ch_layout, 0);
|
| 263 |
+
av_opt_set_int(swr, "out_sample_rate", WAVE_SAMPLE_RATE, 0);
|
| 264 |
+
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
|
| 265 |
+
#else
|
| 266 |
av_opt_set_int(swr, "in_channel_count", codec->channels, 0);
|
| 267 |
av_opt_set_int(swr, "out_channel_count", 1, 0);
|
| 268 |
av_opt_set_int(swr, "in_channel_layout", codec->channel_layout, 0);
|
|
|
|
| 271 |
av_opt_set_int(swr, "out_sample_rate", WAVE_SAMPLE_RATE, 0);
|
| 272 |
av_opt_set_sample_fmt(swr, "in_sample_fmt", codec->sample_fmt, 0);
|
| 273 |
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
|
| 274 |
+
#endif
|
| 275 |
|
| 276 |
swr_init(swr);
|
| 277 |
if (!swr_is_initialized(swr)) {
|