最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Convert Byte-range to Time-range in html <video> - Stack Overflow

programmeradmin1浏览0评论

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?

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.

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?

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.

Share Improve this question edited May 23, 2017 at 11:54 CommunityBot 11 silver badge asked Mar 15, 2017 at 5:23 fengshaunfengshaun 2,1701 gold badge16 silver badges26 bronze badges 8
  • You can try fetching the video with offset and end_offset – Gyan Commented Mar 15, 2017 at 6:03
  • Those options seem to be only for http streaming directly with ffmpeg. I'm using ffmpeg to transcode only. – fengshaun Commented Mar 15, 2017 at 6:24
  • The mit which added those mention "request ranges". – Gyan Commented Mar 15, 2017 at 6:27
  • Do you have a link to the mit? thanks. – fengshaun Commented Mar 15, 2017 at 6:38
  • github./FFmpeg/FFmpeg/mit/… – Gyan Commented Mar 15, 2017 at 6:41
 |  Show 3 more ments

1 Answer 1

Reset to default 8

You can run ffprobe and analyze its output to identify the timestamps.

Basic mand is

ffprobe -i in.mp4 -show_entries packet=pos,pts_time,flags -select_streams v -of pact=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 mand below:

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.

发布评论

评论列表(0)

  1. 暂无评论