FFmpeg提取图像二进制命令

时间:2017-07-19 03:04:12

标签: android ffmpeg

我的ffmpeg for android studio是用这个编译的:

  

编译'com.writingminds:FFmpegAndroid:0.3.2'

在下面的代码中,我有这行代码:

  

String [] complexCommand = {“ - i”,yourRealPath,“ - c:v”,“libx264”,   “-crf”,“22”,“ - map”,“0”,“ - segment_time”,“6”,“ - g”,“9”,   “-sc_threshold”,“0”,“ - force_key_frames”,“expr:gte(t,n_forced * 6)”,   “-f”,“segment”,dest.getAbsolutePath()};

我想知道的事情:

  1. 我想知道那些输入是什么(即“-sc_threshold”,“ - g”,“ - crf”),它们的功能是什么。
  2. 如果一个视频有30fps并且是5秒长,那么有150帧,如果是这样,ffmpeg能够全部接收150个吗?
  3. 这是我的代码:

         /**
         * Command for extracting images from video
         */
        private void extractImagesVideo(int startMs, int endMs) {
            File moviesDir = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES
            );
    
            String filePrefix = "extract_picture";
            String fileExtn = ".jpg";
            String yourRealPath = getPath(MainActivity.this, selectedVideoUri);
    
            File dir = new File(moviesDir, "VideoEditor");
            int fileNo = 0;
            while (dir.exists()) {
                fileNo++;
                dir = new File(moviesDir, "VideoEditor" + fileNo);
    
            }
            dir.mkdir();
            filePath = dir.getAbsolutePath();
            File dest = new File(dir, filePrefix + "%03d" + fileExtn);
    
    
            Log.d(TAG, "startTrim: src: " + yourRealPath);
            Log.d(TAG, "startTrim: dest: " + dest.getAbsolutePath());
    
            String[] complexCommand = {"-y", "-i", yourRealPath, "-an", "-r", "1/2", "-ss", "" + startMs / 1000, "-t", "" + (endMs - startMs) / 1000, dest.getAbsolutePath()};
    
            execFFmpegBinary(complexCommand);
    
        }
    
     /**
         * Executing ffmpeg binary
         */
        private void execFFmpegBinary(final String[] command) {
            try {
                ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
                    @Override
                    public void onFailure(String s) {
                        Log.d(TAG, "FAILED with output : " + s);
                    }
    
                    @Override
                    public void onSuccess(String s) {
                        Log.d(TAG, "SUCCESS with output : " + s);
                        if (choice == 1 || choice == 2 || choice == 5 || choice == 6 || choice == 7) {
                            Intent intent = new Intent(MainActivity.this, PreviewActivity.class);
                            intent.putExtra(FILEPATH, filePath);
                            startActivity(intent);
                        } else if (choice == 3) {
                            Intent intent = new Intent(MainActivity.this, PreviewImageActivity.class);
                            intent.putExtra(FILEPATH, filePath);
                            startActivity(intent);
                        } else if (choice == 4) {
                            Intent intent = new Intent(MainActivity.this, AudioPreviewActivity.class);
                            intent.putExtra(FILEPATH, filePath);
                            startActivity(intent);
                        } else if (choice == 8) {
                            choice = 9;
                            reverseVideoCommand();
                        } else if (Arrays.equals(command, lastReverseCommand)) {
                            choice = 10;
                            concatVideoCommand();
                        } else if (choice == 10) {
                            File moviesDir = Environment.getExternalStoragePublicDirectory(
                                    Environment.DIRECTORY_MOVIES
                            );
                            File destDir = new File(moviesDir, ".VideoPartsReverse");
                            File dir = new File(moviesDir, ".VideoSplit");
                            if (dir.exists())
                                deleteDir(dir);
                            if (destDir.exists())
                                deleteDir(destDir);
                            choice = 11;
                            Intent intent = new Intent(MainActivity.this, PreviewActivity.class);
                            intent.putExtra(FILEPATH, filePath);
                            startActivity(intent);
                        }
                    }
    

    从以下网址下载代码:

    https://github.com/bhuvnesh123/FFmpeg-Video-Editor-Android

1 个答案:

答案 0 :(得分:1)

<强> 1

  

-sc_threshold:场景变化灵敏度(范围在0 - 100之间)。在每次场景变换时,都会插入一个新的I帧。

     

-g:是GOP(图片组)。帧长度间隔。 GOP确定I帧之间的最大距离。额外提示:高GOP   使视频非常有效压缩。推荐值为250

     

-crf:恒定速率因子(CRF)定义平均期望质量而不是目标比特率。

<强> 2

是的,可以使用FFMPEG库获取目前在视频容器中记录的每个帧。

Bonus:ffmpeg -i video.avi IMG%03d.jpg - 用于获取每个帧并将其转换为jpg图像文件并将其存储在同一位置的示例命令。