- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解码音频并使用 ffmpeg 绘制波形,输入音频数据为 AV_SAMPLE_FMT_S16P
,基本上我正在按照教程 here 进行操作, 音频在 libao 下播放正常.现在我需要使用解码数据绘制波形,目前我正在编写左右 channel 以分离 csv 文件并在 excel 上绘制。但是波形与使用相同音频剪辑的 Audacity 中显示的波形有所不同。当我分析写在 csv 上的值时,大多数值都接近 uint16_t
(65535) 的最大值,但也有一些其他较低的值,但大多数是峰值。
这是源代码,
const char* input_filename="/home/user/Music/Clip.mp3";
av_register_all();
AVFormatContext* container=avformat_alloc_context();
if(avformat_open_input(&container,input_filename,NULL,NULL)<0){
endApp("Could not open file");
}
if(avformat_find_stream_info(container, NULL)<0){
endApp("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){
endApp("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){
endApp("cannot find codec!");
}
if(avcodec_open2(ctx,codec,NULL)<0){
endApp("Codec cannot be found");
}
AVPacket packet;
av_init_packet(&packet);
//AVFrame *frame=avcodec_alloc_frame();
AVFrame *frame=av_frame_alloc();
int buffer_size=AVCODEC_MAX_AUDIO_FRAME_SIZE+ FF_INPUT_BUFFER_PADDING_SIZE;
// MSVC can't do variable size allocations on stack, ohgodwhy
uint8_t *buffer = new uint8_t[buffer_size];
packet.data=buffer;
packet.size =buffer_size;
int frameFinished=0;
int plane_size;
ofstream fileCh1,fileCh2;
fileCh1.open ("ch1.csv");
fileCh2.open ("ch2.csv");
AVSampleFormat sfmt=ctx->sample_fmt;
while(av_read_frame(container,&packet)>=0)
{
if(packet.stream_index==stream_id){
int len=avcodec_decode_audio4(ctx,frame,&frameFinished,&packet);
int data_size = av_samples_get_buffer_size(&plane_size, ctx->channels,
frame->nb_samples,
ctx->sample_fmt, 1);
if(frameFinished){
int write_p=0;
// QTime t;
switch (sfmt){
case AV_SAMPLE_FMT_S16P:
for (int nb=0;nb<plane_size/sizeof(uint16_t);nb++){
for (int ch = 0; ch < ctx->channels; ch++) {
if(ch==0)
fileCh1 <<((uint16_t *) frame->extended_data[ch])[nb]<<"\n";
else if(ch==1)
fileCh2 <<((uint16_t *) frame->extended_data[ch])[nb]<<"\n";
}
}
break;
}
} else {
DBG("frame failed");
}
}
av_free_packet(&packet);
}
fileCh1.close();
fileCh2.close();
avcodec_close(ctx);
avformat_close_input(&container);
delete buffer;
return 0;
编辑:
我附上了使用opencv绘制的波形图像,这里我将样本值缩放到0-255范围内,并将值127作为0(Y轴)。现在为每个样本绘制从 (x,127) 到 (x,sample value) 的线,其中 x=1,2,3,...
最佳答案
问题是当示例格式已签名时转换为 uint16_t
(AV_SAMPLE_FMT_S16P,其中 S 表示已签名)。因此,-1 将作为 2147483648 等写入文件。
要修复它,更改行:
fileCh1 <<((uint16_t *) frame->extended_data[ch])[nb]<<"\n";
到:
fileCh1 <<((int16_t *) frame->extended_data[ch])[nb]<<"\n";
关于c++ - FFMPEG Audio解码并绘制波形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36425401/
我正在尝试实现一系列音频文件,这些文件是三星语音记录功能的一部分。 像这样 enter image description here 但是,没有显示实时频谱的信息,但是没有显示上传的音频文件的波形的信
希望从输入中获取特定金色#ad9557(173/255、149/255、87/255)的波形,并具有透明背景/或黑色(如果不可能)。 我目前正在使用此脚本来生成它: command = new Str
这个问题是关于用于回答 this 的代码的线。我使用的是 Nicholas DiPiazza 发布的代码,后来是 Andrew Thompson 的变体。我在这段代码中添加了第二个 AudioWave
这就是我要达到的结果 这是我所做的:https://codepen.io/demedos/pen/gjQNOM HTML 结构: .container .header .page-1
我想在未来用 C# .NET 4.0 中的音频做一些项目,所以我收集了一些用于录音、处理 WAVE 文件等的代码示例。但我没能找到的是: 如何实时(ish)绘制音频波形/频谱图?显然,创建内存位图并将
我已经搜索了很多东西,但是找不到我想要的东西。 有没有办法从一个非常短的音频文件(在我的情况下为1秒mp3)生成简化或平坦的声波图像? 简化可能是错误的术语,但是我的意思是我想要这种输出: 而不是这样
我在使用 MS-s 波形 API 的程序中遇到某种链接错误。我正在使用的代码可以在这里找到:http://www.planet-source-code.com/vb/scripts/ShowCode.
我正在使用 Android 2.3.1 上的 Visualizer 类进行一些音乐分析。我发现 FFT 和波形幅度受设备体积的影响。这意味着,如果用户调低音量,我会收到很少或收不到 FFT 数据。 我
我有两张 png,一张白色,一张红色。 当歌曲不播放时,它应该是白色的,当歌曲播放时,它应该随着歌曲的进行而填充红色,并且当分别向后和向前滑动时,它应该填充红色。 我已经能
像soundcloud和zippyshare1,如何用java生成音频波形图?是否有任何框架或开源库可用于这种情况? 我想生成一个音频波形作为图像,加载轨道后,将加载波形图像。 最佳答案 以 this
是否有一种仅 Java 的方法可以在 JScrollPane 中显示更大的图片?我不想重新发明轮子,而且我已经在 JLabel 技巧中使用 ImageIcon 来显示 32768x400 图像而苦
是否有(某处)用于 Windows 的命令行程序,可以从 MP3/WAV 创建 PNG/JPEG 视觉效果? 编辑: 这是图像应该是什么样子的一个很好的例子。 最佳答案 Sox ,“音频处理的瑞士军刀
我正在开发一个 WebGL 应用程序,它使用来自 soundcloud API 的数据。 我正在尝试使用 ThreeJS 将轨道图稿和波形 PNG 加载到纹理中以放入 Sprite 上。 但是我在 c
我是一名优秀的程序员,十分优秀!