jni参数的转换(3)

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值