gpt4 book ai didi

c - FFmpeg 解码 .mp4 视频文件

转载 作者:行者123 更新时间:2023-12-04 00:10:57 35 4
gpt4 key购买 nike

我正在开发一个需要打开 .mp4 文件格式、逐帧读取帧、解码它们并使用更好的无损压缩类型对其进行编码并将它们保存到文件中的项目。

如果我做事的顺序有误,请纠正我,因为我不是 100% 确定应该如何做这件事。据我了解,它应该是这样的:

1. Open input .mp4 file
2. Find stream info -> find video stream index
3. Copy codec pointer of found video stream index into AVCodecContext type pointer
4. Find decoder -> allocate codec context -> open codec
5. Read frame by frame -> decode the frame -> encode the frame -> save it into a file

到目前为止,我遇到了几个问题。例如,如果我想使用 av_interleaved_write_frame() 保存帧功能,我无法使用 avformat_open_input() 打开输入 .mp4 文件因为它将填充 filename AVFormatContext 的一部分具有输入文件名的结构,因此我无法“写入”该文件。我使用 av_guess_format() 尝试了不同的解决方案但是当我使用 dump_format() 转储格式时我什么也没得到,所以我找不到有关它使用哪个编解码器的流信息。

因此,如果有人有任何建议,我将不胜感激。先感谢您。

最佳答案

请参阅 muxing docs 中的“详细说明”。你:

  • 使用 oformat 设置 ctx-> av_guess_format
  • 使用 pb 设置 ctx-> avio_open2
  • 为输出文件中的每个流调用 avformat_new_stream。如果您正在重新编码,这是通过将输入文件的每个流添加到输出文件中。
  • 调用avformat_write_header
  • 循环调用av_interleaved_write_frame
  • 调用av_write_trailer
  • 关闭文件(avio_close)并清除所有分配的内存
  • 关于c - FFmpeg 解码 .mp4 视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35771821/

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