I am developing a script to download live online video.
My Script:
print "Recording video..."
response = urllib2.urlopen("streaming online video url")
filename = time.strftime("%Y%m%d%H%M%S",time.localtime())+".avi"
f = open(filename, 'wb')
video_file_size_start = 0
video_file_size_end = 1048576 * 7
block_size = 1024
while True:
try:
buffer = response.read(block_size)
if not buffer:
break
video_file_size_start += len(buffer)
if video_file_size_start > video_file_size_end:
break
f.write(buffer)
except Exception, e:
logger.exception(e)
f.close()
The above script works great to download 7Mb video from streaming content and save it in * .avi files.
However, I would like to upload just 10 seconds of video regardless of file size and save it in an avi file.
I tried different possibilities, but to no avail.
Can someone please share your knowledge here to fix my problem.
Thanks in advance.
source
share