I have some sever-side code that currently supports the http byte range requests without an issue. However, I want to be able to transcode the video file (which is located on-disk) on-the-fly with ffmpeg before I send the transcoded chunk to the client, but ffmpeg requires I give it a seek time whereas I get byte ranges from the client. How would I be able to figure out the time range (seek time) of a video file given the byte range from the client browser?
我有一些当前支持http字节范围请求的服务器端代码没有问题。但是,我希望能够在将转码后的块发送到客户端之前使用ffmpeg对视频文件(位于磁盘上)进行转码,但ffmpeg要求我给它一个寻道时间,而我得到字节范围从客户端。在给定客户端浏览器的字节范围的情况下,我如何能够计算出视频文件的时间范围(寻道时间)?
I have already looked at this question which assumes the server already knows the specified time.
我已经看过这个问题,假设服务器已经知道指定的时间。
I am open to using an html5 video player which supports the use of time ranges to request data instead of byte ranges, but I have been unable to find an implementation or figure out how the javascript side of buffering <video>
works.
我愿意使用支持使用时间范围来请求数据而不是字节范围的html5视频播放器,但我一直无法找到实现或弄清楚缓冲
1 个解决方案
#1
2
You can run ffprobe and analyze its output to identify the timestamps.
您可以运行ffprobe并分析其输出以标识时间戳。
Basic command is
基本命令是
ffprobe -i in.mp4 -show_entries packet=pos,pts_time,flags -select_streams v -of compact=p=0:nk=1 -v 0
This produces
0.000000|48|K_
0.133333|956|__
0.066667|996|__
0.033333|1053|__
0.100000|1602|__
0.266667|1811|__
0.200000|2371|__
0.166667|2746|__
0.233333|3294|__
....
The first column is the video frame timestamp, the 2nd is the byte offset for that frame and the 3rd is whether the frame is a keyframe.
第一列是视频帧时间戳,第二列是该帧的字节偏移量,第三列是帧是否是关键帧。
Since you can only cut video at keyframes, when copying the stream, you will either have to cut at a timestamp whose flag is K
or use the argument in the command below:
由于您只能在关键帧处剪切视频,因此在复制流时,您必须剪切其标志为K的时间戳或使用以下命令中的参数:
ffmpeg -ss X -i in.mp4 -c copy -avoid_negative_ts make_zero out.mp4
This is not needed if you're transcoding the video stream.
如果您要对视频流进行转码,则不需要这样做。
#1
2
You can run ffprobe and analyze its output to identify the timestamps.
您可以运行ffprobe并分析其输出以标识时间戳。
Basic command is
基本命令是
ffprobe -i in.mp4 -show_entries packet=pos,pts_time,flags -select_streams v -of compact=p=0:nk=1 -v 0
This produces
0.000000|48|K_
0.133333|956|__
0.066667|996|__
0.033333|1053|__
0.100000|1602|__
0.266667|1811|__
0.200000|2371|__
0.166667|2746|__
0.233333|3294|__
....
The first column is the video frame timestamp, the 2nd is the byte offset for that frame and the 3rd is whether the frame is a keyframe.
第一列是视频帧时间戳,第二列是该帧的字节偏移量,第三列是帧是否是关键帧。
Since you can only cut video at keyframes, when copying the stream, you will either have to cut at a timestamp whose flag is K
or use the argument in the command below:
由于您只能在关键帧处剪切视频,因此在复制流时,您必须剪切其标志为K的时间戳或使用以下命令中的参数:
ffmpeg -ss X -i in.mp4 -c copy -avoid_negative_ts make_zero out.mp4
This is not needed if you're transcoding the video stream.
如果您要对视频流进行转码,则不需要这样做。