c++ - 自定义 AVIOContext 的未定义 AVFormatContext 持续时间

标签 c++ ffmpeg libavcodec libav

问题是为什么字段 AVFormatContext::duration 在之后未定义

avformat_open_input
avformat_find_stream_info

如果在 here 中使用自定义 AVIOContext或 here .

通过简单的文件打开,该字段被设置。 Example

最佳答案

问题是我没有定义搜索函数,所以对于 std::istream 示例,这应该是

static int64_t seekFunction(void* opaque, int64_t offset, int whence)
{

auto& stream = *reinterpret_cast<std::istream*>(opaque);

if(whence == AVSEEK_SIZE)
{
    size_t position = stream.tellg();

    stream.seekg(0, std::ios::beg);
    size_t begin = stream.tellg();

    stream.seekg(0, std::ios::end);
    size_t end = stream.tellg();

    stream.seekg(position, std::ios::beg);

    return end - begin;
}

stream.seekg(offset, std::ios::beg);

return stream.tellg();

}

如果是 eof,您还应该在 readFunction 中为流添加 clear for clear

关于c++ - 自定义 AVIOContext 的未定义 AVFormatContext 持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48626433/

相关文章:

c++ - 在不使用默认构造函数的情况下声明 POD 结构时会实例化什么?

android - 使用 Android NDK 为 x86 编译 FFmpeg 3.1.1

iphone - FFMPEG 编译库和 iOS

c++ - libavcodec/libx264 不产生 B 帧

ffmpeg 没有找到 vcodec libx264

ffmpeg - 使用 ffmpeg/libavcodec 从 x265 (HEVC) 编码视频中提取运动矢量?

c++ - 我的钳位宏有问题

c++ - rand_r 是否是真正的线程安全的?

ffmpeg - 使用 FFmpeg 检索和保存媒体元数据

c++ - 使用 Eclipse CDT 配置 MinGW