我对FFMpeg非常陌生,目前我正在尝试将音频数据从PCM AV_SAMPLE_FMT_S16格式转换为Mp3 AV_SAMPLE_FMT_FLTP格式。
为此,我使用了来自FFMpeg的FFMpeg
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查找信息时,我看到比特率刚刚从128 kbps上升到64 kbps。
编辑:要完成更多的信息,我想压缩一些原始音频数据与mp3编解码器,并有一个output.mp3输出格式。原始音频数据示例格式是AV_SAMPLE_FMT_S16,mp3编解码器支持的示例格式是FLTP (或S16P)。因此,我正在做一个从AV_SAMPLE_FMT_S16到AV_SAMPLE_FMT_FLTP的示例格式转换,但是它缺少一半的数据。
有人能帮我吗?我知道我错过了一些很简单的东西,但我就是想不出是什么。
编辑:2这里是执行重采样的代码(来自https://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
谢谢你的帮助!
发布于 2019-11-26 10:09:09
1)如果音频播放速度快,采样率可能不正确。检查重放器的输入采样率是否与解码器中的输入采样率相同。输出采样率与编码器中使用的相同。
2)平面与非平面只是在缓冲器中保存样本的一种方法( S16?)。你不应该错过飞机的。
3)由于输出较短:提醒冲洗解码器、重采样器、编码器。所有这些都是缓冲数据。当将所有数据输入到处理器链(D E)时,您需要刷新每个组件,并在下一阶段处理刷新的数据(flush解码器->重采样->编码;刷新重放->编码;刷新编码器)。
你找到解决问题的办法了吗?我正为一个类似的问题而挣扎。当从S16 -> FLTP转换时,我得到一个ffmpeg错误:"processor: psymodel.c:576: calc_energy:断言‘`el >= 0’失败。“
https://stackoverflow.com/questions/37159044
复制相似问题