Ste*_*e M 8 android ffmpeg storage-access-framework
我试图CATEGORY_OPENABLE从存储访问框架的URI中打开文件描述符.我首先尝试使用sdcard上的文件,我已经可以使用该_data列解析到文件路径并打开(我正在尝试远离这样做,而是使用文件描述符).
我得到了这样的native int fd:
int fd = getContentResolver().openFileDescriptor(data.getData(), "r").detachFd();
Run Code Online (Sandbox Code Playgroud)
然后在C++中,我试图像这样打开它,这个想法取自如何在Android中使用JNI将资产FileDescriptor正确传递给FFmpeg:
pFormatCtx = avformat_alloc_context();
pFormatCtx->iformat = av_find_input_format("mp3");
char path[50];
sprintf(path, "pipe:%d", fd);
int e;
if(e=(avformat_open_input(&pFormatCtx,path,NULL,NULL)!=0)){
av_strerror(e, path, 50);
return error;
}
Run Code Online (Sandbox Code Playgroud)
这会产生"未知错误" avformat_open_input.如果我使用jniGetFDFromFileDescriptor上面链接的jni方法FileDescriptor来获取int fd,则会发生同样的事情.如何在不使用文件路径的情况下正确打开带有FFMPEG的可打开URI?
我的项目(FFmpegMediaMetadataRetriever)实现了这一点。请参阅此处的要点或完整文件。
注意:确保您已经构建了 FFmpeg 并启用了管道协议!
我使用了avformat_open_input文件描述符dup()并确保通过以下方式设置偏移量:
if (state->offset > 0) {
state->pFormatCtx = avformat_alloc_context();
state->pFormatCtx->skip_initial_bytes = state->offset;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
655 次 |
| 最近记录: |