It reads frames from a movie OK. Thanks to PB I got that working in fairly short order. I'm having difficulty writing the frames back to a file and for the resulting movie to be playable by, say, VLC.
You will need an mp4 video file and the ffmpeg audio and video codec which can be obtained from zeranoe:
https://ffmpeg.zeranoe.com/builds/
This code also functions as the basis of a movie player (no audio, though) and it currently displays images upside-down which is not of immediate concern as long as the images it writes to the file are right-side-up.
https://www.videolan.org/vlc/index.html
The target OS is Windows 10.
This program is based on code written for C and python which I was unable to get to work:
https://batchloaf.wordpress.com/2017/02 ... t-2-video/
http://zulko.github.io/blog/2013/09/27/ ... ng-ffmpeg/
Code: Select all
;MP4 MOVIE GRABBER
#HEIGHT = 720: #WIDTH = 1280: #PIXCOUNT = #HEIGHT * #WIDTH * 3
endFlag = 0
OpenWindow(1,0,0,#Width,#Height,"")
CreateImage(1, #Width, #Height , 24)
StartDrawing(ImageOutput(1))
*buff = DrawingBuffer()
StopDrawing()
Dim pixels.a(#HEIGHT,#WIDTH,3)
*pix = @pixels(0,0,0)
pipeIn$ = "-i teapot.mp4 -f image2pipe -pix_fmt rgb24 -vcodec rawvideo -"
;pipeOut$ = "-y -f rawvideo -vcodec rawvideo -pix_fmt yuv420p -s 1280x720 -r 25 -i - -f mp4 -q:v 5 -an -vcodec mpeg4 outputvideo.mp4"
;pipeOut$ = "-y -f rawvideo -vcodec rawvideo -pix_fmt yuv420p -s 1280x720 -r 25 -i - -f mp4 -q:v 5 -an -c:v libx264 -bitrate 3000k outputvideo.mp4"
pipeOut$ = "-y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s 1280x720 -r 25 -i - -f mp4 -q:v 5 -an -vcodec mpeg4 -bitrate 3000k outputvideo.mp4"
readFrame = RunProgram("ffmpeg.exe", pipeIn$, "", #PB_Program_Open | #PB_Program_Read)
writeFrame = RunProgram("ffmpeg.exe", pipeOut$, "", #PB_Program_Open|#PB_Program_Write)
Repeat
count = ReadProgramData(readFrame, *pix, #PIXCOUNT)
;If count < #PIXCOUNT: endFlag = #True: Break: EndIf
If count = 0: endFlag = #True: Break: EndIf
;For y = 0 To 719
;For x = 0 To 1279
;pixels(y,x,0) = 255
;pixels(y,x,1) = 255
;pixels(y,x,2) = 255
;Next
;Next
;For y = 0 To 719
;For x = 0 To 1279
;Invert each colour component in every pixel
;pixels(y,x,0) = 255 - pixels(y,x,0); // red
;pixels(y,x,1) = 255 - pixels(y,x,1); // green
;pixels(y,x,2) = 255 - pixels(y,x,2); // blue
;Next
;Next
CopyMemory(*pix,*buff,#PIXCOUNT)
StartDrawing(WindowOutput(1))
DrawImage(ImageID(1),0,0)
StopDrawing()
If endFlag <> #True
;WriteProgramData(writeFrame,*buff,#PIXCOUNT)
WriteProgramData(writeFrame,*pix,#PIXCOUNT)
;WriteProgramData(writeFrame,@pixels(0,0,0),#PIXCOUNT)
EndIf
;If result = 0: Debug "error": EndIf
ForEver
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
KillProgram(readFrame)
CloseProgram(readFrame)
KillProgram(writeFrame)
CloseProgram(writeFrame)
FreeArray(pixels())
CloseWindow(1):End