VLC

More progress towards my project

I’ve been doing odds and sods today.

  1. Play a list of videos on a continuous loop full screen. By using libvlc and the Java wrapper I’ve finally got a full screen player working in less than 60 lines of code which plays a list of video files.
  2. Write a server and test over the internet. Using just a Java server, the initial test worked which was to accept a connection and send “Hello world!” back. Now that it is running I can expand the server with all the functionality I require. This will be handling the back-end database, media and installations.
  3. Define a KISS (Keep It Simple Stupid) database for handling devices and media.

To do:

  1. Write a mobile Android app to manage the setup of devices and assigning play lists. This is going to be a big one and a lot of work and I need to be on site when setting up devices and getting them playing without glitches.
  2. Expand on the software for the media player so that it can update itself from the server with not only media updates, but also software updates.
  3. Run an outside test live over the internet and update the playlist.
  4. Get more experience with Blender and video creation. For the most part, I’m more than capable of producing the videos in approximately an hour for everything I need. The more I get familiar with Blender then I can add more effects to the videos which will be a bonus.
  5. Bully test the server. I already have someone on hand that can test the servers integrity and stability. Pen-testing the server will give me some good pointers to how to make it more secure. I’m also considering the 2 way login.

That’s the plan for the next couple of weeks. Just so long as I get some free time I can move along quite quickly with this with the exception of the bully testing and updating.

Right now, things are looking almost bullet proof. Fingers crossed.

EDIT:

I forgot to add the VPS (Virtual Private Server)

Not been that busy lately this time

I had 2.5 days carried over for holidays so I took a long weekend off beginning half day on Friday. All to go for long rides with the missus on our motorbikes. And she was very happy because she has only been riding for almost a month now.

Anyway, documents have been written up towards this project and a very important document that I created regarding it from about six years ago needs altering. No database plan has been setup yet until the spreadsheets are finalised. Number crunching has been pretty good.

At the moment I have four sample videos created, although I need a lot more, to which a demonstration setup can be made. When all the sample videos have been produced, they will range through all categories of businesses.

My Intel tiny PC turned up and I am not disappointed. I may as well stick to 30 frames per second instead of 60 as the current videos play perfect. I’ve got it to boot up in Linux and auto run my software to play the videos on a loop. No screen tearing and running all over these last four days.

Over the next one to three weeks I should have the server infrastructure in place where I can live test my new system. As mentioned above, the documentation has been more of an important matter over this weekend off when I’ve had the time. The infrastructure will include storage, database solutions, communications, security protocols and a users interface to the server.

Throughout this entire project I’ve kept to a strict diet of royalty free and open source. In the future, the software I have used will get donations.

PS…

The initial test was a single ‘cpp’ program which links to ‘libvlc’ and ‘X11’ which opens a full screen window and attaches each instance being played to the full screen window. Now it gets complex. (not really)…

Libvlc and my Odroid

Before I go ahead and actually buy the Odroid C2, I thought I’d dig out my U3 and try the vlc library on that. All I had to do was to copy the project folder over SSH to it and build it. At first it didn’t compile because I needed to install the X11 dev files, and then again I had to install the libvlc-dev files. And then it built just fine.

Major problem though, VLC doesn’t have hardware acceleration on any of the Arm processors yet.

Well, now it looks like I’ll either go down the Qt route, FFMpeg route, OGV decoder route, or find another player library.

One thing I do know is that I’d like to stick to a single video format, ie OGV. So that makes writing my own player easy enough.

My next step is to get a player working by myself and make it work on the Odroid. I’m going to see about the OGV sources before checking out other open source players.

I’ll keep you posted.

 

Fullscreen video playlist done

Using Linux and libvlc I’ve finally got what I was aiming for. A full screen video playlist player. And it was quite easy.

The steps to get here:

  1. Monday: Play a media file. A few lines of code did this. And with the addition of one extra line of code made it full screen.
  2. Play a playlist of videos full screen. This is where things went wrong. After one video had finished, the vlc player would quit fullscreen, flash the desktop and then play the next video in full screen. This was not acceptable.
  3. Tuesday: Using the stock Linux libraries to go full screen. This took all of about 20 minutes from start to end. And again, in just a few lines of code. It was a chaotic night at home so I just finished up there.
  4. Wednesday: Just chilled out and watched TV after work instead.
  5. Thursday: I now needed to use the full screen window and attach the videos to it so that the desktop doesn’t appear. By just passing the window ID to the vlc media player, this was done.

Now all I need to work on the managing the playlists over the internet. And order myself and Odroid C2 with a few other gadgets. So far, this is going 100% perfectly.

By my reckoning, I should have a media player that boots up in less than 10 seconds and playing. How awesome…

The hefty part of the coding is about to start…

libVLC and fullscreen

Okay, so I was successful with getting libVLC to play a video in full screen in just a few lines of code. This was a great success. However, when using a play list, each item is shown in a window.

Tonight I haven’t the time to set up a full screen window and attach libVLC to it, so I will try that tomorrow. There’s tons of Linux windowing API’s I can use. Just a standard X11 window will be fine as there will be no user input at all.

It’s no use having a black background as a desktop as some videos will end with a different coloured background.

Ah well. Plod on tomorrow. Almost there.

If I fail then it will be a minimal build of ffmpeg or maybe just the OGV libraries and I will write a player myself which will take a tad longer than I wanted.

Sample C code on Linux:

#include <X11/X.h>
#include <X11/Xlib.h>
#include <strings.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

extern "C" {
#include <vlc/vlc.h>
}

const char *files[] = {
	"/media/wlgfx/WLGfx/WLGfxMedia/2017July/WLGfxJul/wlgfx.ogv",
	"/media/wlgfx/WLGfx/WLGfxMedia/2017July/sample1/sample.ogv"
};
const int files_count = 2;

void play_media(libvlc_instance_t *inst, const char *uri, uint32_t win) {
	libvlc_media_t *m = libvlc_media_new_path(inst, uri);
	libvlc_media_player_t *mp = libvlc_media_player_new_from_media(m);
	libvlc_set_fullscreen(mp, 1);
	libvlc_media_player_set_xwindow(mp, win);
	libvlc_media_player_play(mp);
	sleep(1); // enough time to start
	while (libvlc_media_get_state(m) == libvlc_Playing) usleep(200);
	libvlc_media_release(m);
	libvlc_media_player_release(mp);
}

int main() {
	Display* dis = XOpenDisplay(NULL);
	Window win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 0, 0, 10, 10,
			0, BlackPixel (dis, 0), BlackPixel(dis, 0));

	Screen *screen; // get screen size
	screen = ScreenOfDisplay(dis, 0);
	int dwid = screen->width;
	int dhgt = screen->height;

	Window root; // position mouse to bottom left (hide it)
	root = XRootWindow(dis, 0);
	XSelectInput(dis, root, KeyReleaseMask);
	XWarpPointer(dis, None, root, 0, 0, 0, 0, dwid, dhgt);
	XFlush(dis);

	XInitThreads();

	Atom wm_state = XInternAtom(dis, "_NET_WM_STATE", False);
	Atom fullscreen = XInternAtom(dis, "_NET_WM_STATE_FULLSCREEN", False);

	XEvent xev;
	memset(&xev, 0, sizeof(xev));
	xev.type = ClientMessage;
	xev.xclient.window = win;
	xev.xclient.message_type = wm_state;
	xev.xclient.format = 32;
	xev.xclient.data.l[0] = 1;
	xev.xclient.data.l[1] = fullscreen;
	xev.xclient.data.l[2] = 0;

	XMapWindow(dis, win);

	XSendEvent (dis, DefaultRootWindow(dis), False,
		SubstructureRedirectMask | SubstructureNotifyMask, &xev);

	XFlush(dis);

	printf("XWindow initialised with threading enabled\n");

	libvlc_instance_t *vlc_instance = libvlc_new(0, NULL);

	printf("Playing media files in vlc attached to window\n");

	uint32_t id = (uint32_t) win;

	play_media(vlc_instance, files[0], id);
	play_media(vlc_instance, files[1], id);
	play_media(vlc_instance, files[0], id);
	play_media(vlc_instance, files[1], id);

	libvlc_release(vlc_instance);

	printf("Hopefully all was successful\n");

	return 0;
}

Blender and Python and VLC

Since getting home on Friday after work, I had a plan.

  1. Figure out the animation and timeline in Blender. I’ve done this. I can now rotate, translate, scale and modify objects on the timeline. As well as texturing, particles and other things useful for animations. I’ve still yet to show video in a texture, but that looks a doddle.
  2. Play animations (for testing) from the ‘.blend’ file. This was a bit fiddly as I had to use the Blender Game Engine and all the animations I had done for each individual objects, I had to add in the ‘BGE’. The Blender player works fine with the ‘.blend’ files with many exceptions. There’s a lot that Blender can do that the player doesn’t handle. A simple one is the morphing of an object. Which rules out a hell of a lot of Blenders stuff.
  3. Blender rendering videos. Awesome this one. It will render videos to OGV format. All effects included, or at least I hope so. I’ve rendered a 15 second video many times on my laptop in the background (it is an i7) and I can still get on with other stuff. This will be much quicker on my PC, but my laptop is darn fast as is.
  4. Use Bash or another scripting language to play the videos because the Blender player, although fast and smooth, doesn’t do everything. I’ve been successful with Python and the VLC plugin for it, so I now know I can use the VLC library to play these files. I’m still beginning with Python, but it did show me how easy the VLC library is to use.

Although I’ve made sure I’ve put time out to get out this weekend just to keep myself in a good mood, this progress has been great.

It’s a long learning curve with Blender, but at the moment, I can make use of it to do 90% of what I need it for. 30 frames per second with a medium 3D scene was taking on my laptop 2.0 seconds per frame to render at 1920 x 1080. And 15 seconds of full quality is about 12Mb.

The framework around all of this will be a WIP from today and it is going to be so awesome even I can’t wait.

The next stage for me will be integrating custom engines to produce these animations better then the Blender player without the need to render video files.

Back to Blender… See y’all soon…