Pymedia video encoding failed
- by user1474837
I am using Python 2.5 with Windows XP. I am trying to make a list of pygame images into a video file using this function. I found the function on the internet and edited it. It worked at first, than it stopped working.
This is what it printed out:
Making video...
Formating 114 Frames...
starting loop
making encoder
Frame 1 process 1
Frame 1 process 2
Frame 1 process 2.5
This is the error:
Traceback (most recent call last):
File "ScreenCapture.py", line 202, in <module>
makeVideoUpdated(record_files, video_file)
File "ScreenCapture.py", line 151, in makeVideoUpdated
d = enc.encode(da)
pymedia.video.vcodec.VCodecError: Failed to encode frame( error code is 0 )
This is my code:
def makeVideoUpdated(files, outFile, outCodec='mpeg1video', info1=0.1):
fw = open(outFile, 'wb')
if (fw == None) :
print "Cannot open file " + outFile
return
if outCodec == 'mpeg1video' :
bitrate= 2700000
else:
bitrate= 9800000
start = time.time()
enc = None
frame = 1
print "Formating "+str(len(files))+" Frames..."
print "starting loop"
for img in files:
if enc == None:
print "making encoder"
params= {'type': 0,
'gop_size': 12,
'frame_rate_base': 125,
'max_b_frames': 90,
'height': img.get_height(),
'width': img.get_width(),
'frame_rate': 90,
'deinterlace': 0,
'bitrate': bitrate,
'id': vcodec.getCodecID(outCodec)
}
enc = vcodec.Encoder(params)
# Create VFrame
print "Frame "+str(frame)+" process 1"
bmpFrame= vcodec.VFrame(vcodec.formats.PIX_FMT_RGB24,
img.get_size(),
# Covert image to 24bit RGB
(pygame.image.tostring(img, "RGB"), None, None)
)
print "Frame "+str(frame)+" process 2"
# Convert to YUV, then codec
da = bmpFrame.convert(vcodec.formats.PIX_FMT_YUV420P)
print "Frame "+str(frame)+" process 2.5"
d = enc.encode(da) #THIS IS WHERE IT STOPS
print "Frame "+str(frame)+" process 3"
fw.write(d.data)
print "Frame "+str(frame)+" process 4"
frame += 1
print "savng file"
fw.close()
Could somebody tell me why I have this error and possibly how to fix it? The files argument is a list of pygame images, outFile is a path, outCodec is default, and info1 is not used anymore.
UPDATE 1
This is the code I used to make that list of pygame images.
from PIL import ImageGrab
import time, pygame
pygame.init()
f = [] #This is the list that contains the images
fps = 1
for n in range(1, 100):
info = ImageGrab.grab()
size = info.size
mode = info.mode
data = info.tostring()
info = pygame.image.fromstring(data, size, mode)
f.append(info)
time.sleep(fps)