Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何创建NDK AMediaMuxer?_Android_C_Android Ndk_Java Native Interface - Fatal编程技术网

Android 如何创建NDK AMediaMuxer?

Android 如何创建NDK AMediaMuxer?,android,c,android-ndk,java-native-interface,Android,C,Android Ndk,Java Native Interface,我正试图在JNI中转换我的java媒体代码。 在java中,我们使用目标文件的绝对路径创建mediaMuxer MediaMuxer(@NonNull String path, @Format int format) 当muxer的JNI版本使用文件描述符时 AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format); 一种方法是使用资产,但资产类似于资源文件:只读。因此,这不是一个好办法 创建文件描述符并将其传递给JNI muxer构

我正试图在JNI中转换我的java媒体代码。 在java中,我们使用目标文件的绝对路径创建mediaMuxer

MediaMuxer(@NonNull String path, @Format int format)
当muxer的JNI版本使用文件描述符时

AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);
一种方法是使用资产,但资产类似于资源文件:只读。因此,这不是一个好办法

创建文件描述符并将其传递给JNI muxer构造函数的好方法是什么


谢谢。

虽然这是可能的,但在java端获取文件描述符,然后将其传递给本机代码是一种过度消耗。传递输出文件名并用本机代码打开文件更容易:

#include <unistd.h>
#include <fcntl.h>
#include <jni.h>

void my_jni_func(JNIEnv* env, jobject thiz, jstring filename) {
    const char* c_filename = (*env)->GetStringUTFChars(env, filename)
    int output_fd = open(c_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    (*env)->ReleaseStringUTFChars(env, filename, c_filename);

    /* Check output_fd for validity, create muxer, and write streams */

    close(output_fd); /* close file when you've finished with muxer */
}
#包括
#包括
#包括
void my_jni_func(JNIEnv*env,jobject thiz,jstring文件名){
const char*c_filename=(*env)->GetStringUTFChars(env,filename)
int output_fd=open(c_filename,O_WRONLY | O_create | O_TRUNC,0666);
(*env)->ReleaseStringUTFChars(env,文件名,c_文件名);
/*检查输出\u fd的有效性,创建muxer并写入流*/
关闭(output_fd);/*使用完muxer后关闭文件*/
}

虽然这是可能的,但在java端获取文件描述符,然后将其传递给本机代码是一种过度消耗。传递输出文件名并用本机代码打开文件更容易:

#include <unistd.h>
#include <fcntl.h>
#include <jni.h>

void my_jni_func(JNIEnv* env, jobject thiz, jstring filename) {
    const char* c_filename = (*env)->GetStringUTFChars(env, filename)
    int output_fd = open(c_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    (*env)->ReleaseStringUTFChars(env, filename, c_filename);

    /* Check output_fd for validity, create muxer, and write streams */

    close(output_fd); /* close file when you've finished with muxer */
}
#包括
#包括
#包括
void my_jni_func(JNIEnv*env,jobject thiz,jstring文件名){
const char*c_filename=(*env)->GetStringUTFChars(env,filename)
int output_fd=open(c_filename,O_WRONLY | O_create | O_TRUNC,0666);
(*env)->ReleaseStringUTFChars(env,文件名,c_文件名);
/*检查输出\u fd的有效性,创建muxer并写入流*/
关闭(output_fd);/*使用完muxer后关闭文件*/
}