Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

android - FFMPEG:Multiple Image frames + 1 Audio =1 Video

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??
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...