Is it possible to play an mp4 video in linux with freebasic? I have absolutely zero idea on how to code such a thing. It would need a start and pause button ideally. Do I need some library to do this? If someone could point me in the right direction I would apprecite it.
Thank you
mp4
Re: mp4
It is possible, I think that the way some people have done it, is they become a kind of controlling window for mplayer. I have not tried this before.
Here is the closest piece of code that I have for this. It only deals with the image part, not the sound. It works by telling ffmpeg to output as bitmap images, which it then renders to the freebasic window. Although this doesn't really solve your problem, it may be of use to people who just need to get the image frames out of the video.
Here is the closest piece of code that I have for this. It only deals with the image part, not the sound. It works by telling ffmpeg to output as bitmap images, which it then renders to the freebasic window. Although this doesn't really solve your problem, it may be of use to people who just need to get the image frames out of the video.
Code: Select all
' With thanks to mysoft, and apologies for the scrappyness of the code, I didn't spend any time to clean it up for you.
type WORD as ushort
type DWORD as uinteger
type BITMAPFILEHEADER field = 1
as WORD bfType
as DWORD bfSize
as WORD bfReserved1
as WORD bfReserved2
as DWORD bfOffBits
end type
type BITMAPINFOHEADER field = 1
as DWORD biSize
as LONG biWidth
as LONG biHeight
as WORD biPlanes
as WORD biBitCount
as DWORD biCompression
as DWORD biSizeImage
as LONG biXPelsPerMeter
as LONG biYPelsPerMeter
as DWORD biClrUsed
as DWORD biClrImportant
end type
print command(1)
dim as integer screen_pitch
dim as any ptr screen_p
dim as integer frame_size
dim as any ptr frame_buffer
dim as integer frame_pitch
dim as integer frame_pitch_diff
dim as BITMAPFILEHEADER bf
dim as BITMAPINFOHEADER bi
open cons for output as #99
' -s 100x100
' -r 0.1
open pipe "ffmpeg -i " & command(1) & " -vcodec bmp -f image2pipe pipe:1 2> /dev/null" for input access read as #1
dim as double t1 = timer()
dim as integer frames
dim as integer bytes_read
get #1, , bf
get #1, , bi
bytes_read = sizeof(bf) + sizeof(bi)
if bf.bfType <> cvshort("BM") then
print #99, "Bad frame..."
end 1
end if
screenres bi.biWidth, bi.biHeight, 32
screeninfo , , , , screen_pitch
frame_size = bi.biWidth * bi.biheight * 3
frame_buffer = callocate(frame_size + 1) ' add one so that i can read 4 bytes at a time and mask off the bad one
frame_pitch = ((bi.biWidth * 3) + 3) and (not 3)
frame_pitch_diff = frame_pitch - (bi.biWidth * 3)
screen_p = screenptr()
while not eof(1)
dim as ubyte u8 = any
while bytes_read < bf.bfOffBits
get #1, , u8
bytes_read += 1
wend
get #1, , *cast(ubyte ptr, frame_buffer), frame_size
bytes_read += frame_size
screenlock
dim as any ptr p = screen_p
dim as ubyte ptr frame_p = frame_buffer
p += (bi.biHeight - 1) * screen_pitch
for y as integer = bi.biHeight - 1 to 0 step - 1
for x as integer = 0 to bi.biWidth - 1
cast(uinteger ptr, p)[x] = *cast(uinteger ptr, frame_p) and &HFFFFFF
frame_p += 3
next x
p -= screen_pitch
frame_p += frame_pitch_diff
next y
locate 1, 1
print "fps:" & int(frames / (timer() - t1))
screenunlock
while bytes_read < bf.bfSize
get #1, , u8
bytes_read += 1
wend
get #1, , bf
get #1, , bi
bytes_read = sizeof(bf) + sizeof(bi)
if bf.bfType <> cvshort("BM") then
exit while
end if
frames += 1
if (timer() - t1) > 2 then
t1 = timer()
frames = 0
end if
wend
close #1
close #99
deallocate(frame_buffer)
Re: mp4
Here is another piece of code I found from Landeel that is closer to the 'mplayer control' method.
I think to add controls to this, it may be possible, to instead of using SHELL, use OPEN PIPE, then you may be able to write the keys you want to send, like SPACE for PAUSE to the PIPE.
Code: Select all
' Thanks to Landeel
screenres 640,480,,32
dim as integer xid
ScreenControl 2, xid
shell "mplayer -wid "+str(xid)+" -really-quiet " & command(1)
Re: mp4
OK, sorry to keep posting on this one :P This is my last post, my time and ideas are now low ;)
This little prog now accepts the keys "q" to quit, and "p" to pause/play
So, now this program tells mplayer its window id so that mplayer knows where to draw. It also gives it a FIFO (named pipe) to read its input commands from.
I hope that this really gets you started on whatever you want to make, or that a true master of the dark arts emerges to help you more ;)
This little prog now accepts the keys "q" to quit, and "p" to pause/play
Code: Select all
' Thanks to Landeel
screenres 640,480,,32
dim as integer xid
ScreenControl 2, xid
'shell "mplayer -wid "+str(xid)+" -really-quiet " & command(1)
shell "mkfifo fbfifo"
open pipe "mplayer -input file=fbfifo -wid "+str(xid)+" -really-quiet " & command(1) for output as #1
do
dim as string k = inkey
if k = "p" then
open "fbfifo" for output as #2
print #2, "pause"
close #2
elseif k = "q" then
end
end if
sleep 10, 1
loop
close #1
I hope that this really gets you started on whatever you want to make, or that a true master of the dark arts emerges to help you more ;)