【问题标题】:Array of Bitmaps into Video with ffmpeg使用 ffmpeg 将位图数组转换为视频
【发布时间】:2020-05-30 01:07:36
【问题描述】:

我正面临当前的问题。 我有一个包含 100 个位图的数组。这些是我从视图中截取的屏幕截图。 我使用 JCodec 制作视频,但速度很慢。我希望用 FFmpeg 得到更好的结果

现在我想使用 FFmpeg 库。有人问了类似的问题,但我不知道如何使用 ffmpeg 以及如何在我的特定情况下使用它。我所看到的都是奇怪的复杂命令,请参阅:

 File dir = your directory where image stores;
    String filePrefix = "picture"; //imagename prefix
    String fileExtn = ".jpg";//image extention
    filePath = dir.getAbsolutePath();
    File src = new File(dir, filePrefix + "%03d" + fileExtn);// image name should ne picture001, picture002,picture003 soon  ffmpeg takes as input valid

complexCommand = new String[]{"-i", src + "", "-c:v", "libx264", "-c:a", "aac", "-vf", "setpts= 2*PTS”、“-pix_fmt”、“yuv420p”、“-crf”、“10”、“-r”、“15”、“-shortest”、“-y”、“/storage/emulated/0/ " + app_name + "/Video/" + app_name + "_Video" + number + ".mp4"};

问题是,在这种情况下,他使用的是路径。我需要它来自一个数组。而且我不知道如何处理字符串(ComplexCommands):/ 我的位图是这样的:

位图[]位图=新位图[100];

这是稍后填写的。

如果有人正在搜索如何使用 JCodec:

 try {
                    out = NIOUtils.writableFileChannel( Environment.getExternalStorageDirectory().getAbsolutePath()+"/***yourpath***/output"+System.currentTimeMillis()+".mp4");
                    // for Android use: AndroidSequenceEncoder

                    AndroidSequenceEncoder encoder = new AndroidSequenceEncoder(out, Rational.R(25, 1));
                    for (int i = 0 ; i < 100 ; i++) {
                        // Generate the image, for Android use Bitmap

                        // Encode the image
                        System.out.println("LOO2P"+i);
                        encoder.encodeImage(bitmaps[i]);
                    }
                    // Finalize the encoding, i.e. clear the buffers, write the header, etc.
                    encoder.finish();

                } catch (FileNotFoundException e) {
                    System.out.println("fNF");
                    e.printStackTrace();

                } catch (IOException e) {
                    System.out.println("IOE");
                    e.printStackTrace();
                } finally {
                    System.out.println("IOSSE");
                    NIOUtils.closeQuietly(out);
                }

【问题讨论】:

    标签: android arrays video ffmpeg bitmap


    【解决方案1】:

    根据the ffmpeg wiki,您描述的方式正是它打算如何完成的。要实现这一点,您应该根据所描述的命名约定将阵列中的每个图像写入单个文件。我不知道这是否有助于解决您的性能问题。 将图像写入文件可以按照this answer:

    for (int i = 0; i<bitmapArray.length(); i++){
        // Write to file while incrementing the file name
        writeToFile(bitmapArray[i], i);
    }
    

    据我所知,ffmpeg 不支持直接从数组编码。

    【讨论】:

      猜你喜欢
      • 2014-03-02
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 2011-09-23
      • 2020-08-25
      • 1970-01-01
      相关资源
      最近更新 更多