Raspberry Pi ofVideoPlayer FullHD movie

Hello,

I’ve been trying to play FullHD videos with ofVideoPlayer on a Raspberry Pi without success. Is there anyone here that knows if it is possible and how?

Thankyou!

Yes, it’s possible.

  • What have you tried?
  • What Raspberry Pi version (hardware and OS)?
  • What version of openFrameworks?

Are you sure you need openFrameworks? omxplayer is a great standalone fullHD video player for openFrameworks with lots of great options for cropping, scaling, looping, etc. Plus, it’s built in http://elinux.org/Omxplayer

Hello backercp. Thank you very much for your answer.

I’m using a Raspberry Pi 2 and latest Raspbian Lite image with OF 0.9.8. I’ve split memory to 256Mb for the GPU.

I’ve tried the examples/video/videoPlayerExample/ changing the main.cpp to:

int main( ){
ofSetupOpenGL(1920,1080, OF_FULLSCREEN);			// <-------- setup the GL context

ofGLESWindowSettings settings;
settings.setGLESVersion(2);
ofCreateWindow(settings);

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}

as I’ve seen in some topics in the forum, and selecting a FullHD video (h264 coded in an mp4 container) and setting OF_PIXELS_NATIVE in the ofApp.cpp file.

The video plays without any problem using omxplayer, but using ofVideoPlayer all I get is a blank screen. I’ve I run the original example video (Timecoded_Big_bunny_1.mov) it runs properly.

I know there’s omxplayer to play videos, but i’d like to create an application that can take several images and videos and play them one after the other without any black screen in the middle using the loadAsync() method of the ofVideoPlayer.

Thank you very much in advance.

Hello backercp.

Could you give me any clue on how to play FullHD movies in Raspberry Pi with ofVideoPlayer please? I’ve been trying some other things, but I’m still unable to play FullHD movies with ofVideoPlayer…

Thank you very much in advance,

Hi jordiblanchcarles,

As far as I know: It will be not very wise to use ofVideoPlayer. Raspberry is not a very powerful computer. It has a special video chip, which does help to play videos smoothly. It does a lot of calculations necessary, so the CPU does not need to do it. That’s what people call hardware acceleration. But you need a software that does use this chip. I don’t think ofVideoPlayer does at all. Or at least not very effective (!-- this seems to be wrong, check arturos comment below --!).
There are currently two ways I am using openFrameworks for video.

  1. ofxOmxPlayer (https://github.com/jvcleave/ofxOMXPlayer). This is an add-on for open frameworks which wraps omxPlayer (the Player bakercp mentioned: it is very well optimized for the raspberry). I realized multiple projects with ofxOmxPlayer and it is very fast and quite easy to use. Only drawback: acceptable sound will only be going through HDMI.
  2. VLC. It is possible (though not always smooth) to compile VLC on raspberry to use hardware acceleration. It is not as effective as omxPlayer, but it can play HD videos smoothly. You can use it by doing system calls from openFrameworks calling VLC. This solution is not as effective as ofxOmxPlayer and it is not as nice (not well integrated, have to fiddle with child processes and so on). It is possible though. Only advantage over omxPlayer (and only reason to think about it) is that you can use ALSA, so all sound possibilities, like e.g. hifiBerry cards, USB sound cards and so on.

does this help?
oe

ofVideoPlayer on raspberry pi does hardware acceleration, there’s some difference with omxplayer because it needs to transfer back pixels to ram after decoding but the decoding itself is hardware accelerated. using the native pixels format should be fast enough to play 1 full hd video.

can you post the code you are using to initialize the player

Hi arturo,

thanks for making this clear (and sorry to have spread wrong news!). I am confused, though. Is hardware acceleration on ofVideoPlayer newly implemented or changed somehow? Or is it, that Pi 2 (or 3) are just now fast enough, so that it works? I am confused as I did a lot of tries maybe 2 years ago and had to use VLC whenever I could not use ofxOmxPlayer. Also jordiblanchcarles does not seem to get it done out of the box.

So: I would be glad to correctly understand (would be happy to write some tutorial / overview / comparison in the end).

Thanks & have a good day!
oe

no it’s not new, gstremer on raspberry pi uses omx for doing video decoding since raspberry pi 1. if you used it 2 years ago, i think native pixels was not available yet which made a huge difference since colorspace conversion had to be done in the cpu

Hello arturo & dasoe,

here is my code:

main.cpp

#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main( ){

	ofGLESWindowSettings settings;
	settings.setGLESVersion(2);
	settings.windowMode = OF_FULLSCREEN;
	ofCreateWindow(settings);

	// this kicks off the running of my app
	// can be OF_WINDOW or OF_FULLSCREEN
	// pass in width and height too:
	ofRunApp( new ofApp());

}

ofApp.h

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

	public:

		void setup();
		void update();
		void draw();
		
		ofVideoPlayer movie;
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	movie.setPixelFormat(OF_PIXELS_NATIVE);
	movie.load("movies/Export_Mercat_03_422_v2.mp4");
	movie.setLoopState(OF_LOOP_NORMAL);
	movie.play();
}

//--------------------------------------------------------------
void ofApp::update(){
    movie.update();
}

//--------------------------------------------------------------
void ofApp::draw(){
    movie.draw(0,0);
}

With this code, the movie plays at about 2fps wich is completely unusable. My monitor is a FullHD monitor, so the initial OF_FULLSCREEN makes the program really use the FullDH mode of the screen. I’ve checked and the cpu usage is about 10% during the full movie length, so it doesn’t seem a problem of the cpu…

Could you please tell me what is wrong with this code? Is there anything else that I’ve to take into account when trying to play a FullHD movie?

Thank you very much in advance.

