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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
flashkot
Prole
Posts: 27
Joined: Sun Jul 29, 2012 4:56 pm
Location: ru

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

Post 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! :)
User avatar
flashkot
Prole
Posts: 27
Joined: Sun Jul 29, 2012 4:56 pm
Location: ru

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

Post 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.
User avatar
flashkot
Prole
Posts: 27
Joined: Sun Jul 29, 2012 4:56 pm
Location: ru

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

Post 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. ;)
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

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

Post 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!
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

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

Post 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.
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

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

Post 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 :)
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

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

Post 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:
Artal, A .PSD loader: https://github.com/EvineDev/Artal
User avatar
flashkot
Prole
Posts: 27
Joined: Sun Jul 29, 2012 4:56 pm
Location: ru

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

Post by flashkot »

Hi, everyone.

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

So, where is code updated for 0.9? :awesome:
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

mjpeg_player for Löve 0.9.1

Post 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! ^^
Attachments
mjpeg_player_hq_0.9.1.love
High-quality Video
(6.11 MiB) Downloaded 129 times
mjpeg_player_shader_0.9.1.love
Low-quality with shader
(1.49 MiB) Downloaded 117 times
mjpeg_player_0.9.1.love
Low-quality Video
(1.49 MiB) Downloaded 123 times
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

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

Post by murks »

I just write this post to attach the fourth file, have fun :)
Attachments
mjpeg_player_2hq_0.9.1.love
Even higher quality video
(8.02 MiB) Downloaded 134 times
Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests