Playing audio with FFMPEG

孤街浪徒 提交于 2020-02-03 10:42:31

问题


I have been trying to port FFMPEG (for playing audio) into Android using NDK. I have had some success

  • I could build FFMPEG and link it via NDK.
  • I could call avcodec_decode_audio3() and decode a given audio file.

So here I have a audio buffer output from the function. How do I play this now? Any ffmpeg guys can tell me the exact steps to decode and play audio. I am really clueless of what to do with the audio buffers created I got from avcodec_decode_audio3().

thanks a lot.


回答1:


I have developed a videoplayer on android based on ffmpeg. You can use AudioTrack class to play audio onto device.

EDIT :

In Java create an audiotrack object

AudioTrack track;
bufferSize = AudioTrack.getMinBufferSize(44100,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, mode);

//Play audio clip
track.play();

while(stream_is_over){
//Copy the decoded raw buffer from native code to "buffer" .....
............
track.write(buffer, 0, readBytes);
}



回答2:


In order to use the FFmpeg as an audio playback tool you can untilize FFplay (available for Windows and for Linux).

It's as simple as: ffplay <input audio track> The audio track must be of a supported format, meaning you will need some libraries.

  1. If you want something for a Windows system, then just download the builds here, and then put the executable in your environment variable path. One can also go the hard way and download the source code and build. But why bother?
  2. In case you're using something sporting some Linux, including Raspbian this link describes how to get libraries and then enable then in the FFmpeg build. The FFmpeg build will also include FFplay. I have tested this and it seems to work for me.
  3. In both cases you will need to have a C compiler installed in order to tackle the make commands.

An implementation example using FFplay processes in python3:

I am working on a personal project utilizing a RaspberryPi as more or less a fancy mp3 player doorbell type IoT device. It plays Darude Sandstorm on full blast for anyone ringing the doorbell. But it also has a twist. It's called DarudeDoorBell.



来源:https://stackoverflow.com/questions/5000385/playing-audio-with-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!