使用 ffmpeg 从图像创建视频文件

2022-01-10 00:00:00 android-ndk android java

我现在可以在我的项目创建的 Android.mk 文件中编译并将 ffmpeg 添加到 jni 文件夹中我想使用 ffmpeg 从我存储在我的静态数组列表中的图像创建一个视频文件

I am able to compile and add ffmpeg to jni folder in my project created Android.mk file now I want to use ffmpeg to create a video file from the images I have stored in my static arraylist

我搜索了很多,但找不到任何教程,非常感谢任何帮助.

I have searched alot but couldn't find any tutorial any help is really appreciated.

推荐答案

我有类似的需求并完成了同样的工作.有两种方法可以做到这一点.我想先分享一个简单的.

I was in a similar need and accomplished the same. There are two ways in which you can do this. I would like to share the simpler one first.

  • 在 Android 中创建一个临时文件夹.

  • Create a temporary folder inside the Android.

将图片复制到新文件夹中

Copy your images in the new folder

首先,按照数字顺序重命名您的图片.比如img1.jpg,img2.jpg,img3.jpg,... 那么你可以运行:

First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,... Then you may run:

要以编程方式运行,

使用以下代码:

void convertImg_to_vid()
{
    Process chperm;
    try {
        chperm=Runtime.getRuntime().exec("su");
          DataOutputStream os = 
              new DataOutputStream(chperm.getOutputStream());

              os.writeBytes("ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
");
              os.flush();

              chperm.waitFor();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

开始吧.我会帮助你..一切顺利

Get started with this. I will help you.. All the best

使用教程:http://ffmpeg.org/faq.html 里面专门通读了3.2部分教程.

Use the tutorial : http://ffmpeg.org/faq.html Specially gothrough 3.2 section inside the tutorial.

为了能够运行上述命令,你应该在 bin 目录中有 ffmpeg 命令.ffmpeg 二进制文件应该针对 Android 平台进行交叉编译...

To be able to run the above commands, you should have ffmpeg command in bin directory. The ffmpeg binary should be cross compiled for Android platform...

相关文章