gpt4 book ai didi

android - 如何创建 NDK AMediaMuxer?

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:42 26 4
gpt4 key购买 nike

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

MediaMuxer(@NonNull String path, @Format int format)

当混合器的 JNI 版本使用文件描述符时。

AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format);

一种方法是使用 Assets ,但 Assets 就像资源文件一样:只读。所以这不是这样做的好方法。

创建 fileDescriptor 并将其传递给 JNI muxer 构造函数的好方法是什么?

谢谢。

最佳答案

虽然这是可能的 - 在 Java 端获取文件描述符然后将其传递给 native 代码是过大的杀伤力。在 native 代码中传递输出文件名和打开文件要容易得多:

#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 */
}

关于android - 如何创建 NDK AMediaMuxer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44974918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com