bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.54k stars 1.58k forks source link

how to get the spectrum of the audio processed by the filter #1639

Open Nirvana-feng opened 3 years ago

Nirvana-feng commented 3 years ago

Hello, I would like to ask how to get the spectrum of the audio processed by the filter of showwavespic .

saudet commented 3 years ago

Documentation is available here with an example: https://ffmpeg.org/ffmpeg-filters.html#showwavespic

Nirvana-feng commented 3 years ago

Hello, I just refer to this implementation, but I don't know how to deal with the pull frame?I used ffmpegframerecorder to collect it,But the following error occurred: Exception in thread "main" org.bytedeco.javacv.FrameFilter$Exception: avfilter_graph_parse_ptr() error -22 at org.bytedeco.javacv.FFmpegFrameFilter.startAudioUnsafe(FFmpegFrameFilter.java:461) at org.bytedeco.javacv.FFmpegFrameFilter.startUnsafe(FFmpegFrameFilter.java:271) at org.bytedeco.javacv.FFmpegFrameFilter.start(FFmpegFrameFilter.java:251) at showwave.wave(showwave.java:37) at showwave.main(showwave.java:57) [aac @ 000000001b4981c0] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'F:\dashtest\23.aac': Duration: 00:02:54.59, bitrate: 71 kb/s Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 71 kb/s [Parsed_showwavespic_0 @ 000000001b50dbc0] Media type mismatch between the 'Parsed_showwavespic_0' filter output pad 0 (video) and the 'out' filter input pad 0 (audio) Cannot create the link showwavespic:0 -> abuffersink:0 command:ffmpeg -i test.mp4 -filter_complex "showwavespic=s=1024x800" -frames:v 1 audio.png code: public class showwave { public static void wave(String input, String output, String filtercontent) throws Exception { FFmpegFrameGrabber grab = new FFmpegFrameGrabber(input); grab.start(); FFmpegFrameRecorder recorder=new FFmpegFrameRecorder(output,100,100); recorder.setVideoCodec(avcodec.AV_CODEC_ID_PNG); recorder.setPixelFormat(avutil.AV_PIX_FMT_RGBA);//设置像素格式 FFmpegFrameFilter filter = new FFmpegFrameFilter(filtercontent, grab.getAudioChannels()); filter.start(); recorder.start(); Frame frame = null; Frame frame1 = null; while ((frame = grab.grabSamples()) != null) { filter.push(frame); frame1 = filter.pull(); if(frame1!=null){ recorder.record(frame1); }else{ System.out.println(frame1); } } grab.close(); filter.close(); recorder.close(); } public static void main(String[] args) throws Exception { wave("F:\dashtest\23.aac", "F:\dashtest\audio_1.png", "showwavespic=split_channels=1:s=1024x800"); } } Please help me to see what the problem is,thank you very much!

saudet commented 3 years ago

I don't think this is something we can do with FFmpegFrameFilter right now, but we can easily use the ffmpeg program from Java: http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html

Nirvana-feng commented 3 years ago

Thank you very much. It's working