ptypy.utils.scripts.png2mpg#

ptypy.utils.scripts.png2mpg(listoffiles, framefile='frames.txt', fps=5, bitrate=2000, codec='wmv2', Encode=True, RemoveImages=False)#

Makes a movie (*.mpg) from a collection of *.png or *.jpeg frames. Requires binary of mencoder installed on system

Parameters:
  • listoffiles (list of str) – A list of paths to files. Each file will be reinterpreted as a collection files in the same directory, e.g. only the first file in a series needs to be selected. All series for which a first file was given will be concatenated in the movie. May also be a textfile with a listing of frames in which case the creation of an intermediate file of frame paths will be skipped.

  • framefile (str) – Filepath, the respective file will be created to store a list of all frames. This file will be used by mencoder later.

  • fps (scalar) – Frames per second in final movie

  • bitrate (int) – Encoding detail, determines video quality

  • codec (str) – Defines the codec to Use

  • Encode (bool) – If True, video will be encoded calling mencoder If False, mencoder will not be called, but the necessary command expression will be returned instead. Very well suited for a dry-run

  • RemoveImages (bool) – If True, all images referred to by framefile are deleted except for the last frame.

Returns:

cmd – Command string for the shell to encode the video later manually.

Return type:

str

Examples

>>> from ptypy.utils.scripts import png2mpg
>>> png2mpg(['/path/to/image_000.png'])

The following happens: 1) search for files similar to image_*.png in ‘/path/to/’ 2) found files get listed in a file ‘/path/to/frames.txt’ 3) calls mencoder to use that file to encode a movie with the default args. 4) movie is in the same folder as ‘frames.txt’ and is called ‘frames.mpg’

>>> png2mpg(['/path1/to/imageA_040.png', '/path2/to/imageB_001.png'],
>>>         framefile='./banana.txt')

Generates list file ‘banana_text’ in current folder. The list file contains in order every path compatible with the wildcards ‘/path1/to/imageA_*.png’ and ‘/path2/to/imageB_*.png’

>>> str = png2mpg(['/path/to/image_000.png'], Encode=False)

Returns encoder argument string. Use os.system(encoderstring) for encoding manually later