Recording live video stream from IP camera issue

Sam Berry sambez_14 at hotmail.co.uk
Wed Feb 6 13:12:44 CET 2013


Hey,

I have no vast knowledge of python, but i came across this code to capture video from my IP camera

import urllib2
import time
import logging

print "Recording video..."
response = urllib2.urlopen("IP Address")
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 * 20  # end in 20 mb
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:
        logging.exception(e)
f.close()

This code works, however when i try to playback the .avi file in VLC player (file wont open in any other media player) it just flashes an image instead of a video file, even though the .avi file is around 20mb.

Is there some extra lines of code i need to include or change? Perhaps a timing option instead of a file size?

Any help or insight would be much appreciated!!

Thanks, Sam



More information about the Python-list mailing list