直接使用ffmpeg访问FileProvider 提供出去的content uri会报protocol not support,正确的方式是使用ffmpeg访问uri 转换后的 fd
cpp
//---- 读、seek 回调 ----
static int readFn(void *opaque, uint8_t *buf, int buf_size) {
int fd = (int) (intptr_t) opaque;
return read(fd, buf, buf_size);
}
static int64_t seekFn(void *opaque, int64_t offset, int whence) {
int fd = (int) (intptr_t) opaque;
return lseek(fd, offset, whence);
}
// 1. AVIO
uint8_t *ioBuf = (uint8_t *) av_malloc(32768);
LOGI("extractFrameUri ++++++++++++++++++++++++ 3");
avio = avio_alloc_context(
ioBuf, 32768, 0, (void *) (intptr_t) fd,
readFn, nullptr, seekFn);
if (!avio) {
LOGE("avio_alloc_context fail");
goto cleanup;
}
LOGI("extractFrameUri ++++++++++++++++++++++++ 4");
// 2. 打开封装
fmt = avformat_alloc_context();
LOGI("extractFrameUri ++++++++++++++++++++++++ 5");
fmt->pb = avio;
if (avformat_open_input(&fmt, nullptr, nullptr, nullptr) < 0) {
LOGE("avformat_open_input fail");
goto cleanup;
}
LOGI("extractFrameUri ++++++++++++++++++++++++ 6");
// 开始进行抽帧处理
result = extract_video_with_time_range(fmt,
outputDir,
sectionList,
frame_interval,
clip_row_cnt, clip_column_cnt,
use_soft_decode);
LOGI("extractFrameUri ++++++++++++++++++++++++ 7");