网络 - 视频:字节范围到时间 [英] Web - Video : bytes range to time

查看:51
本文介绍了网络 - 视频:字节范围到时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于从 url 流式传输视频的 PHP 脚本,我想花时间控制流.

I have a PHP script for stream a video from an url, and I want to get the time to control the flow.

浏览器在每次跳转视频时使用一系列字节发出 HTTP 请求.

Browsers makes HTTP requests with a range of bytes when jumping at a time of the video.

请求标头

Accept:*/ *
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Host:h.com
If-Range:Tue, 20 Oct 2015 23:38:00 GMT
Range:bytes=560855038-583155711
Referer:http://h.com/7743a76d2911cdd90354bc42be302c6946c6e5b4
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36

响应标头

Accept-Ranges:bytes
Cache-Control:private, max-age=14400
Connection:Keep-Alive
Content-Length:22300674
Content-Range:bytes 560855038-583155711/605162520
Content-Type:video/mp4
Date:Tue, 10 May 2016 11:23:34 GMT
Expires:Tue, 10 05 2016 15:23:34 GMT
Keep-Alive:timeout=5, max=98
Last-Modified:Tue, 20 Oct 2015 23:38:00 GMT
Server:Apache/2.4.7 (Ubuntu)
X-Powered-By:PHP/5.5.9-1ubuntu4.16

这段时间到字节转换的工作原理是什么?

How works that time to bytes conversion ?

在我的 PHP 服务器上,我尝试从字节请求中获取时间:

On my PHP server I try to get the time from the byte request :

$time_second = $start_request_byte / $video_size_byte * $video_length_second;

但这不是解决方案,也不准确......有什么想法吗?

But it's not the solution, it isn't exact... Any ideas ?

谢谢

推荐答案

好的,我找到了使用 ffprobe 的解决方案!

Ok, I found a solution using ffprobe !

命令

$ ffprobe -i 430079256.mp4 -show_frames 
-show_entries frame=pkt_pos 
-read_intervals 01:23%+#1 
-of default=noprint_wrappers=1:nokey=1 
-hide_banner -loglevel panic

输出

偏移字节 => 视频的 1:23

Offset byte => 1:23 of the video

209782270

解释

  • -i 430079256.mp4视频输入
  • -show_frames显示每一帧的信息
  • -show_entries frame=pkt_pos 仅显示有关字节位置的信息
  • -read_intervals 01:23%+#1 搜索到 01:23 位置后只读取 1 个数据包
  • -of default=noprint_wrappers=1:nokey=1 不想打印密钥以及部分页眉和页脚
  • -hide_banner -loglevel panic 不想打印ffprob的banner,用只显示致命错误的panic"隐藏meta
  • -i 430079256.mp4 Video input
  • -show_frames Display information about each frame
  • -show_entries frame=pkt_pos Display only information about byte position
  • -read_intervals 01:23%+#1 Read only 1 packet after seeking to position 01:23
  • -of default=noprint_wrappers=1:nokey=1 Don't want to print the key and the section header and footer
  • -hide_banner -loglevel panic Don't want to print banner of ffprob, and hide meta on with "panic" who only show fatal errors

这篇关于网络 - 视频:字节范围到时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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