FFmpeg 如何将视频写入文件 [英] FFmpeg How to write video to a file

查看:97
本文介绍了FFmpeg 如何将视频写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是

 1. Get video packet from stream source
 2. Decode it
 3. And write  that decoded data as video file(avi, mpeg etc)

我可以从文件中获取视频数据包(作为 AVPacket),也可以解码并保存为图像.(原始)(FFmpeg 教程展示了如何做到这一点).但我不能(不知道)将该视频数据写入一个文件(其他)可以由媒体播放器(例如 VLC)播放.

I can able to get video Packets from a file (as AVPacket) and also can decode and save as an image.(raw)( FFmpeg tutorials show how to do it). But i can not ( do not know ) write that video data to a file(other) which can be played by media players(such as VLC).

最美好的祝愿

Ps:如果可能的话,真实的代码示例会很棒...

Ps: Real code samples will be great if possible...

现在我使用 av_interleaved_write 进行测试,但我得到了奇怪的错误非单调时间戳"(我无法控制媒体源的 pts 值)

Now i make test with av_interleaved_write but i got strange error "non monotone timestamps" ( i have no control over pts values of media source )

一些额外信息

在 FFmpeg 中我必须

In FFmpeg I have to

  1. 从媒体源(可能是真实文件(.avi、mov)甚至rtsp服务器)读取媒体包.
  2. 然后将这些媒体数据包写入真实文件(物理 .avi、.mov 等文件)

我需要读者和作家.我可以读取媒体源文件(甚至根据给定的格式对数据包进行编码).但我无法写入文件...(任何玩家都可以玩)

I need reader and writer. I can read the media source file ( even encode packets according to given format). But i can not write to file...(which any player can play)

还有一些伪代码

File myFile("MyTestFile.avi");

while ( source ->hasVideoPackets)
{
     packet = source->GetNextVideoPacket();
     Frame decodedFrame = Decode(packet);
     VideoPacket encodedPacket = Encode( decodedFrame);
     myFile.WriteFile(encodedPacket);
 }

或者直接写原文件不编码解码

Or Just write the original file without encode decode

     File myFile("MyTestFile.avi");

     while ( source ->hasVideoPackets)
     {
         packet = source->GetNextVideoPacket();
         myFile.WriteFile(packet);
     }

然后

I can able to open MyTest.avi file with a player.

推荐答案

现在在 FFmpeg 主干的 doc/examples/transcoding.c 中有一个新的视频转码示例,它完全符合您的要求需要:用于解复用、解码、过滤、编码和复用的 API 示例.

Now there's a new example of video transcoding in doc/examples/transcoding.c of FFmpeg trunk, and it does exactly what you need: API example for demuxing, decoding, filtering, encoding and muxing.

这是针对当前的ffmpeg 2.4.4

这篇关于FFmpeg 如何将视频写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