OvejaNegra
6th January 2011, 23:36
Im trying to get a video frame directly from avisynth using VB.net.
After reading lots of code pieces (avsp,AVEditor,the pure basic api) this is what i have so far:
Imports System.Runtime.InteropServices
Public Class Form1
Private Structure avs_Value
Dim Type As Short
Dim ArraySize As Short
Dim Value As Integer
End Structure
Private Structure AVS_VideoFrameBuffer
Public data As Byte
Public data_size As Integer
' sequence_number is incremented every time the buffer is changed, so
' that stale views can tell they're no longer valid.
Public sequence_number As Integer
Public refcount As Integer
End Structure
Private Structure AVS_VideoFrame
Public refcount As Integer
Public vfb As AVS_VideoFrameBuffer
Public offset As Integer ' U&V offsets are from top of picture.
Public pitch As Integer
Public row_size As Integer
Public height As Integer
Public offsetU As Integer
Public offsetV As Integer
Public pitchUV As Integer
End Structure
<DllImport("avisynth.dll")> Private Shared Function avs_create_script_environment(Optional ByVal Version As Integer = 2) As IntPtr
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_invoke(ByVal AVS_ScriptEnvironment As IntPtr, ByVal name As String, ByVal AVS_Value_args As String, ByVal arg_names As Integer) As avs_Value
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_take_clip(ByVal AVS_Value As avs_Value, ByVal AVS_ScriptEnvironment As IntPtr) As IntPtr
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_get_frame(ByVal AVS_Clip As IntPtr, ByVal n As Integer) As AVS_VideoFrame
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As IntPtr
Dim x As avs_Value
Dim clip As IntPtr
Dim frame As AVS_VideoFrame
test = avs_create_script_environment() :this returns test = 11421784
x = avs_invoke(test, "Avisource", "d\t_normal.avi", 0) : this returns X
ArraySize 1165 Short
Type 101 Short
Value 82494212 Integer
clip = avs_take_clip(x, test):this returns clip=11451608
frame = avs_get_frame(clip, 60):returns 0
End Sub
End Class
everything runs ok until line:
frame = avs_get_frame(clip, 60) <- this line gives me memory protection error.
Sugestions?
Second: if the above code runs ok, i will have a structure with the data of a frame. Now what? how can i read the pixels and display them on a window?
Thanks.
PD: I think MEGUI has a wrapper to AVS but i cant find any documentation about how use it.
My goal is have access to a frame from Avisynth and use it on a window.
After reading lots of code pieces (avsp,AVEditor,the pure basic api) this is what i have so far:
Imports System.Runtime.InteropServices
Public Class Form1
Private Structure avs_Value
Dim Type As Short
Dim ArraySize As Short
Dim Value As Integer
End Structure
Private Structure AVS_VideoFrameBuffer
Public data As Byte
Public data_size As Integer
' sequence_number is incremented every time the buffer is changed, so
' that stale views can tell they're no longer valid.
Public sequence_number As Integer
Public refcount As Integer
End Structure
Private Structure AVS_VideoFrame
Public refcount As Integer
Public vfb As AVS_VideoFrameBuffer
Public offset As Integer ' U&V offsets are from top of picture.
Public pitch As Integer
Public row_size As Integer
Public height As Integer
Public offsetU As Integer
Public offsetV As Integer
Public pitchUV As Integer
End Structure
<DllImport("avisynth.dll")> Private Shared Function avs_create_script_environment(Optional ByVal Version As Integer = 2) As IntPtr
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_invoke(ByVal AVS_ScriptEnvironment As IntPtr, ByVal name As String, ByVal AVS_Value_args As String, ByVal arg_names As Integer) As avs_Value
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_take_clip(ByVal AVS_Value As avs_Value, ByVal AVS_ScriptEnvironment As IntPtr) As IntPtr
End Function
<DllImport("avisynth.dll")> Private Shared Function avs_get_frame(ByVal AVS_Clip As IntPtr, ByVal n As Integer) As AVS_VideoFrame
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As IntPtr
Dim x As avs_Value
Dim clip As IntPtr
Dim frame As AVS_VideoFrame
test = avs_create_script_environment() :this returns test = 11421784
x = avs_invoke(test, "Avisource", "d\t_normal.avi", 0) : this returns X
ArraySize 1165 Short
Type 101 Short
Value 82494212 Integer
clip = avs_take_clip(x, test):this returns clip=11451608
frame = avs_get_frame(clip, 60):returns 0
End Sub
End Class
everything runs ok until line:
frame = avs_get_frame(clip, 60) <- this line gives me memory protection error.
Sugestions?
Second: if the above code runs ok, i will have a structure with the data of a frame. Now what? how can i read the pixels and display them on a window?
Thanks.
PD: I think MEGUI has a wrapper to AVS but i cant find any documentation about how use it.
My goal is have access to a frame from Avisynth and use it on a window.