[Tutor] Movies from jpg files

János Juhász janos.juhasz at VELUX.com
Sun Apr 8 14:57:31 CEST 2007


Dear Greg,

thanks the link to pymedia.

> Maybe PyMedia is what you are looking for:  http://www.pymedia.org

I looked for it for a while. It is very cool.
I made the next short script from one of the samples that make exactly 
what I wanted.

###########

import sys, os, glob, Image, time
import pymedia.video.vcodec as vcodec

def files2Video(files, outFile='out.mpg', outCodec='mpeg1video'):
  s= Image.open(files[0])
  if outCodec== 'mpeg1video': bitrate= 2700000
  else:                       bitrate= 9800000
  params= { 'type': 0, 'gop_size': 12, 'frame_rate_base': 125, 
'max_b_frames': 0,
            'width': s.size[0], 'height': s.size[1], 'frame_rate': 2997,
            'deinterlace': 0,'bitrate': bitrate, 'id': 
vcodec.getCodecID(outCodec)
          }
  e= vcodec.Encoder(params)

  fw= open(outFile, 'wb')
  for ActPic in files:
    s= Image.open(ActPic)
    ss= s.tostring()
    bmpFrame= vcodec.VFrame(vcodec.formats.PIX_FMT_RGB24, s.size, 
(ss,None,None))
    yuvFrame= bmpFrame.convert(vcodec.formats.PIX_FMT_YUV420P)
    d= e.encode(yuvFrame)
    fw.write(d.data)
  fw.close()

if __name__== '__main__':
    files = glob.glob(r'.\test\*.jpg')
    files.sort(key=lambda f:(os.stat(f).st_mtime, f))
    files2Video(files, time.strftime('Cam1_%Y%m%d%H%M.mpg', 
time.localtime()))
    [os.remove(f) for f in files]

###########

Python is Cool :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070408/ac88ca12/attachment.htm 


More information about the Tutor mailing list