are you compiling in release mode?

Yes, I’ve tried both “make” and “make Release” but nothing changes…

can you try to run in the console:

gst-inspect-1.0 | grep omx

Here’s the output:

omx:  omxmpeg2videodec: OpenMAX MPEG2 Video Decoder
omx:  omxmpeg4videodec: OpenMAX MPEG4 Video Decoder
omx:  omxh263dec: OpenMAX H.263 Video Decoder
omx:  omxh264dec: OpenMAX H.264 Video Decoder
omx:  omxtheoradec: OpenMAX Theora Video Decoder
omx:  omxvp8dec: OpenMAX VP8 Video Decoder
omx:  omxmjpegdec: OpenMAX MJPEG Video Decoder
omx:  omxvc1dec: OpenMAX WMV Video Decoder
omx:  omxh264enc: OpenMAX H.264 Video Encoder

can you try running your application as:

GST_DEBUG=4 bin/videoExample | grep omx

change videoExample with whatever the name of you app is

Here it is (very loooong…):

debug4.zip (24.9 KB)

what’s the exact size of your video? some sizes need some resizing in memory which could be making things really slow, if you are using some strange resolution try using exact full hd, 1920x1080

Hello Arturo,

all videos I’ve tried are exactly 1920x1080. Here is a screenshot of its properties:

Hello Arturo,

although all the videos I’ve tried are 1920x1080, I’ve seen something strange at the output of the OF app:

pi@raspberrypi:~/openFrameworks/examples/video/videoPlayerExample $ make RunRelease 
HOST_OS=Linux
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl gtk+-3.0 
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): screenRect: 1920x1080
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): windowRect: 1920x1080
[notice ] ofAppEGLWindow: createSurface(): setting up EGL Display
[notice ] ofAppEGLWindow: createSurface(): EGL Display correctly set 0x1
[notice ] ofAppEGLWindow: createSurface(): no current renderer selected
[notice ] ofAppEGLWindow: createSurface(): GLES2 renderer detected
[notice ] ofAppEGLWindow: createSurface(): surface created correctly
[notice ] ofAppEGLWindow: createSurface(): API bound correctly
[notice ] ofAppEGLWindow: createSurface(): -----EGL-----
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MAJOR = 1
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MINOR = 4
[notice ] ofAppEGLWindow: createSurface(): EGL_CLIENT_APIS = OpenGL_ES OpenVG
[notice ] ofAppEGLWindow: createSurface(): EGL_VENDOR = Broadcom
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION = 1.4
[notice ] ofAppEGLWindow: createSurface(): EGL_EXTENSIONS = EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_vg_parent_image EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_lock_surface 
[notice ] ofAppEGLWindow: createSurface(): GL_RENDERER = VideoCore IV HW
[notice ] ofAppEGLWindow: createSurface(): GL_VERSION  = OpenGL ES 2.0
[notice ] ofAppEGLWindow: createSurface(): GL_VENDOR   = Broadcom
[notice ] ofAppEGLWindow: createSurface(): -------------
[notice ] ofAppEGLWindow: setupPeripherals(): peripheral setup complete
[notice ] ofAppEGLWindow: setupNativeUDev(): created udev object
[notice ] ofAppEGLWindow: setupMouse(): unabled to find mouse
[ error ] ofAppEGLWindow: setupMouse(): did not open mouse
[ error ] ofAppEGLWindow: setupMouse(): did not open mouse, mouse_fd < 0
[warning] ofAppEGLWindow: setupKeyboard(): unabled to find keyboard
[ error ] ofAppEGLWindow: setupKeyboard(): did not open keyboard
[ error ] ofAppEGLWindow: setupKeyboard(): did not open keyboard, keyboard_fd < 0
[notice ] ofAppEGLWindow: setupPeripherals(): native event setup complete
[warning] ofShader: GL_VERTEX_SHADER shader reports:
Compiled
[warning] precision mediump float;
#define IN attribute
#define OUT varying
#define TEXTURE texture2D
#define TARGET_OPENGLES
uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform mat4 textureMatrix; uniform mat4 modelViewProjectionMatrix; uniform float usingTexture; uniform float usingColors; uniform vec4 globalColor; IN vec4 position; IN vec4 color; IN vec4 normal; IN vec2 texcoord; OUT vec4 colorVarying; OUT vec2 texCoordVarying; void main(){ gl_Position = modelViewProjectionMatrix * position; if(usingTexture>.5) texCoordVarying = (textureMatrix*vec4(texcoord.x,texcoord.y,0,1)).xy; if(usingColors>.5) colorVarying = color; else colorVarying = globalColor; }

[warning] ofShader: GL_FRAGMENT_SHADER shader reports:
Compiled
[warning] precision mediump float;
#define IN varying
#define OUT
#define TEXTURE texture2D
#define FRAG_COLOR gl_FragColor
#define TARGET_OPENGLES
uniform sampler2D src_tex_unit0; uniform float usingTexture; uniform float bitmapText; IN vec4 colorVarying; IN vec2 texCoordVarying; void main(){ vec4 tex; if(usingTexture>.5){ tex = TEXTURE(src_tex_unit0, texCoordVarying); if(bitmapText>.5 && tex.a < 0.5){ discard; }else{ FRAG_COLOR = colorVarying*tex; } }else{ FRAG_COLOR = colorVarying; } }

[notice ] ofGstVideoUtils: allocating with 1920x1088 RGBA

Please, take a look at the last line, it is talking about “allocating with 1920x1088 RGBA”. Could this be the problem (as you stated in your last answer)?

that’s strange but usually the problem is with the width not the height, have you tried with the original video that comes with omx player?

I don’t know which video is coming with omxplayer… Do you mean Big_Bunny?