Sub Globals
Dim imgByte() As Byte
Private IntervalMs As Int = 150
Private lastPreviewSaved As Long
End Sub
' Frame Source is stored in imgByte
Sub Camera1_Preview (PreviewPic() As Byte)
If DateTime.Now > lastPreviewSaved + IntervalMs Then
imgByte = camEx.PreviewImageToJpeg(PreviewPic, 70)
lastPreviewSaved = DateTime.Now
End If
End Sub
Sub CreateVideo
Dim state As JavaObject
Dim aBitmapToVideoEncoder As BitmapToVideoEncoder
state = aBitmapToVideoEncoder.setup("/sdcard/Movies/testX.mp4", 640, 480, "video/avc", 2000000, 15, 1)
Dim bmp As Bitmap=generateVideoFrame(0)
Dim ret As Boolean = True
Dim n As Int = 1
Do While bmp.IsInitialized And ret=True
ret=aBitmapToVideoEncoder.writeBitmap(state, bmp)
bmp=generateVideoFrame(n)
n=n+1
Loop
aBitmapToVideoEncoder.endEncoding(state)
End Sub
'the imgByte is converted to stream and then to bitmap
Sub generateVideoFrame(n As Int) As Bitmap
Dim In As InputStream
In.InitializeFromBytesArray(imgByte, 0, imgByte.Length)
Dim bmp As Bitmap
bmp.Initialize2(In)
Return bmp
End Sub
'start video recording
Sub Camera1_Ready (Success As Boolean)
If Success Then
Starter.csu.CallSubPlus(Me, "CreateVideo", 5000)
End If
End Sub