August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
Cookbook Example
How can I...?
Example 10: Simple dirac encoder/decoder. Shows how to read raw video frames from a file, encode them using dirac, decode them again, and then playback via a video overlay. Components used:ReadFileAdaptor, RawYUVFramer, DiracEncoder, DiracDecoder, VideoOverlay .
Download and build dirac first!
Get the source raw video file (in rgb format) from here, and gunzip it:
http://sourceforge.net/project/showfiles.php?group_id=102564&package_id=119507
To convert RGB to YUV:
RGBtoYUV420 snowboard-jum-352x288x75.rgb snowboard-jum-352x288x75.yuv 352 288 75
Alternatively, source your own AVI file and convert with:
ffmpeg -i file_from_digital_camera.avi rawvideo.yuv
and alter the config below as required.
#!/usr/bin/python
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Codec.RawYUVFramer import RawYUVFramer
from Kamaelia.Codec.Dirac import DiracEncoder, DiracDecoder
from Kamaelia.UI.Pygame.VideoOverlay import VideoOverlay
= "/data/dirac-video/snowboard-jum-352x288x75.yuv"
FILENAME = (352,288)
SIZE = "CIF" # dirac resolution and encoder settings preset
DIRACPRESET
# encoder param sets it to iframe only (no motion based coding, faster)
# (overrides preset)
= {"num_L1":0}
ENCPARAMS
="bitrate", bitrate= 1000000),
pipeline( ReadFileAdaptor(FILENAME, readmode=SIZE ),
RawYUVFramer( size=DIRACPRESET, encParams=ENCPARAMS ),
DiracEncoder(preset
DiracDecoder(),
VideoOverlay() ).run()
Source: Examples/example10/SimpleDiracEncodeDecode.py