问题
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)
but when I open the file with vlc, nothing happens(so it doesn't work)
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())
Edit: my intention is to download videos the part of the videos faster, and not to download the whole video and then cut it
回答1:
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.
来源:https://stackoverflow.com/questions/42470133/download-the-second-half-of-a-video-using-https-range-header