Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38268

Recording live video stream from IP camera issue

Newsgroups comp.lang.python
Date 2013-02-06 04:12 -0800
Message-ID <ffa5fb6e-2d2c-484c-bfae-1014f1d0ebcc@googlegroups.com> (permalink)
Subject Recording live video stream from IP camera issue
From Sam Berry <sambez_14@hotmail.co.uk>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-06 04:12 -0800
  Re: Recording live video stream from IP camera issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-06 23:26 +1100
    Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-06 04:36 -0800
  Fwd: Recording live video stream from IP camera issue Xavier Ho <contact@xavierho.com> - 2013-02-06 23:39 +1100
    Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-06 05:12 -0800
      Re: Recording live video stream from IP camera issue Xavier Ho <contact@xavierho.com> - 2013-02-07 01:35 +1100
        Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-17 06:15 -0800
          Re: Recording live video stream from IP camera issue Xavier Ho <contact@xavierho.com> - 2013-02-18 06:57 +1100
        Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-17 06:15 -0800
    Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-06 05:12 -0800
  Re: Recording live video stream from IP camera issue Sam Berry <sambez_14@hotmail.co.uk> - 2013-02-18 05:03 -0800

csiph-web