News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
FLTK and ffmpeg
Author Message
dvw86
Junior Member
**


Posts: 39
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #1
FLTK and ffmpeg

Is it possible to capture video with ffmpeg and use murgaLua to display it on the screen? Videoview does this with fltk but I assume that they used some type of "C" language.

videoview

04-06-2008 04:25 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: FLTK and ffmpeg

I'm sure videoview uses other libraries that are written specifically to decode and display video.

The only way I could think of to do this with the current mugaLua is to use external applications that are already built to perform these tasks. You could probably use a timeout to display a series of still frames to emulate video playback, but as far as capturing goes I'm pretty sure you'd need to outsource it to another application. Perhaps the library communication that John has been working on for the next release will be able to use some external library to capture?

This post was last modified: 04-06-2008 11:22 AM by mikshaw.

04-06-2008 11:21 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #3
RE: FLTK and ffmpeg

It doesn't make sense to en-/decode or grab video with Lua or any other similar language (perl,python,php,....)
These are pretty low level tasks which need a lot OS, hardware and userspace interaction. Therefore it would only make sense to write a GUI in that languages and use the available GUI bindings and for the video IO, decode and encode stuff use a low level C/C++ library.
Even if a high level library is used for video/audio en-/decoding, writing a player includes highly OS specific code which has to do a lot more then most people think (the video and audio stream has to be synced at all times, which isn't a trivial task ;-) Also it should still perform well. Therefore it is quite a hard task to program a good video player.

On Linux there are quite a few alternatives. There is mplayer, VLC, Xine and even ffmpeg comes with a rudimentary player (ffplay). Mplayer, VLC and Xine can also grab video from a V4L source. Also it is possible to script all three of them and let them render into a fltk window. So it is possible to use them as a backend to output video into a fltk window of a murgaLua script.

Btw.: One reason I wanted the fl_xid() function included in murgaLua was to embed mplayer in a script. Unfortunately to have that reliably working, there are still a few functions needed. The problem is that the std. Lua IO functions can't be used to reliably script mplayer over pipes, because read blocks, ... But VLC and Xine should work, because they can be scripted over a socket and with luasocket and copas it should be no problem to get that going.

Juergen

04-07-2008 01:06 AM
Find all posts by this user Quote this message in a reply
dvw86
Junior Member
**


Posts: 39
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #4
RE: FLTK and ffmpeg

Juergen,
You have my attention. I would be quite happy to use xine and have it display in an FLTK window. I'll play around with that. Thanks

04-07-2008 02:31 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #5
RE: FLTK and ffmpeg

dvw86 Wrote:
Juergen,
You have my attention. I would be quite happy to use xine and have it display in an FLTK window. I'll play around with that. Thanks


This is a primitive mplayer example. The problem is that with the primitive Lua IO model, I can't read the output from mplayer reliably, because I have no Idea how much lines are in the buffer and when I call read() on an empty buffer it will block. When this is solved, it would be no problem to easily script mplayer.

Code:
#!/usr/bin/env murgaLua
function my_cb(self)
        if not initialized then
                os.execute("mkfifo /tmp/mpfifo")
                mpout=io.popen("LANG=C mplayer -quiet -input file=/tmp/mpfifo -wid "..fltk.fl_xid(group).." "..arg[1].." &","r")
                mpin=io.open("/tmp/mpfifo","w")
                initialized=1
        end
        mpin:write("seek 10\n")
        mpin:flush()
end

w=fltk.Fl_Double_Window(640,510,"Mpayer Gui")
w:size_range(32,20,Fl:w(),Fl:h())
button1=fltk.Fl_Button(0,495,70,15,"Press Me!")
group=fltk.Fl_Window(0,0,640,480)
w:resizable(group)
button1:callback(my_cb)
w:show()
Fl:run()


Juergen

This post was last modified: 04-07-2008 07:13 AM by Juergen.

04-07-2008 03:13 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: FLTK and ffmpeg

That's pretty cool.
I did a test with urxvt, and was suprised how simple it was.
Unfortunately, I have yet to find a reliable way to close both the terminal and the container window...so far i'm using if os.execute("killall urxvt")==0 then os.exit() end, but that's far from ideal. There doesn't seem to be a way to get the pid for that particular instance of urxvt from Lua.

04-08-2008 12:20 AM
Find all posts by this user Quote this message in a reply
dvw86
Junior Member
**


Posts: 39
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #7
RE: FLTK and ffmpeg

This is all fun and new to me, so my first test was to try it without murgaLua and this is what I came up with to display my webcam in a xine window. The next step would be to embed the xine display into a fltk window.

Code:
#!/bin/sh
rm -f /tmp/stream
mkfifo /tmp/stream
xine -G 352x288 -B --no-splash fifo:///tmp/stream &
ffmpeg -vd /dev/video -f video4linux -r 25 -s 352x288 -sameq -f mpeg -y /tmp/stream


This works most of the time but it is not very reliable. I often get an empty or scrambled xine window that never displays the stream. When it does work there is a large (about 5 or 10 second) delay between what is captured and what is displayed. It is an encouraging start though.

04-08-2008 02:33 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #8
RE: FLTK and ffmpeg

dvw86 Wrote:
This is all fun and new to me, so my first test was to try it without murgaLua and this is what I came up with to display my webcam in a xine window. The next step would be to embed the xine display into a fltk window.

Code:
#!/bin/sh
rm -f /tmp/stream
mkfifo /tmp/stream
xine -G 352x288 -B --no-splash fifo:///tmp/stream &
ffmpeg -vd /dev/video -f video4linux -r 25 -s 352x288 -sameq -f mpeg -y /tmp/stream


This works most of the time but it is not very reliable. I often get an empty or scrambled xine window that never displays the stream. When it does work there is a large (about 5 or 10 second) delay between what is captured and what is displayed. It is an encouraging start though.

Normally I don't use Xine, but mplayer, which should be able to do that whithout calling ffmpeg.
But to start with your example, you should try the following first:

Code:
ffmpeg -vd /dev/video -f video4linux -r 25 -s 352x288 -sameq -f mpeg - | xine -G 352x288 -B --no-splash stdin:/

It should work better, but I haven't tested it, since I don't have xine available at the moment.

Juergen

04-08-2008 03:27 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #9
RE: FLTK and ffmpeg

mikshaw Wrote:
That's pretty cool.
I did a test with urxvt, and was suprised how simple it was.
Unfortunately, I have yet to find a reliable way to close both the terminal and the container window...so far i'm using if os.execute("killall urxvt")==0 then os.exit() end, but that's far from ideal. There doesn't seem to be a way to get the pid for that particular instance of urxvt from Lua.

Without proper suppoert for the posix API either through the posix module or alien every solution would be a hack.
But there is one thing you could do (also a hack):

Code:
pidpipe=io.popen("urxvt -embed "..fltk.fl_xid(...).."..... >/dev/null & echo $!","r")
urxvtpid=pidpipe:read("*l")
pidpipe:close()
pidpipe=nil
os.execute("kill "..pid)


I didn't test it, but it should work.

Juergen

04-08-2008 03:44 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #10
RE: FLTK and ffmpeg

Quote:
>/dev/null & echo $!"

Looks like this is where I was going wrong.
I'd tried "urxvt & && echo $!" and "urxvt &; echo $!", which choked, and "(urxvt &) && echo $!", which echoed nothing.
I didn't know using a single "&" would separate the commands, but that makes sense to me now.

04-08-2008 04:38 AM
Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: