I have successfully built ffmpeg for android using the bambuser
. Now I have to build a sample converter application like mp4 to 3gp. I know there are command line commands ffmpeg -i video_origine.avi video_finale.mpg
. But I don't know how to execute these commands programatically. I have sample code like
jint Java_com_example_ndklearning1_MainActivity_logFileInfo(JNIEnv * env, jobject this, jstring filename)
{
av_register_all();
AVFormatContext *pFormatCtx;
const jbyte *str;
str = (*env)->GetStringUTFChars(env, filename, NULL);
if(av_open_input_file(&pFormatCtx, str, NULL, 0, NULL)!=0)
{
LOGE("Can't open file '%s'\n", str);
return 1;
}
else
{
LOGI("File was opened\n");
LOGI("File '%s', Codec %s",
pFormatCtx->filename,
pFormatCtx->iformat->name
);
}
return 0;
}
This code open's a file and extracts the codec information. All I want is that, to convert the opened file in a desired format. Any kind of help such as code snippet or steps to follow will be highly appreciated.
Can ffmpeg API serve my purpose ? If there is existing API available, it will be more helpful
Recently I came across the similar problem. My solution is to simulate a command line in Java program.
Firstly, I add a function to the file "ffmpeg.c":
In fact this function is just a copy of the main function with a little modification.
Then create a native function:
After compilation with ffmpeg, you can simulate excuting ffmpeg commands like:
Hope this helps!
EDIT: Android.mk
Replace NativeVideoUtil.c with your native file.