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??
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!
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"
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
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.