Given below is the Python script I am using for accessing an IP Camera and saving the incoming video stream:
import cv2
from cv2 import cv
writer=cv2.VideoWriter("vid.avi",cv.CV_FOURCC('X', '2', '6', '4'), 24, (320,240))
def cvloop():    
    stream=urllib.urlopen('URL of the camera')
    bytes=''
    while True:
        bytes+=stream.read(1024)
        a = bytes.find('\xff\xd8')
        b = bytes.find('\xff\xd9')
        if a!=-1 and b!=-1:
            jpg = bytes[a:b+2]
            bytes= bytes[b+2:]
            i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)            
            tki = ImageTk.PhotoImage(Image.fromarray(cv2.cvtColor(i, cv2.COLOR_BGR2RGB)))
            cv2.imshow('i',i)
            writer.write(i)
            if cv2.waitKey(1) ==27:
                exit(0)
Now, if you want to know why I am parsing the jpg images from the stream the answer can be found here. The answer explains everything.
As for the video writer script, I have referred OpenCV's documentation which can be found here.
Now instead of using the default list of codecs I am using H-264 but I have tried all the codecs installed on my system.
Question: Now the problem is on executing the program the video file is being made, on running it I see nothing. Also, on using the software GSpot to analyse the video, I am getting the number of frames in the video. Same is the case with FFMPEG. Where am I going wrong?
Camera: Axis IP Camera M1103
OS: Windows 7 32bit
 
    