How to properly save frames from mp4 as png files using ExtractMpegFrames.java?

十年热恋 提交于 2019-12-07 04:01:23

You can get all Frames of Video Using ffmpeg library here is working code.

add dependancy

compile 'com.writingminds:FFmpegAndroid:0.3.2'

to your gradle

      private void loadFFMpegBinary() {
        try {
            if (ffmpeg == null) {
                ffmpeg = FFmpeg.getInstance(this);
            }
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
//                @Override
//                public void onFailure() {
//                    showUnsupportedExceptionDialog();
//                }

                @Override
                public void onSuccess() {
                    Log.d(TAG, "ffmpeg : correct Loaded");
                }
            });
        } catch (FFmpegNotSupportedException e) {

        } catch (Exception e) {
            Log.d(TAG, "EXception  : " + e);
        }
    }

here is image extratct method

 public void extractImagesVideo() {
        File moviesDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES
        );

        String filePrefix = "extract_picture";
        String fileExtn = ".jpg";
        String yourRealPath = getPath(Pick_Video.this, DataModel.selectedVideoUri);
        Log.d("selected url", "" + DataModel.selectedVideoUri);
        File src = new File(yourRealPath).getAbsoluteFile();

        File appDir=new File(moviesDir,"/"+app_name+"/");
        if(!appDir.exists())
            appDir.mkdir();
        DataModel.appDir=appDir;
        File dir = new File(appDir, "testVideo");
        int fileNo = 0;
        while (dir.exists()) {
            fileNo++;
            dir = new File(moviesDir+"/"+app_name+"/", "testVideo" + fileNo);

        }
        dir.mkdir();
        DataModel.dir = dir;

        resultList = new ArrayList<String>(256);

        filePath = dir.getAbsolutePath();
        File dest = new File(dir, filePrefix + "%03d" + fileExtn);


        Log.d(TAG, "startTrim: src: " + src.toString());
        Log.d(TAG, "startTrim: dest: " + dest.getAbsolutePath());


        String[] complexCommand = { "-i",""+src.toString(),"-qscale:v", "2","-vf", "fps=fps=20/1",dest.getAbsolutePath()};
        //"-qscale:v", "2","-vf", "fps=fps=20/1",//
        //works fine with speed and
        execFFmpegBinary(complexCommand);



    }

call this two method on button click event

Comment If Any query.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!