2

I am using this library Android-MJPEG-Video-Capture-FFMPEG to and getting the frames with using the camera..I am Using below FFMPEG command for this

String[] ffmpegCommand = {
                    "/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg", "-r",
                    "" + p.getPreviewFrameRate(), "-b", "1000000",
                    "-vcodec", "mjpeg", "-i",
                    TEMPIMAGEPATH + "frame_%05d.jpg", "-i",
                    VIDEOPATH + "video.mov" };

Its working fine..while getting the frames i am also recording the audio.now i want to add audio to the output video..I have tried with this command but its not working..

String[] ffmpegCommand = {
                    "/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg", "-r",
                    "" + p.getPreviewFrameRate(), "-b", "1000000",
                    "-vcodec", "mjpeg", "-acodec", "copy", "-i",
                    TEMPIMAGEPATH + "frame_%05d.jpg", "-i",
                    VIDEOPATH + "audio.mp4", VIDEOPATH + "video.mov" };

searched in google but no working solutions found..

QUESTION::

what is the correct command for combining audio and frames into video??
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
  • I think you should add option map before output filename, like: -map [0:v] -map [1:a] – ptQa Dec 09 '13 at 15:15
  • "Not working" is never as useful as the actual console output. – llogan Dec 09 '13 at 18:11
  • @LordNeckbeard I have tried like this "/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg", "-i", VIDEOPATH + "audio.3gp", "-i", TEMPIMAGEPATH + "frame_%05d.jpg", /* * "-acodec", "copy ", * "-vcodec", "mpeg4" */ "-r", "" + p.getPreviewFrameRate(), "-b", "1000000", "-shortest", VIDEOPATH + "video.mkv" its giving me video but audio is not coming..i am stuck here help me please.. – kalyan pvs Dec 10 '13 at 04:58
  • @ptQa i have tried with map but it saying map is not recognized – kalyan pvs Dec 10 '13 at 05:33
  • What exactly do are you trying to execute when "map is not recognized"? – ptQa Dec 10 '13 at 08:55
  • trying to add multiple images and one audio file into video file..video is coming but audio is not coming – kalyan pvs Dec 10 '13 at 09:07
  • You need to show the actual, unscripted ffmpeg command and the complete ffmpeg console output. Please do not try to cram it in comments but you can update your question with this info. – llogan Dec 10 '13 at 18:42
  • Link not working. can you please fixed it. – Butani Vijay May 17 '16 at 07:18

4 Answers4

6

I found the solution after applied lot of tricks.

public void myFunction(ShellCallback sc, String imgPath, String audioPath, String outPath) throws IOException, InterruptedException
    {

        Log.e("MyFunction","audioPath"+audioPath);
        Log.e("MyFunction","imagePath"+imgPath);
        ArrayList<String> cmd = new ArrayList<String>();

        cmd = new ArrayList<String>();

        cmd.add(ffmpegBin);
        cmd.add("-y");
        cmd.add("-loop");
        cmd.add("1");
        cmd.add("-r");
        cmd.add("1");
        cmd.add("-i");
        cmd.add(new File(imgPath).getCanonicalPath());
        cmd.add("-i");
        cmd.add(new File(audioPath).getCanonicalPath());
        cmd.add("-acodec");
        cmd.add("aac");
        cmd.add("-vcodec");
        cmd.add("mpeg4");
        cmd.add("-s");
        cmd.add("480x320");
        cmd.add("-strict");
        cmd.add("experimental");
        cmd.add("-b:a");
        cmd.add("32k");
        cmd.add("-shortest");
        cmd.add("-f");
        cmd.add("mp4");
        cmd.add("-r");
        cmd.add("2");
        File fileOut = new File(outPath);
        cmd.add(fileOut.getCanonicalPath());

        execFFMPEG(cmd, sc);
    }

I hope this may help others.Thanks!

Jagdish
  • 2,418
  • 4
  • 25
  • 51
  • @kalyanpvs,What happend about your issue? – Jagdish Feb 05 '14 at 11:53
  • @ArslanAhmad, You need to be download ffmpeg library and import into eclipse.then add to the desire project. put the above function in the ffmpeg project. – Jagdish May 27 '14 at 05:50
  • Yes I have already import this library. but I think ffmpegBin is something like the variable. – Ahmad Arslan May 27 '14 at 06:39
  • String ffmpegBin = new File(Path,"ffmpeg").getAbsolutePath(); Runtime.getRuntime().exec("chmod 700 " +ffmpegBin); String[] ffmpegCommand=new String[]{ ffmpegBin, "-h" }; I think ffmpeg should be declare like this – Ahmad Arslan May 27 '14 at 09:34
  • @Kalyan, Jagdish, Arslam Ahmad, Am also having the exactly same requirement of "Multiple Image frames + 1 Audio =1 Video". and also I got video without audio. Which value i should pass to "ShellCallback sc" while calling the function? Can anyone help me to solve it? Thanks in advance!!! – Karthikeyan Jan 27 '15 at 04:56
  • From where you are getting this "execFFMPEG" method? – Akshay kumar Mar 28 '19 at 05:10
1

From jagadish answer, i tried the command like this, this is worked for me.

-y -i /storage/emulated/0/images.jpg -i /storage/emulated/0/rec.wav -acodec aac -vcodec mpeg4 -s 480*320 -f mp4 -r 2 /storage/emulated/0/result.mp4"

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
Phani varma
  • 475
  • 5
  • 7
0

Try with the below command it should work with multiple images Library - https://github.com/WritingMinds/ffmpeg-android-java

Here test$04d.png refers to series of images like test0001.png, test0002.png etc.. make sure that you have the same name image conventions for your images names

ffmpeg -r 1/5 -i /storage/emulated/0/Pictures/Screenshots/test%04d.png -c:v libx264 -vf fps=20 -pix_fmt yuv420p /storage/emulated/0/Movies/out.mp4

With Music file

ffmpeg -r 1/5 -i /storage/emulated/0/Pictures/Screenshots/test%04d.png -i /storage/emulated/0/Pictures/Screenshots/music.mp3 -c:v libx264 -vf fps=20 -pix_fmt yuv420p /storage/emulated/0/Movies/out.mp4

Good luck

Nagendra Badiganti
  • 2,099
  • 2
  • 22
  • 30
0
   inputCode = new String[]{FileUtils.getFFmpeg(getApplicationContext()),
                "-y", "-r", "15", "-i", ImageListDirectory + "",
                "-i", Environment.getExternalStorageDirectory() + "/" + "MusuicFile.mp3", "-shortest",
                "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", Outputpath};

you can try this command.

Ria Mehta
  • 23
  • 1
  • 7