gpt4 book ai didi

android - FFmpeg:用于提取图像的复杂命令

转载 作者:行者123 更新时间:2023-12-04 23:08:34 25 4
gpt4 key购买 nike

我在 android studio 2.3.3 上的 ANDROID APPLICATION 的 ffmpeg 是使用以下代码编译的:

compile '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()};



我想知道的:
  • 如何更改我拥有的复杂命令,以便我可以获得 2 秒长的 30fps 视频的最后 15 帧。

  • 这是我引用的代码:
         /**
    * 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

    最佳答案

    使用 select 过滤器以通过索引选择特定帧。

    30 fps 的 2 秒视频有 60 帧,因此您需要从 45 开始的所有帧:

    ffmpeg -i input.mp4 -vf "select='gte(n,45)'" -vsync 0 out-%04d.png

    还有其他选择表达式,如 ltebetween ,见 Expression Evaluation在 ffmpeg 文档中。 -vsync 0丢弃帧时间戳以消除重复。

    最终命令如下所示:
    String[] complexCommand = {"-y", "-i", yourRealPath, "-an", "-framerate", "60", "-vf", "select='gte(n,45)'", "-vsync", "0", dest.getAbsolutePath()};

    关于android - FFmpeg:用于提取图像的复杂命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45189285/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com