简体   繁体   English

如何在Android上使用ffmpeg

[英]how to use ffmpeg on android

I want to create video file from Jpeg and audio file. 我想从Jpeg和音频文件创建视频文件。 I've compiled FFMpeg to android and I've got libffmpeg.so, and obj folder with ithers resources. 我已经将FFMpeg编译为android,并且我有libffmpeg.so和带有Ithers资源的obj文件夹。

But how to use it? 但是如何使用呢? What I need to do for use command like: "ffmpeg -i image.jpeg -i audio.mp3 out.avi" Please help. 我需要为使用命令做什么,例如:“ ffmpeg -i image.jpeg -i audio.mp3 out.avi”请帮助。

From the FFmpeg docs on images : 图像上FFmpeg文档

The following example shows how to use ffmpeg for creating a video from the images in the file sequence 'img-001.jpeg', 'img-002.jpeg', ..., assuming an input frame rate of 10 frames per second: 以下示例显示了如何使用ffmpeg从文件序列'img-001.jpeg','img-002.jpeg',...中的图像创建视频,并假设输入帧率为每秒10帧:

 ffmpeg -i 'img-%03d.jpeg' -r 10 out.mkv 

To actually run it from Android, look at the documentation for Runtime.exec() . 要从Android实际运行它,请查看Runtime.exec()的文档

您将需要包括可以从Java调用的JNI包装器方法,这将依次调用FFmpeg函数。

You may use JNI interface to call functions from a library, in your case ffmpeg library. 您可以使用JNI接口从库(对于ffmpeg库)中调用函数。 Here is a basic tutorial of JNI: http://marakana.com/forums/android/examples/49.html 这是JNI的基本教程: http : //marakana.com/forums/android/examples/49.html

To put simply, JNI is the bridge between your Java code and C code. 简而言之,JNI是Java代码和C代码之间的桥梁。

In order to call ffmpeg as in command line from your Java code, You may include ffmpeg.c (and other needed files) into your jni interface (under jni directory) and compile it along with your other jni code, so that you may call ffmpeg's main function with arguments just like the command line. 为了从您的Java代码中以命令行方式调用ffmpeg,您可以将ffmpeg.c(和其他需要的文件)包含到jni界面(位于jni目录下)中,并将其与其他jni代码一起编译,以便您可以调用ffmpeg的主函数带有参数,就像命令行一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM