MydKnight
Posts: 2
Joined: Mon Aug 31, 2015 6:13 pm

Switching between videos

Mon Aug 31, 2015 6:23 pm

I'm trying to build out an effect on the pi that has a single video (possibly image at some point) that is playing on a loop. When a trigger is received (I'm using RFID tags to do this), then the video swaps to another video, which plays out, and then swaps back to the looping video. For instance, a window with a forest view loop and when triggered, it switches to a window with a monster running towards it, as he jumps at the window, we flip b ack to the window on forest view.

I have the code to do all this swapping, and I have done it two ways, both with the same fail point.

First I used OMX player and spawned the player looping, then on trigger, killed it and spawned the new player, played it and then killed that and respawened my loop.

Next I tried using Kodi (running on both raspbian and OMPC) and then sending RPC commands to play one file, then play the other file.

In both cases, the transition period has me either dropping to the desktop/console (in the first case) or the kodi UI (in the second) for a second or two. This exposure of the OS totally breaks the effect.

Is there a way to accomplish this swapping seamlessly? I've heard someone mention loading the vids into ram, and I was thinking something about having the two vids playing on two different VTs and just swapping terminals, but I'm not sure if these will work any better. I can probably live with a slight flicker (a la alt-tabbing) but this exposing the desktop or ui is just not going to work.

Anyone have any ideas?

User avatar
dividuum
Posts: 168
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: Switching between videos

Tue Sep 01, 2015 3:13 pm

My tool info-beamer pi can be used to do that. I quickly hacked together some code that should do what you asked for: It seamlessly loops one video (loop.mp4). You can then externally trigger the code to play an intermission video (intermission.mp4), which is either played completely or until you send another message to resume the loop. In both cases the looping video is stopped once the intermission video starts and resumed once the intermission video playback finished.

The intermission video is preloaded each time it ended. That way it can be immediately played once the command is given. Since preloading takes a short time, rapidly switching between loop and intermission will show a black screen, since preloading might not be done yet.

I uploaded the code code to github. To run it, download info-beamer and install it (see the README.txt inside the downloaded file). Then create a new directory, put the file named node.lua and two videos called loop.mp4 and intermission.mp4 in it and finally start info-beamer by running info-beamer /path/to/that/directory.

To trigger the intermission video, just send the following UDP packet to localhost port 4444 (which is the port info-beamer is listening to):

Code: Select all

looper/set:intermission
To abort the intermission video playback and resume the loop, send

Code: Select all

looper/set:loop
If you're using bash, you can execute

Code: Select all

$ echo -n "looper/set:intermission" > /dev/udp/localhost/4444
Of course you can use the programming language of your choice to send those packets. Let me know if that works for you or you have any questions.
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

MydKnight
Posts: 2
Joined: Mon Aug 31, 2015 6:13 pm

Re: Switching between videos

Tue Sep 01, 2015 4:00 pm

Wow, thank you SO much for this! I'll have to putter around with it this week to confirm that it meets the need, but from your description it certainly sounds that way. The prebuffering sounds exactly like what I needed to prevent the black screen. I really appreciate it.

jaimekhc
Posts: 1
Joined: Fri Jun 17, 2016 12:57 pm

Re: Switching between videos

Fri Jun 17, 2016 2:13 pm

Dear dividuum,

I am new to raspberry Pi. I am working on a project similar to Mydknight was working on, and Info Beamer caught my eyes! It looks cool and solid. I have tried your code and loop.mp4 plays well. Unfortunately, I couldn't make the intermission.mp4 plays. I have tried remotely ssh to the raspbian with my macbook, but neither

Code: Select all

echo -n "looper/set:intermission" | netcat -u localhost 4444
or

Code: Select all

echo -n "looper/set:intermission" > /dev/udp/localhost/4444
works. And I have also tried setting INFOBEAMER_ADDR=0.0.0.0.

Could you help me out with this issue? Is there any step I missed?

User avatar
dividuum
Posts: 168
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: Switching between videos

Thu Jun 30, 2016 9:26 pm

I'm sorry for missing your questions. Right now, info-beamer only supports IPv4 (this will change in the next release). Can you try to use

Code: Select all

echo -n "looper/set:intermission" | netcat -u 127.0.0.1 4444
instead? Notice the 127.0.0.1 instead of localhost. This will force IPv4 and should work.
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

nuthan
Posts: 2
Joined: Wed Aug 17, 2016 3:45 pm

Re: Switching between videos

Wed Aug 17, 2016 3:50 pm

Hi Dividuum,

The workaround was cool and worked seamlessly.

This would work with loop and intermission videos i.e, 2 videos only. What if there are multiple videos say 50. Is there any limit with your workaround?

I need to play the videos instantly based on trigger from sensors connected to usb.

Is the use case possible?

Thanks,
Nuthan.

User avatar
dividuum
Posts: 168
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: Switching between videos

Wed Aug 17, 2016 4:49 pm

nuthan wrote:The workaround was cool and worked seamlessly.
With the current release you don't need that workaround any more. info-beamer now supports IPv6 too. \o/
nuthan wrote:I need to play the videos instantly based on trigger from sensors connected to usb.
Right now the example code uses two videos only. One video is constantly loaded and paused on demand. The other, the intermission one, is preloaded. That means everything is ready to instantly start playback. This preloading uses quite some resources: info-beamer uses a background thread to open the video file, sets up all the hardware accelerated pipeline that does decoding of the video and then pauses it right at the start. So when the command to play the video arrives, all that's left to do is unpause playback. You cannot preload many videos that way, as you would run out of memory really quickly. For more than 2-3 videos I would suggest you use a different approach: Every time the command to play a video arrives, start loading the video and then play it once loaded. This might take 50 and 150ms. So there would be a small delay between the user action and the video starting. Would that work?
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

nuthan
Posts: 2
Joined: Wed Aug 17, 2016 3:45 pm

Re: Switching between videos

Thu Aug 18, 2016 9:24 am

Thanks for the response Dividuum.

Your suggestion is interesting. 50-100ms latency should not matter. But, How do I start loading the video?

Code: Select all

 local function preload()
        if vid then vid:dispose() end
        vid = resource.load_video(file, false, false, true)
    end
OR can you point me to the possible nodes in the list? Any possible use cases?
https://github.com/dividuum/info-beamer-nodes

Nuthan.

User avatar
dividuum
Posts: 168
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: Switching between videos

Thu Aug 18, 2016 12:19 pm

nuthan wrote:Your suggestion is interesting. 50-100ms latency should not matter. But, How do I start loading the video?
Loading videos, as you wrote, works like this (documentation):

Code: Select all

local vid = resource.load_video("videofile.mp4")
Explaining everything might be a bit tricky without basically writing the code. I figured that such an example might help others, so I quickly coded the video looper with intermissions and put it in the info-beamer example repository. Let me know if that works for you. Be sure to use a recent version of info-beamer.

Just put loop.mp4 and other video files into the same directory as the node.lua file. Then run info-beamer in that directory. It will start looping loop.mp4. Then you can send it UDP packets to interrupt the loop to play any other video in the same directory. Once done it will resume the loop.

Hope that helps.
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

Return to “Graphics, sound and multimedia”