繁体   English   中英

FFmpeg解码.mp4视频文件

[英]FFmpeg decoding .mp4 video file

我正在一个项目中,该项目需要打开.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()函数,我不能使用开放输入.mp4档案avformat_open_input()因为它的会填充filename中的一部分AVFormatContext结构,输入文件名,所以不能“写入”到该文件中。 我曾尝试使用av_guess_format()尝试不同的解决方案,但是当我使用dump_format()转储格式时,我什么也没得到,所以我找不到有关它正在使用哪种编解码器的流信息。

因此,如果有人有任何建议,我将非常感谢。 先感谢您。

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

  1. 设置则将ctx-> oformat使用av_guess_format
  2. 使用avio_open2设置ctx-> pb
  3. 为输出文件中的每个流调用avformat_new_stream 如果要重新编码,这是通过将输入文件的每个流添加到输出文件中来进行的。
  4. 呼叫avformat_write_header
  5. 循环调用av_interleaved_write_frame
  6. 致电av_write_trailer
  7. 关闭文件( avio_close )并清除所有分配的内存

您可以使用以下方法将视频转换为一系列损失图像:

ffmpeg -i video.mp4 image-%05d.png

然后从一系列图像返回到具有以下内容的视频:

ffmpeg -i image-%05d.png video.mp4

该功能也可以通过包装器使用。

您可以在以下位置看到类似的问题: 从MP4 / FLV中提取帧吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM