Array of Bitmaps into Video with ffmpeg

I'm Facing current porblem. I have an Array of 100 Bitmaps. these are Screenshots i took from a view. I used JCodec to make it to a video, buts its waay to slow. Im hoping to get better results with FFmpeg

Now i want to use the FFmpeg Library. Simillar questions were asked but i have no Idea how to use ffmpeg and how i have to use it in my specific case. All i see are weird Complex Commands See:

 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"};

The Problem is, that in this case he is using a Path. I need it to be from an Array. And i have no idea what to do with the String (ComplexCommands) :/ My Bitmaps are like this:

Bitmap[] bitmaps = new Bitmaps[100];

this is filled later on.

if anyone is searching on how to do it with 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);
                }

1 answer

  • answered 2020-02-14 12:37 B. Plüster

    According to the the ffmpeg wiki, the way you described is exactly how it is intended to be done. To implement this you should write each image from your array into a single file according to the described naming conventions. I don't know if this will help with your performance issues though. Writing the images to files can be done following this answer:

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

    As far as I could find, ffmpeg does not support directly encoding from an array.