我根据以下链接更改了 ffmpeg.c
:
http://www.roman10.net/how-to-port-ffmpeg-the-program-to-androidideas-and-thoughts/
他说改变main()
为JNI接口(interface)原型(prototype)。好吧,我不熟悉 JNI 接口(interface)原型(prototype),但我阅读了一篇关于 JNI 的文章并相应地对其进行了更改。
谁能看看我的代码,看看这是真的吗?
JNIEXPORT jint JNICALL Java_com_ffmpegtest_MainActivity_main(JNIEnv *pEnv, int argc, char **argv) {
int64_t ti;
av_log_set_flags(AV_LOG_SKIP_REPEATED);
if(argc>1 && !strcmp(argv[1], "-d")){
run_as_daemon=1;
verbose=-1;
av_log_set_callback(log_callback_null);
argc--;
argv++;
}
avcodec_register_all();
#if CONFIG_AVDEVICE
avdevice_register_all();
#endif
#if CONFIG_AVFILTER
avfilter_register_all();
#endif
av_register_all();
#if HAVE_ISATTY
if(isatty(STDIN_FILENO))
avio_set_interrupt_cb(decode_interrupt_cb);
#endif
init_opts();
if(verbose>=0)
show_banner();
/* parse options */
parse_options(argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
fprintf(stderr, "Use -h to get full help or, even better, run 'man ffmpeg'\n");
ffmpeg_exit(1);
}
/* file converter / grab */
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
ffmpeg_exit(1);
}
if (nb_input_files == 0) {
fprintf(stderr, "At least one input file must be specified\n");
ffmpeg_exit(1);
}
ti = getutime();
if (transcode(output_files, nb_output_files, input_files, nb_input_files,
stream_maps, nb_stream_maps) < 0)
ffmpeg_exit(1);
ti = getutime() - ti;
if (do_benchmark) {
int maxrss = getmaxrss() / 1024;
printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
}
return ffmpeg_exit(0);
}
最佳答案
应该是
JNIEXPORT jint JNICALL
Java_com_ffmpegtest_MainActivity_main(JNIEnv *pEnv, jobject obj) {
其中 obj
是此函数所属的对象,即您的 MainActivity
实例。如果您需要传递额外的参数,您还需要将它们添加到 Java 代码中的 native 方法声明中。
关于android - 将 int main() 更改为 JNI 接口(interface)原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9670587/