1.
java中:
private native FFMpegAVFormatContext native_av_setInputFile(String filePath) throws IOException;
JNI中:
static jobject FFMpeg_setInputFile(JNIEnv *env, jobject obj, jstring filePath) {
const char *_filePath = (*env)->GetStringUTFChars(env, filePath, NULL);
AVFormatContext *fileContext = opt_input_file(_filePath);
if(fileContext == NULL) {
jniThrowException(env,
"java/io/IOException",
"Can't create input file");
}
jobject *file = AVFormatContext_create(env, fileContext);
jobject *inFormat = AVInputFormat_create(env, fileContext->iformat);
jfieldID f = (*env)->GetFieldID(env,
AVFormatContext_getClass(env),
"mInFormat",
AVInputFormat_getClassSignature());
(*env)->SetObjectField(env, file, f, inFormat);
return file;
}
2.
java中:
private native FFMpegAVFormatContext native_av_setOutputFile(String filePath) throws IOException;
JNI中:
static jobject FFMpeg_setOutputFile(JNIEnv *env, jobject obj, jstring filePath) {
const char *_filePath = (*env)->GetStringUTFChars(env, filePath, NULL);
AVFormatContext *fileContext = opt_output_file(_filePath);
if(fileContext == NULL) {
jniThrowException(env,
"java/io/IOException",
"Can't create output file");
}
return AVFormatContext_create(env, fileContext);
}
3.private native void native_av_parse_options(String[] args) throws RuntimeException;
static void FFMpeg_parseOptions(JNIEnv *env, jobject obj, jobjectArray args) {
int i = 0;
int argc = 0;
char **argv = NULL;
if (args != NULL) {
argc = (*env)->GetArrayLength(env, args);
argv = (char **) malloc(sizeof(char *) * argc);
for(i=0;i<argc;i++)
{
jstring str = (jstring)(*env)->GetObjectArrayElement(env, args, i);
argv[i] = (char *)(*env)->GetStringUTFChars(env, str, NULL);
}
}
/* parse options */
parse_options(argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"Use -h to get full help or, even better, run 'man ffmpeg");
}
/* file converter / grab */
if (nb_output_files <= 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"At least one output file must be specified");
}
if (nb_input_files == 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"At least one input file must be specified");
}
}
4.
java中:
private native FFMpegAVFormatContext native_av_setInputFile(String filePath) throws IOException;
JNI中:
static jobject FFMpeg_setInputFile(JNIEnv *env, jobject obj, jstring filePath) {
const char *_filePath = (*env)->GetStringUTFChars(env, filePath, NULL);
AVFormatContext *fileContext = opt_input_file(_filePath);
if(fileContext == NULL) {
jniThrowException(env,
"java/io/IOException",
"Can't create input file");
}
jobject *file = AVFormatContext_create(env, fileContext);
jobject *inFormat = AVInputFormat_create(env, fileContext->iformat);
jfieldID f = (*env)->GetFieldID(env,
AVFormatContext_getClass(env),
"mInFormat",
AVInputFormat_getClassSignature());
(*env)->SetObjectField(env, file, f, inFormat);
return file;
}
2.
java中:
private native FFMpegAVFormatContext native_av_setOutputFile(String filePath) throws IOException;
JNI中:
static jobject FFMpeg_setOutputFile(JNIEnv *env, jobject obj, jstring filePath) {
const char *_filePath = (*env)->GetStringUTFChars(env, filePath, NULL);
AVFormatContext *fileContext = opt_output_file(_filePath);
if(fileContext == NULL) {
jniThrowException(env,
"java/io/IOException",
"Can't create output file");
}
return AVFormatContext_create(env, fileContext);
}
3.private native void native_av_parse_options(String[] args) throws RuntimeException;
static void FFMpeg_parseOptions(JNIEnv *env, jobject obj, jobjectArray args) {
int i = 0;
int argc = 0;
char **argv = NULL;
if (args != NULL) {
argc = (*env)->GetArrayLength(env, args);
argv = (char **) malloc(sizeof(char *) * argc);
for(i=0;i<argc;i++)
{
jstring str = (jstring)(*env)->GetObjectArrayElement(env, args, i);
argv[i] = (char *)(*env)->GetStringUTFChars(env, str, NULL);
}
}
/* parse options */
parse_options(argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"Use -h to get full help or, even better, run 'man ffmpeg");
}
/* file converter / grab */
if (nb_output_files <= 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"At least one output file must be specified");
}
if (nb_input_files == 0) {
jniThrowException(env,
"java/lang/RuntimeException",
"At least one input file must be specified");
}
}
4.