Search code examples
pythonpyqt4ctypesvapoursynth

Python libass or VapourSynth?


I am using VapourSynth as libass wrapper for a video preview of an application wich generates special .ass files, the returned video frame should be outputted to a QImage object of pyqt4.

I've read VapourSynth documentation about get_read_ptr, they says it is a pointer of an image encoded as frame.format says, in my case frame.format is RGB24. My question is: How can I access raw frame data and seve it to a QImage object to display?

Here is my code, i am not good enougth at ctypes :/

import vapoursynth as vs
# needed for stdout
import sys
from PyQt4 import QtGui
import ctypes
# create a core instance
core = vs.Core()

core.std.LoadPlugin(path=r'C:\Shared\VapourSynth\plugins\ffms2.dll')
# open a video file; ret is now a clip object
ret = core.ffms2.Source(source='Fisica.o.Chimica.S01E01.iTALiAN.WWW.ITALIA-LINK.COM .avi')

# output the clip to stdout with y4m headers (useful for x264 encoding/mplayer playback)
# ret.output(sys.stdout, y4m=True)

print(str(ret.width)+"x"+str(ret.height)+"@"+str(ret.fps_den)+"fps")
print(ret.format)

frame = ret.get_frame(10000)

data = frame.get_read_ptr(0)
print(data)
d = ctypes.pointer(data)
print(d)
print(d.contents)
print(frame.props)

currently returns:

640x480@1fps
Format Descriptor
    Id: 3000010
    Name: YUV420P8
    Color Family: YUV
    Sample Type: Integral
    Bits Per Sample: 8
    Bytes Per Sample: 1
    Planes: 3
    Subsampling W: 1
    Subsampling H: 1

c_void_p(100597856)
<__main__.LP_c_void_p object at 0x02FD0170>
c_void_p(100597856)
<vapoursynth.VideoProps object at 0x02D78050>


Solution

  • You might get an answer by posting in the VapourSynth thread over at Doom9. The author is very helpful.

    Also, there's now a native libass plugin for VS. Oddly enought is named assvapour. http://code.google.com/p/vapoursynth/source/browse/trunk/src/filters/assvapour/assvapour.c?spec=svn384&r=384

    Doom9 thread: http://forum.doom9.org/showthread.php?t=165771