FFMpeg:从AV_SAMPLE_FMT_S16到AV_SAMPLE_FMT_FLTP的重新采样将比特率除以2
FFMpeg: Resampling from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_FLTP divides bitrate by 2
我对FFMpeg非常陌生,目前正在尝试将音频数据从PCM AV_SAMPLE_FMT_S16格式转换为Mp3 AV_SAMPLE_FMT_FLTP格式。
为此,我使用来自FFMpeg 的AudioResampleContext
av_opt_set_int( audioResampleCtx, "in_sample_fmt", m_aplayer->aCodecCtx->sample_fmt, 0);
av_opt_set_int( audioResampleCtx, "in_sample_rate", m_aplayer->aCodecCtx->sample_rate, 0);
av_opt_set_int( audioResampleCtx, "in_channels", m_aplayer->aCodecCtx->channels,0);
av_opt_set_int( audioResampleCtx, "out_channel_layout", audioCodecCtx->channel_layout, 0);
av_opt_set_int( audioResampleCtx, "out_sample_fmt", audioCodecCtx->sample_fmt, 0);
av_opt_set_int( audioResampleCtx, "out_sample_rate", audioCodecCtx->sample_rate, 0);
av_opt_set_int( audioResampleCtx, "out_channels", audioCodecCtx->channels, 0);
转换效果很好,因为我可以听我的mp3文件,但问题是我的原始文件长60秒,输出的mp3文件只有34秒。我能听到它被加速了,就像有什么东西加速了声音一样。当用FFMpeg查找信息时,我发现比特率刚刚从128kbps上升到64kbps。
编辑:为了完成更多信息,我想用mp3编解码器压缩一些原始音频数据,并使用output.mp3输出格式。原始音频数据采样格式为AV_sample_FMT_S16,mp3编解码器支持的采样格式为FLTP(或S16P)。因此,我正在进行从AV_sample_FMT_S16到AV_sample_FMT_FLTP的示例格式转换,但它缺少一半的数据。
有人能帮我吗?我知道我错过了一些非常简单的东西,但我就是不知道是什么。
编辑:2以下是执行重新采样的代码(即将fromhttps://github.com/martin-steghoefer/debian-karlyriceditor/blob/master/src/ffmpegvideoencoder.cpp)。音频源不是AVFrame,而是一个字节数组:
// Resample the input into the audioSampleBuffer until we proceed the whole decoded data
if ( (err = avresample_convert( audioResampleCtx,
NULL,
0,
0,
audioFrame->data,
0,
audioFrame->nb_samples )) < 0 )
{
qWarning( "Error resampling decoded audio: %d", err );
return -1;
}
if( avresample_available( audioResampleCtx ) >= audioFrame->nb_samples )
{
// Read a frame audio data from the resample fifo
if ( avresample_read( audioResampleCtx, audioFrame->data, audioFrame->nb_samples ) != audioFrame->nb_samples )
{
qWarning( "Error reading resampled audio: %d", err );
return -1;
}
//Init packet, do the encoding and write data to file
谢谢你的帮助!
1)如果音频播放速度快,则采样率可能不正确。检查重采样器的输入采样率是否与解码器中的相同。AND输出采样率与编码器中使用的采样率相同。
2) 平面与非平面只是将样本保存在缓冲区中的一种方式(检查:AV_SAMPLE_FMT_S16P和AV_SAMPLE_FMT_S16之间有什么区别?)。你不应该错过飞机。
3) 由于输出较短:提醒刷新解码器、重采样器、编码器。所有这些都缓冲数据。当所有数据被馈送到处理器链(d-r-e)时,您需要刷新每个组件,并在下一阶段处理刷新的数据(刷新解码器->重采样->编码;刷新重采样器->编码;清除编码器)。
你现在找到解决问题的方法了吗?我正在为类似的问题而挣扎。当从S16->FLTP转换时,我得到一个ffmpeg错误:"处理器:psymodel.c:576:calc_energy:Assertion`el>=0'失败。"
- boost日志文件无法创建sample.log文件
- C++ std::d iscrete_distribution vs. sample() 在 R 中的行为
- Luci 无法启动请求的 CGI 程序:/www/cgi-bin/sample.cgi:执行错误
- 以简单格式"c:filessample.txt"从用户读取文件路径
- `sTD :: sample()的输出序列是否遵循输入序列的顺序
- 我想在Android中将音频服务器(/frameworks/av/media/audioserver)构建为64位,但无法启动
- 如何在 的容器上使用 std::sample 返回指针容器 <T*><T>?
- 运行时检查失败 #2 - 变量周围的堆栈'sample'已损坏
- 具有 SVM、EM 和其他具有"weights per sample"的方法的库,例如
- Sample Grabber返回的IMediaSample具有意外的缓冲区大小
- OpenCl:sample float4程序-分段错误(核心转储)
- Sample.exe中0x7537812f处未处理的异常:0xC0020001:字符串绑定无效
- 全局变量析构函数中的 ctrl-c 上的 AV
- BlueZ D-Bus C or C++ Sample
- 为什么"std::sample"将"UniformRandomBitGenerator"作为&&?
- Boost随机样本,如python random.sample
- F-35飞行器C++编码标准AV规则6的澄清;文件.编号2RDU00001修订版C
- Visual Studio没有为KinectBridgeWithOpenCVBasics D2D c++ Sample使
- 在dll中使用std::stringstream时的AV