How to convert video file to audio file by using FFMPEG?

Related searches

I'm making video to audio converter app but need help to convert video to audio using ffmpeg. I checked many answers and websites but their answers are not easy to understand and I'm confused with command that is used to convert. What is the proper command to convert video to audio and is I'm executing the command in right way?

public class VideoConvertActivity extends AppCompatActivity {

    private VideoView videoView;
    private Button convertButton;
    private String filePath;
    private FFmpeg ffmpeg;

    protected void onCreate(Bundle savedInstanceState) {

        videoView = findViewById(;
        convertButton = findViewById(;

        ffmpeg = FFmpeg.getInstance(VideoConvertActivity.this);

// in variable video i'm getting the path of video path from previous activity through intent and that video will have to convert to audio file
        Intent extras = getIntent();
        final String video = extras.getStringExtra("video");


        convertButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                try {

                    File moviesDir = Environment.getExternalStoragePublicDirectory(

                    String filePrefix = "convert_audio";
                    String fileExtn = ".mp3";
                    File dest = new File(moviesDir, filePrefix + fileExtn);

                    int fileNo = 0;
                    while (dest.exists()) {
                        dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
                    filePath = dest.getAbsolutePath();

                    // to execute "ffmpeg -version" command you just need to pass "-version"
                    String[] command = {"-y", "-i", video, "-vn", "-ar", "44100", "-ac", "2", "-b:a", "256k", "-f", "mp3", filePath};
                    ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {

                        public void onStart() {

                        public void onProgress(String message) {

                        public void onFailure(String message) {

                        public void onSuccess(String message) {

                        public void onFinish() {
                } catch (FFmpegCommandAlreadyRunningException e) {
                    // Handle if FFmpeg is already running

                 Toast.makeText(VideoConvertActivity.this,"Converted Successfully",Toast.LENGTH_SHORT).show();




Main is not a place u should place a while loop, it will cause problems.Since main is a loop in it self u should use thread to do something in background and not interrupt the flow of program. In this case if will do.

Here is an example of player so u can understand how it works:

If u don't solve it in a few hours ill see what I can do to help you.

A quick guide to using FFmpeg to convert media files, please say how to use ffmpeg to change only audio format in a video file. i used one such formula and it processed . but i could not find the output file in the source� Convert Over 20 Different File Types. Access & Convert Your Videos Now. Instant Free Download. Access & Convert Videos with Video Converter HD extension install.

any convert commend you should place it in your command variable

so instrad of this commend

String[] command = {"-y", "-i", video, "-vn", "-ar", "44100", "-ac", "2", "-b:a", "256k", "-f", "mp3", filePath};

use this one

ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3

or you can format your commend as you did for command to be an array :

   String[] command = {"-y", "-i", video, "-f", "mp3", "-ab", "192000", "-vn", filePath};

How to use FFMpeg to do Simple Audio Conversion, Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample ffmpeg -i videofile.mp4 -vn -acodec libvorbis audiofile.ogg. Instant Online Video Converter. Convert Hundreds Of Audio & Video To Other Format. Easily Convert Audio & Video To Different File Formats Like Mp3, Music, Wav & More.

I gave read permission in manifest but forget to give write permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

ffmpeg guide � GitHub, The basic command is: ffmpeg -i filename.mp4 filename.mp3. or ffmpeg -i video. mp4 -b:a 192K -vn music.mp3. Check this URL: MP4 Video to MP3 File Using� use this one . ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3 or you can format your commend as you did for command to be an array : String[] command = {"-y", "-i", video, "-f", "mp3", "-ab", "192000", "-vn", filePath};

How can I convert MP4 video to MP3 audio with FFmpeg?, Merging video and audio, with audio re-encoding. See this example, taken from this blog entry but updated for newer syntax. It should be something to the effect� You can use one input file to get several different output files by just entering the name and the prefix like this: ffmpeg -i filename.mp3 newfilename.wav newfilename.ogg newfilename.mp4 This will result in converting 3 output audio files (wav,ogg,mp4) from one mp3 file.

How to merge audio and video file in ffmpeg, Use. ffmpeg -i "!original!" -map 0:v -map 0:a -c:v libx265 -preset medium -crf 28 -c:a copy "g:\Prepare\Convert\!file!" FFmpeg by default only picks one video, audio and subtitle track (if they are present) from among the sources. Express map assignments are required in order to include other streams. 0:a selects all audio streams.

FFmpeg isn’t only for videos, there’s a lot you can do with audio files as well. This example will convert a.wav file to mp3 format. ffmpeg -i input_sound.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 output_sound.mp3 Convert.avi Video to.mpg

  • I'm not using the exo player and what is the proper and easy way to convert video to audio in android ?
  • what about rest of my code ? is it true to convert video to audio
  • it maybe will be good idea to make your process into a asynctask or Runnable, however i think your code is fine ...
  • im using the com.arthenica.mobileffmpeg.FFmpeg , with the same commend and it work fine, so there is two possibilities, that you forget to add ndk to your project ,or the files you set are wrong.
  • I didn't add any ndk is it compulsory ? I'm not getting any error or crash