Page 2 of 3

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Thu Aug 09, 2012 6:39 am
by flashkot
NÖÖB wrote:Then the memory usage gets much lower -- 25mb
Wow! Thanks a lot! This is what this code needed so musch!
Roland_Yonaba wrote:But, what if we need some full video playing features ? go forth, go back , stop, resume, etc...
You can easily add this features.

For example, this is all you need for play/pause with space bar:

Code: Select all

function love.keypressed(key)
    if key == " " then
        if sound:isPaused() then
        	sound:resume()
        else
        	sound:pause()
        end
    end
end

This is because video depends on position in played audio.

Rewind and fast forward a little bit tricky. When changing position of audio with sound:seec(25, "seconds") you also should update all player values: img1, img2, first_image, cur_frame, next_load, curent_quad. But again, all this values depends on adio position and your video configuration (frames per image, frame rate)
Roland_Yonaba wrote:@flashkot : For what reason did you used love.thread, by the way ?
Idea was simple:
Loading image with frames for one second of video takes (just for example) 0.5 seconds. so this can't be done in one loop, you video will be laggy:

0.5s loading, 1s video, 0.5s loading, 1s video, 0.5s loading, 1s video...

With loader thread it runs like this:

Code: Select all

Player thread:  | 1s video     | 1s video     | 1s video     | 1s video     | 1s video     |
Loader thread:  | 0.5s loading | 0.5s loading | 0.5s loading | 0.5s loading | 0.5s loading |
Roland_Yonaba wrote:Plus, did you envision some sort of streaming ? I mean, load some frames, display them, and progressively load the next frames in background while playing the video. It may reduce the reduce the memory usage, but i don't know if that would be faster. That's jus some random ideas I am throwing on the table, so that we can all learn from that.
It's already works as you described. Frames are loaded in background. Code keeps only what it plays right now. Right, it's some sort of streaming.
Roland_Yonaba wrote:Thanks for the amazing work, though.
You're welcome! :)

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Thu Aug 09, 2012 6:43 am
by flashkot
retrotails wrote:This is awesome. I assume it would work with lossless images as well?
Yes, but data size will be much bigger.

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Thu Aug 09, 2012 6:57 am
by flashkot
Hmmm... I just get some ideas with threading. And it is also interesting to make this player feature rich...

So i decided to rewrite it as nice and friendly library and put to my gitbox with all helper scripts for video converting. Stay tuned. ;)

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Thu Aug 09, 2012 7:31 am
by Roland_Yonaba
flashkot wrote:So i decided to rewrite it as nice and friendly library and put to my gitbox with all helper scripts for video converting. Stay tuned. ;)
I was about to say that. Git it, and let the world f***...Err...fork it!

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Sat Jun 07, 2014 6:49 pm
by murks
This sounds awesome, but it seems something needs an update for love 0.9:
A simple require solved the first problem, but 0.9 changed how threads work, so there's more to do than I can do within 5 minutes. Maybe I'll try to update it if noone beats me to it.

Code: Select all

$ love mjpeg-player.love 
Error: main.lua:37: Could not open file loader_thread. Does not exist.
stack traceback:
	[C]: in function 'newThread'
	main.lua:37: in function 'load'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:399>
	[C]: in function 'xpcall'
$ love mjpeg-player_hq.love 
Error: main.lua:37: Could not open file loader_thread. Does not exist.
stack traceback:
	[C]: in function 'newThread'
	main.lua:37: in function 'load'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:399>
	[C]: in function 'xpcall'
$ love mjpeg_player_shader.love 
Error: main.lua:36: attempt to call field 'newPixelEffect' (a nil value)
stack traceback:
	main.lua:36: in main chunk
	[C]: in function 'require'
	[string "boot.lua"]:360: in function <[string "boot.lua"]:241>
	[C]: in function 'xpcall'
$ love mjpeg_player_2hq.love 
Error: main.lua:35: Could not open file loader_thread. Does not exist.
stack traceback:
	[C]: in function 'newThread'
	main.lua:35: in function 'load'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:399>
	[C]: in function 'xpcall'
EDIT: I had a look at it and tried to fix it but it's not completely trivial since the thread semantics changed so much.

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Fri Jun 13, 2014 10:19 pm
by murks
I finished porting all four examples to love 0.9.1.
Just waiting for flashkot to put the original under a license so I can release my modifications without problems.
Looking forward to it :)

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Sat Jun 14, 2014 5:12 pm
by Evine
Check his GitHub https://github.com/flashkot/LuaStuff
flashkot wrote:LuaStuff
Some Lua snippets created while playing with LÖVE framework
All code in this repository is in public domain.
So Lovely :awesome:

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Sat Jun 14, 2014 5:54 pm
by flashkot
Hi, everyone.

As murks asked, i put VideoPlayer under Apache 2.0 license.

So, where is code updated for 0.9? :awesome:

mjpeg_player for Löve 0.9.1

Posted: Sat Jun 14, 2014 8:05 pm
by murks
IT is done!

First of all, a big thanks goes to flashkot for his original code and for his cooperation that allowed me to release this code.
I did port the examples flashkot released for löve 0.8.*, so there is no fork of the repository.

Changes I made:
  • - Port to Löve 0.9.1 - The threading model changed, so I had to change named messages to unnamed messages through two separate channels.
    - Fix for the stop-bug - I'm not sure whether this happened with the original version, but when testing the port I noticed that the player got stuck at the end of the video. So I had to come up with a new way to quit cleanly. This took me longer than the actual port.
    - Added license note to the Big Buck Bunny trailer files.
    - Added my name to the top of the source files. I made clear that I just did the port to 0.9.1.
Adding the video player to your game is not hard, I'm sure you can figure it out. I did this yesterday for the game I'm developing which I'll most likely release to this forum in a few weeks. For the image conversion script please look at flashkots repository or one of his earlier posts in this thread

Attached you find the first three examples, the fourth I'll need to attach to another post.

I hope to see some videos in games soon :)
Have fun! ^^

Re: Playing Video. mjpeg decoder in pure lua. With audio!

Posted: Sat Jun 14, 2014 8:07 pm
by murks
I just write this post to attach the fourth file, have fun :)