Playing audio with FFMPEG

11,355

Solution 1

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.

Solution 2

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);
}
Share:
11,355
Codevalley
Author by

Codevalley

Someone who's been programming since the DOS days, majorly non-web development. Then forayed into the web a little and into designing. Now, exploring the mobile app world. Working as a Architect for Mobile App development.

Updated on June 04, 2022

Comments

  • Codevalley
    Codevalley almost 2 years

    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.

  • Codevalley
    Codevalley about 13 years
    Can you share some info on that? I would be greatly interested!
  • StackOverflowed
    StackOverflowed about 11 years
    This answer is the bread of a sandwich and completely missing the meat.