使用http的Range标头下载视频的后半部分 [英] Download the second half of a video using http's Range header

查看:312
本文介绍了使用http的Range标头下载视频的后半部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载本地主机上的视频的后半部分,我编写了一些python代码以从下半部到最后(通过http的Range标头)下载文件

I want to download the second half of a video I have on my local host, I wrote some python code to download the file starting from the half to the end(via http's Range header)

但是当我用vlc打开文件时,什么也没发生(所以它不起作用)

but when I open the file with vlc, nothing happens(so it doesn't work)

如何下​​载mp4文件的一部分并且仍然可以观看?

how can I download a part of a mp4 file and still be able to watch it?

import urllib2

file_url = 'http://127.0.0.1:8080/vid.mp4'

result = urllib2.urlopen(file_url)
cont_len = result.headers['content-length']
req = urllib2.Request(file_url)
req.headers['Range'] = 'bytes=%s-%s' % (str(int(int(cont_len) / 2)), str(int(cont_len)))

f = urllib2.urlopen(req)
File = open('2ndhalf.mp4', 'w')
File.write(f.read())

我的目的是更快地下载部分视频中的视频,而不是下载整个视频然后将其剪切

推荐答案

您需要下载完整的moov.从那里可以获取到中间框架的偏移量,然后可以下载该框架以结束该框架(假设框架顺序良好,可能,但mp4不需要).接下来,仅使用您希望保留的条目重写moov,并确保将所有偏移量调整为与新的块偏移量匹配.

You would need to download the complete moov. From there you can get the offset to the middle frame, You can then download for that frame to end (assuming the frames are in order, Likely, but not required by mp4). Next rewrite the moov using only the entries you wish to keep, and make sure all the offsets are adjusted to match the new chunks offsets.

这篇关于使用http的Range标头下载视频的后半部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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