是否可以在编码器中播放编码器输出的视频文件? [英] Is it possible to play an output video file from an encoder as it's being encoded?

查看:84
本文介绍了是否可以在编码器中播放编码器输出的视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视频文件,我需要将其编码为H264/AVC并通过HTTP馈送到客户端.我需要的是我在客户端的播放器可以在编码视频时播放视频.

I have a video file, and I need to encode it as H264/AVC and feed to client via HTTP. What i need is that i player at client side can play back the video as it is being encoded.

AFAIK,要使播放器能够在下载视频时播放,必须在视频文件的开头放置"moov atom".但是,编码器(例如:ffmpeg)在完成编码后始终会在文件末尾写入"moov atom".

AFAIK, To enable player to play as the video is downloading, "moov atom" have to be placed at the begnning of the video file. However, encoders (ex: ffmpeg) always write "moov atom" at the end of file after it completes encoding.

编码器是否可以将"moov atom"放在编码输出的开头?还是播放没有Moov原子存在的视频?

Is there any way encoder can put "moov atom" at beginning of encode's output? Or play video without moov atom presence?

预先感谢

LR

推荐答案

是的,这是可行的,但仅适用于某些容器格式.使用QuickTime/MP4容器是不可能的.在这些格式中,moov原子包含样本偏移量(mdat原子中样本的位置).直到对视频进行编码后,才能知道这些内容.使用VOD(视频点播),您可以获取完成的文件,并将moov原子移到最前面,以使流媒体工作更好.但是,如果您正在动态编码,则无法执行此操作.为了使它起作用,您将需要使用面向流的传输格式.像FLV或MPEG-TS之类的东西都可以工作.如果将视频传递到ffmpeg,并告诉它在FLV容器中生成H.264视频,则可以按编码方式将数据提供给播放器,这样便可以正常工作.当然,如果要通过HTTP提供服务,则可能必须编写自己的服务器(或现有服务器的模块).据我所知,没有任何东西支持在编写文件时提供文件(问题是发送内容长度标头时文件大小未知).但是,如果您通过RTMP或RTSP提供视频,则可以使用现有软件来完成此工作.

Yes, this is possible, but only in some container formats. It is NOT possible with a QuickTime/MP4 container. In these formats, the moov atom contains sample offsets (the locations of the samples in the mdat atom). These are not known until after the video has been encoded. With VOD (video on demand) you can take the finished file, and move the moov atom to the front, to make streaming work better. But there is no way to do this if you are encoding on the fly. To make that work, you'll need to use a stream-oriented transport format. Something like FLV or MPEG-TS would work. If you pass video into ffmpeg and tell it to produce H.264 video in an FLV container, you can then serve that data to a player as it's encoded, and it will work. Of course, if you want to serve it over HTTP, you'll probably have to write your own server (or module for an existing server). Nothing that I know of supports serving a file as it is written (an issue is that the file size is not known when the content-length header is sent). If you serve the video over RTMP or RTSP, however, you can make this work with existing software.

这篇关于是否可以在编码器中播放编码器输出的视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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