ffmpeg 保存avcodec_decode_audio4解码后的PCM数据
来源:互联网 发布:淘宝助理模板数据包 编辑:程序博客网 时间:2024/06/06 03:54
我想要一个。M4A文件转换为原始PCM文件,这样我可以发挥它放回勇气。 按照AVCodecContext中它是一个44100赫兹的采样格式AV_SAMPLE_FMT_FLTP其中,据我了解,当avcodec_decode_audio4,我应该得到浮点值(每个通道一个)的两个数组。 我不确定的AVCodecContext中的bits_per_coded_sample=16的意义 不幸的是Audacity的播放结果回来,如果我有原来的轨道混在白噪声。 下面是我一直在做的示例代码。请注意,我还添加了轨道签名16位非交错数据(sample_format=AC_SAMPLE_FMT_S16P)的情况下 CodeGo.net,这Audacity的播放罚款。
int AudioDecoder::decode(std::string path){ const char* input_filename=path.c_str(); av_register_all(); AVFormatContext* container=avformat_alloc_context(); if(avformat_open_input(&container,input_filename,NULL,NULL)<0){ printf("Could not open file"); } if(avformat_find_stream_info(container, NULL)<0){ printf("Could not find file info"); } av_dump_format(container,0,input_filename,false); int stream_id=-1; int i; for(i=0;i<container->nb_streams;i++){ if(container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){ stream_id=i; break; } } if(stream_id==-1){ printf("Could not find Audio Stream"); } AVDictionary *metadata=container->metadata; AVCodecContext *ctx=container->streams[stream_id]->codec; AVCodec *codec=avcodec_find_decoder(ctx->codec_id); if(codec==NULL){ printf("cannot find codec!"); } if(avcodec_open2(ctx,codec,NULL)<0){ printf("Codec cannot be found"); } AVSampleFormat sfmt = ctx->sample_fmt; AVPacket packet; av_init_packet(&packet); AVFrame *frame = avcodec_alloc_frame(); int buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE+ FF_INPUT_BUFFER_PADDING_SIZE;; uint8_t buffer[buffer_size]; packet.data=buffer; packet.size =buffer_size; FILE *outfile = fopen("test.raw", "wb"); int len; int frameFinished=0; while(av_read_frame(container,&packet) >= 0) { if(packet.stream_index==stream_id) { //printf("Audio Frame read \n"); int len=avcodec_decode_audio4(ctx, frame, &frameFinished, &packet); if(frameFinished) { if (sfmt==AV_SAMPLE_FMT_S16P) { // Audacity: 16bit PCM little endian stereo int16_t* ptr_l = (int16_t*)frame->extended_data[0]; int16_t* ptr_r = (int16_t*)frame->extended_data[1]; for (int i=0; i<frame->nb_samples; i++) { fwrite(ptr_l++, sizeof(int16_t), 1, outfile); fwrite(ptr_r++, sizeof(int16_t), 1, outfile); } } else if (sfmt==AV_SAMPLE_FMT_FLTP) { //Audacity: big endian 32bit stereo start offset 7 (but has noise) float* ptr_l = (float*)frame->extended_data[0]; float* ptr_r = (float*)frame->extended_data[1]; for (int i=0; i<frame->nb_samples; i++) { fwrite(ptr_l++, sizeof(float), 1, outfile); fwrite(ptr_r++, sizeof(float), 1, outfile); } } } }}fclose(outfile);av_close_input_file(container);return 0;
} 我希望我刚刚做了一个天真的转换(最/少显著位的问题),但目前我一直无法弄清楚。需要注意的是Audacity的只能当导入RAW浮点数据的32位或64位浮点(或大或小端)。 感谢您的任何见解。 0 0
- ffmpeg 保存avcodec_decode_audio4解码后的PCM数据
- ffmpeg 保存avcodec_decode_audio4之后的pcm数据
- ffmpeg解码音频保存为PCM
- FFmpeg-利用ffplay.c保存视频解码后的数据yuv420
- ffmpeg:视频解码以及解码后数据的编码
- ffmpeg avcodec_decode_audio4解码 swr_convert 转换为AV_SAMPLE_FMT_S16格式
- ffmpeg最简单的解码保存YUV数据
- ffmpeg最简单的解码保存YUV数据
- ffmpeg最简单的解码保存YUV数据
- 【FFmpeg杂记】音频解码输出PCM格式数据分析
- ffmpeg解码数据保存为yuv格式
- FFMPEG结构体分析:AVFrame(解码后的数据)
- ffmpeg添加mpeg ps流的pcm的解码支持
- ffmpeg中获取yuv解码后数据
- ffmpeg解码后存YUV数据
- ffmpeg保存原始数据PCM YUV
- 使用ffmpeg解码音频文件到PCM格式
- ffmpeg进行音频解码,QAudioOutput播放解码后的音频
- PL/SQL中如何删除没有用的sql脚本(PL/SQL中的reopen删除
- maven 3.3.3 for windows 配置
- Codeforces Round #350 (Div. 2)
- android OOBE创建方法
- 自定义控件之对现有控件拓展(一)
- ffmpeg 保存avcodec_decode_audio4解码后的PCM数据
- 将数据库查询出的数据保存到Excel表格中
- Map集合的4种遍历方式
- 关于:socket阻塞、非阻塞,同步、异步、I/O模型
- 网页上传excel文件到服务器,服务端用NPOI解析excel
- div显示隐藏和内容修改
- 据说最快的拼接字符串的方式bytes. Buffer
- Test
- 浏览器兼容性问题和解决方案