| | |
Image to Video Converter Code Snippet
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Does anyone here have a wxPython code that converts a folder of images to a .wmv file just by clicking a button?
What I did in my program was I load an Image-to-Video Converter Software by clicking a button but I feel that it would be better if I can directly convert the images to a video just by clicking the button.
Hope someone can help me out here. Thanks so much.
-Karen
What I did in my program was I load an Image-to-Video Converter Software by clicking a button but I feel that it would be better if I can directly convert the images to a video just by clicking the button.
Hope someone can help me out here. Thanks so much.
-Karen
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Hi Jeff,
In the Image-to-Video software that I am using, the size of the images does not matter and the frame rate is set by the user. So I was thinking, I can just set the frame rate to be fixed say 5 frames/sec so when the button is clicked, it will automatically convert the images to video. However, I can also add that feature to my GUI such that when the button is clicked, it will ask for the desired frame rate first before actually converting. But I guess that will make things more complicated because to begin with, I have no idea how the conversion code should look like.
-Karen
In the Image-to-Video software that I am using, the size of the images does not matter and the frame rate is set by the user. So I was thinking, I can just set the frame rate to be fixed say 5 frames/sec so when the button is clicked, it will automatically convert the images to video. However, I can also add that feature to my GUI such that when the button is clicked, it will ask for the desired frame rate first before actually converting. But I guess that will make things more complicated because to begin with, I have no idea how the conversion code should look like.
-Karen
The last PyMedia release I saw was for Python24:
http://downloads.sourceforge.net/pym...e_mirror=voxel
However, it is possible to create a video with it from within a Python program. Here is an example called make_video.py they list at
http://downloads.sourceforge.net/pym...irror=internap
...
http://downloads.sourceforge.net/pym...e_mirror=voxel
However, it is possible to create a video with it from within a Python program. Here is an example called make_video.py they list at
http://downloads.sourceforge.net/pym...irror=internap
...
python Syntax (Toggle Plain Text)
#! /bin/env python import sys, os, time import pymedia.video.vcodec as vcodec import pygame def makeVideo( inPattern, outFile, outCodec ): # Get video stream dimensions from the image size pygame.init() i= 1 # Opening mpeg file for output e= None i= 1 fw= open( outFile, 'wb' ) while i: if os.path.isfile( inPattern % i ): s= pygame.image.load( inPattern % i ) if not e: if outCodec== 'mpeg1video': bitrate= 2700000 else: bitrate= 9800000 params= { \ 'type': 0, 'gop_size': 12, 'frame_rate_base': 125, 'max_b_frames': 0, 'height': s.get_height(), 'width': s.get_width(), 'frame_rate': 2997, 'deinterlace': 0, 'bitrate': bitrate, 'id': vcodec.getCodecID( outCodec ) } print 'Setting codec to ', params e= vcodec.Encoder( params ) t= time.time() # Create VFrame ss= pygame.image.tostring(s, "RGB") bmpFrame= vcodec.VFrame( vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None)) yuvFrame= bmpFrame.convert( vcodec.formats.PIX_FMT_YUV420P ) d= e.encode( yuvFrame ) fw.write( d.data ) i+= 1 else: print '%d frames written in %.2f secs( %.2f fps )' % ( i, time.time()- t, float( i )/ ( time.time()- t ) ) i= 0 fw.close() pygame.quit() if __name__== '__main__': if len( sys.argv )!= 4: print "Usage: make_video <in_file_pattern> <out_file> <format>\n\tformat= { mpeg1video | mpeg2video }" else: makeVideo( sys.argv[ 1 ], sys.argv[ 2 ], sys.argv[ 3 ] )
May 'the Google' be with you!
•
•
Join Date: Jan 2008
Posts: 1
Reputation:
Solved Threads: 1
I've tried many Video Converter download from internet and choose the best to share here, Daniusoft Video Converter which could help you convert convert video format to MPEG/WMV/AVI and other popular video formats such as: MP4, FLV, 3GP, ASF, MOV, M4V, MPG, VOB, XviD with high speed and excellent quality. Also let you set the movie effects.
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
I tried running make_video.py by including it in my main code but I can't seem to make it work. Here's the code. The error says that not all arguments converted during string formatting at this line:
if os.path.isfile( inPattern % i ):
Can someone please help me? Can this program convert .jpg images to a video assuming that all images have the same size and the fps is set to be 0.5 ?
Thank you so much.
self.Bind(wx.EVT_BUTTON, self.makeVideo, self.ConverterButton)
def makeVideo(self, evt):
outFile = 'C:/Documents and Settings/12345/Desktop/nyeh.mpg'
inPattern = 'C:/Documents and Settings/12345/My Documents/Files/ACADEMICS/ECE 198/GUI/cam_pics'
outCodec = 'mpeg1video'
# Get video stream dimensions from the image size
pygame.init()
i= 1
# Opening mpeg file for output
e= None
i= 1
fw= open( outFile, 'wb' )
while i:
if os.path.isfile( inPattern % i ):
s= pygame.image.load( inPattern % i )
if not e:
if outCodec== 'mpeg1video':
bitrate= 2700000
else:
bitrate= 9800000
params= { \
'type': 0,
'gop_size': 12,
'frame_rate_base': 10,
'max_b_frames': 0,
'height': s.get_height(),
'width': s.get_width(),
'frame_rate': 2997,
'deinterlace': 0,
'bitrate': bitrate,
'id': vcodec.getCodecID( outCodec )
}
print 'Setting codec to ', params
e= vcodec.Encoder( params )
t= time.time()
# Create VFrame
ss= pygame.image.tostring(s, "RGB")
bmpFrame= vcodec.VFrame( vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None))
yuvFrame= bmpFrame.convert( vcodec.formats.PIX_FMT_YUV420P )
d= e.encode( yuvFrame )
fw.write( d.data )
i+= 1
else:
print '%d frames written in %.2f secs( %.2f fps )' % ( i, time.time()- t, float( i )/ ( time.time()- t ) )
i= 0
fw.close()
pygame.quit()
if os.path.isfile( inPattern % i ):
Can someone please help me? Can this program convert .jpg images to a video assuming that all images have the same size and the fps is set to be 0.5 ?
Thank you so much.
self.Bind(wx.EVT_BUTTON, self.makeVideo, self.ConverterButton)
def makeVideo(self, evt):
outFile = 'C:/Documents and Settings/12345/Desktop/nyeh.mpg'
inPattern = 'C:/Documents and Settings/12345/My Documents/Files/ACADEMICS/ECE 198/GUI/cam_pics'
outCodec = 'mpeg1video'
# Get video stream dimensions from the image size
pygame.init()
i= 1
# Opening mpeg file for output
e= None
i= 1
fw= open( outFile, 'wb' )
while i:
if os.path.isfile( inPattern % i ):
s= pygame.image.load( inPattern % i )
if not e:
if outCodec== 'mpeg1video':
bitrate= 2700000
else:
bitrate= 9800000
params= { \
'type': 0,
'gop_size': 12,
'frame_rate_base': 10,
'max_b_frames': 0,
'height': s.get_height(),
'width': s.get_width(),
'frame_rate': 2997,
'deinterlace': 0,
'bitrate': bitrate,
'id': vcodec.getCodecID( outCodec )
}
print 'Setting codec to ', params
e= vcodec.Encoder( params )
t= time.time()
# Create VFrame
ss= pygame.image.tostring(s, "RGB")
bmpFrame= vcodec.VFrame( vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None))
yuvFrame= bmpFrame.convert( vcodec.formats.PIX_FMT_YUV420P )
d= e.encode( yuvFrame )
fw.write( d.data )
i+= 1
else:
print '%d frames written in %.2f secs( %.2f fps )' % ( i, time.time()- t, float( i )/ ( time.time()- t ) )
i= 0
fw.close()
pygame.quit()
Karen,
Please use code tags when posting code, or else it will become unreadable as it has above.
To use the code tags, wrap your code like this:
[code=python]
# Code inside here
[/code]
This will turn on syntax highlighting and preserve your indentation. Also, forum members are much more inclined to help you if your post isn't a huge mess of plain text.
Please use code tags when posting code, or else it will become unreadable as it has above.
To use the code tags, wrap your code like this:
[code=python]
# Code inside here
[/code]
This will turn on syntax highlighting and preserve your indentation. Also, forum members are much more inclined to help you if your post isn't a huge mess of plain text.
Last edited by jlm699; Mar 19th, 2009 at 9:14 am.
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Thanks Jim. Here it is. I am not sure if I correctly set inPattern and outFile that's why the code isn't working. Hope someone can help me. Thanks.
python Syntax (Toggle Plain Text)
self.Bind(wx.EVT_BUTTON, self.makeVideo, self.ConverterButton) def makeVideo(self, evt): #make_video.py outFile = 'C:/Documents and Settings/12345/Desktop/nyeh.mpg' inPattern = 'C:/Documents and Settings/12345/My Documents/Files/ACADEMICS/ECE 198/GUI/cam_pics' outCodec = 'mpeg1video' # Get video stream dimensions from the image size pygame.init() i= 1 # Opening mpeg file for output e= None i= 1 fw= open( outFile, 'wb' ) while i: if os.path.isfile( inPattern % i ): s= pygame.image.load( inPattern % i ) if not e: if outCodec== 'mpeg1video': bitrate= 2700000 else: bitrate= 9800000 params= { \ 'type': 0, 'gop_size': 12, 'frame_rate_base': 10, 'max_b_frames': 0, 'height': s.get_height(), 'width': s.get_width(), 'frame_rate': 2997, 'deinterlace': 0, 'bitrate': bitrate, 'id': vcodec.getCodecID( outCodec ) } print 'Setting codec to ', params e= vcodec.Encoder( params ) t= time.time() # Create VFrame ss= pygame.image.tostring(s, "RGB") bmpFrame= vcodec.VFrame( vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None)) yuvFrame= bmpFrame.convert( vcodec.formats.PIX_FMT_YUV420P ) d= e.encode( yuvFrame ) fw.write( d.data ) i+= 1 else: print '%d frames written in %.2f secs( %.2f fps )' % ( i, time.time()- t, float( i )/ ( time.time()- t ) ) i= 0 fw.close() pygame.quit()
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Thanks Jim. Here it is. I am not sure if I correctly set inPattern and outFile that's why the code isn't working. Hope someone can help me. And can make_video.py convert a folder of .jpg images to a .mpg video file?
python Syntax (Toggle Plain Text)
self.Bind(wx.EVT_BUTTON, self.makeVideo, self.ConverterButton) def makeVideo(self, evt): #make_video.py outFile = 'C:/Documents and Settings/12345/Desktop/nyeh.mpg' inPattern = 'C:/Documents and Settings/12345/My Documents/Files/ACADEMICS/ECE 198/GUI/cam_pics' outCodec = 'mpeg1video' # Get video stream dimensions from the image size pygame.init() i= 1 # Opening mpeg file for output e= None i= 1 fw= open( outFile, 'wb' ) while i: if os.path.isfile( inPattern % i ): s= pygame.image.load( inPattern % i ) if not e: if outCodec == 'mpeg1video': bitrate= 2700000 else: bitrate= 9800000 params= { \ 'type': 0, 'gop_size': 12, 'frame_rate_base': 10, 'max_b_frames': 0, 'height': s.get_height(), 'width': s.get_width(), 'frame_rate': 2997, 'deinterlace': 0, 'bitrate': bitrate, 'id': vcodec.getCodecID( outCodec ) } print 'Setting codec to ', params e= vcodec.Encoder( params ) t= time.time() # Create VFrame ss= pygame.image.tostring(s, "RGB") bmpFrame= vcodec.VFrame(vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None)) yuvFrame= bmpFrame.convert(vcodec.formats.PIX_FMT_YUV420P) d= e.encode( yuvFrame ) fw.write( d.data ) i+= 1 else: print '%d frames written in %.2f secs( %.2f fps )' % (i,time.time()- t, float( i )/(time.time()- t)) i= 0 fw.close() pygame.quit()
![]() |
Other Threads in the Python Forum
- Previous Thread: Python search command ???
- Next Thread: Script arguments parsing.
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext string strings syntax table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






