Я попытался использовать swr_convert для изменения частоты аудиокадров с 44 100 Гц до 16 000 Гц, обрабатывая кадры один за другим в целях тестирования. Однако результирующий звук выглядит смешанным с шумом.
Следующий код показывает, как выполнить повторную выборку одного аудиокадра:
AVFrame* output_frame = av_frame_alloc();
if (!output_frame) {
throw std::runtime_error("Failed to allocate output AVFrame");
}
AVRational output_time_base = {1, output_sample_rate};
SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate SwrContext");
}
av_opt_set_int(swr_ctx, "in_sample_fmt", aframe->format, 0);
av_opt_set_int(swr_ctx, "out_sample_fmt", output_format, 0);
av_opt_set_int(swr_ctx, "in_channel_layout", aframe->channel_layout, 0);
av_opt_set_int(swr_ctx, "out_channel_layout", output_channel_layout, 0);
av_opt_set_int(swr_ctx, "in_sample_rate", aframe->sample_rate, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", output_sample_rate, 0);
if (swr_init(swr_ctx) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to initialize SwrContext");
}
output_frame->format = output_format;
output_frame->channel_layout = output_channel_layout;
output_frame->sample_rate = output_sample_rate;
int64_t delay = swr_get_delay(swr_ctx, aframe->sample_rate);
output_frame->nb_samples = av_rescale_rnd(
delay + aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);
output_frame->nb_samples = av_rescale_rnd(
aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);
if (av_frame_get_buffer(output_frame, 0) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate buffer for output AVFrame");
}
int ret = swr_convert(swr_ctx,
output_frame->data, output_frame->nb_samples,
(const uint8_t**)aframe->data, aframe->nb_samples);
if (ret < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to resample audio data");
}
if (aframe->pts != AV_NOPTS_VALUE) {
output_frame->pts = av_rescale_q(aframe->pts, {1, aframe->sample_rate}, output_time_base);
} else {
output_frame->pts = AV_NOPTS_VALUE;
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ificant-no
Использование swr_convert для повторной выборки аудиокадров привело к получению звука со значительным шумом. ⇐ C++
Программы на C++. Форум разработчиков
1736307048
Anonymous
Я попытался использовать swr_convert для изменения частоты аудиокадров с 44 100 Гц до 16 000 Гц, обрабатывая кадры один за другим в целях тестирования. Однако результирующий звук выглядит смешанным с шумом.
Следующий код показывает, как выполнить повторную выборку одного аудиокадра:
AVFrame* output_frame = av_frame_alloc();
if (!output_frame) {
throw std::runtime_error("Failed to allocate output AVFrame");
}
AVRational output_time_base = {1, output_sample_rate};
SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate SwrContext");
}
av_opt_set_int(swr_ctx, "in_sample_fmt", aframe->format, 0);
av_opt_set_int(swr_ctx, "out_sample_fmt", output_format, 0);
av_opt_set_int(swr_ctx, "in_channel_layout", aframe->channel_layout, 0);
av_opt_set_int(swr_ctx, "out_channel_layout", output_channel_layout, 0);
av_opt_set_int(swr_ctx, "in_sample_rate", aframe->sample_rate, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", output_sample_rate, 0);
if (swr_init(swr_ctx) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to initialize SwrContext");
}
output_frame->format = output_format;
output_frame->channel_layout = output_channel_layout;
output_frame->sample_rate = output_sample_rate;
int64_t delay = swr_get_delay(swr_ctx, aframe->sample_rate);
output_frame->nb_samples = av_rescale_rnd(
delay + aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);
output_frame->nb_samples = av_rescale_rnd(
aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);
if (av_frame_get_buffer(output_frame, 0) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate buffer for output AVFrame");
}
int ret = swr_convert(swr_ctx,
output_frame->data, output_frame->nb_samples,
(const uint8_t**)aframe->data, aframe->nb_samples);
if (ret < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to resample audio data");
}
if (aframe->pts != AV_NOPTS_VALUE) {
output_frame->pts = av_rescale_q(aframe->pts, {1, aframe->sample_rate}, output_time_base);
} else {
output_frame->pts = AV_NOPTS_VALUE;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79337907/using-swr-convert-to-resample-audio-frames-resulted-in-audio-with-significant-no[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия