特別な .ass ファイルを生成するアプリケーションのビデオ プレビュー用の libass ラッパーとして VapourSynth を使用しています。返されたビデオ フレームは、pyqt4 の QImage オブジェクトに出力する必要があります。
get_read_ptr に関する VapourSynth のドキュメントを読みました。frame.format が示すようにエンコードされた画像のポインタであると書かれています。私の場合、frame.format は RGB24 です。私の質問は次のとおりです。生のフレームデータにアクセスし、それを QImage オブジェクトに表示して表示するにはどうすればよいですか?
これが私のコードです。私は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)
現在、以下を返します:
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>