Page 1 of 1

Using 7" Touchscreen with Omxplayer

Posted: Tue Jul 17, 2018 2:02 pm
by Daeir
When building a custom media player i ran into some troubles. I'll explain my setup.

I have a raspberry pi 3 running a custom nodejs managing system. It can talk to beamers, to the gpio and it can play movies.
That way I can use the raspberry pi to say on the press of a button: turn on a beamer using pjlink, play a movie and when its finished turn the beamer off.

Now this works wonderfully when I use a beamer or a tv-screen, something with a standard aspect ratio. I use omxplayer to actually play the video files. To control omxplayer I've used a nodejs library called omxdirector.

Now the problem: I've felt the need to play some video files with this system and displaying them on the official 7" touchscreen display.
(Im going to build them inside a scale model of an old factory and use the screen to play old video footage of people working there)
I've noticed the screen has a somewhat odd resolution of 800 x 480. So i made some video files having exactly that resolution ( incorporating black bars inside the video to prevent distorting)

When I tried to play the video's I ran into a problem. while the raspberri pi verbose screen uses the entire display. Same goes for when I use startx( i see a little distortion wich I blame the slightly non square pixels for). But when I play a video using omxplayer the video is very distorted and squashed in the Y axis. It seems omxplayer thinks the screen has an odd resolution. When I use omxplayer directly via the commmand line the problem persists. It looks like omxplayer thinks the video or the screen is somewhere in the order of 800x400 or 800x350.

Things I've tried:
  • Setting some settings in the /boot/config.txt

Code: Select all

  • I've started the video file using omxplayer directly, with the same result
  • I've used omxplayer --display 4 /location/of/file.mp4
  • I've used omxplayer -I file.mp4
with the following output:

Code: Select all

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Fatplayer/media/5-ScreenSaver.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2018-07-16 13:27:55
    encoder         : Lavf57.71.100
  Duration: 00:02:00.02, start: 0.000000, bitrate: 35 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 800x480 [SAR 1:1 DAR 5:3], 26 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      creation_time   : 2018-07-16 13:27:55
      handler_name    : VideoHandler
      timecode        : 00:00:00:00
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default)
      creation_time   : 2018-07-16 13:27:55
      handler_name    : SoundHandler
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
      creation_time   : 2018-07-16 13:27:55
      handler_name    : TimeCodeHandler
      timecode        : 00:00:00:00
Video codec omx-h264 width 800 height 480 profile 77 fps 25.000000
Audio codec aac channels 2 samplerate 48000 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
V:PortSettingsChanged: [email protected] interlace:0 deinterlace:0 anaglyph:0 par:1.25 display:0 layer:0 alpha:255 aspectMode:0
I would assume omxplayer sees the video in the correct resulution based on this
  • I've used a .mov video file (maybe the codec messses things up ... it didnt)
  • The only thing that seems to work is using the --win "0 0 799 479" argument. However this is not an argument I can use (afaik) within the omxdirectory library
Furthermore I got the impression people could use the touchscreen to play video's just fine.

Do you guys have any idea where I might start looking for a solution to my problem? Like can I force omxplayer to stretch all video to 800x480? Or does omxplayer have a certain settings file where he fetches the screensize wich I need to adjust?

Thanks a bunch in advance!

Re: Using 7" Touchscreen with Omxplayer

Posted: Wed Jul 18, 2018 6:28 am
by 6by9
I've not checked the code to confirm, but par is normally pixel aspect ratio. The video has been encoded saying that the pixels are not square (1.25:1, or 5:4), and omxplayer will be compensating for that.

Re: Using 7" Touchscreen with Omxplayer

Posted: Wed Jul 18, 2018 9:51 am
by Daeir
Thanks a lot for your suggestion!

I checked the render settings in my video program( After Effects) and the settings were square pixels with a resolution of 800x480
I tried a bunch of different aspect ratio settings in a re-encoder program (FFPMEG) and tried a bunch of different aspect ratios.
Upon playing these videos i did notice difference in stretching and the video filling more or less parts of the screen.
So conclusion for now is: you were right, omxplayer is trying to compensate for a mismatch between the screen and the video

I couldn't find the ideal settings though that would fill the screen. An aspect ratio encoded in the video of i believe 3:2 ( but i might mis-remember it) came closest. Still the video didn't fill the screen and looked distorted.

So I went an looked for a different solution and I stumbled upon this topic:
What I did was the following:
  • I went to /usr/bin/omxplayer and edited it using nano(backed it up first!)
  • I looked for the following line in the code

    Code: Select all

  • So now the line looks like this

    Code: Select all

    LD_LIBRARY_PATH="$OMXPLAYER_LIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $OMXPLAYER_BIN --win "0 0 799 479" "[email protected]"
This seems so work like a charm. I do still see a bit of distortion due to the non square pixels, but that is acceptable to me.
This still isn't a pretty solution and feels kinda hacky but it works for now.
Hopefully I can help someone in the future with this solution ( off course if someone has a better solution, let me know!)

Re: Using 7" Touchscreen with Omxplayer

Posted: Thu Jul 19, 2018 7:22 pm
by aBUGSworstnightmare
Sorry for asking, but why do you use --win command with 799 pixels width and 479 pixels height?

This should be 800 and 480 instead ( ... That's the reason why your video isn't 'full-screen'.

Re: Using 7" Touchscreen with Omxplayer

Posted: Thu Jul 19, 2018 9:34 pm
by Daeir
Because, as I understood the --win command it draws a window between two points defined on the screen.
So, when you look at the command --win x1 y1 x2 y2 - x and y 1 would be the top left point of the video screen, and x and y 2 would be the bottom right of the video screen.

So in this case the top right point sits at coordinates x 0 and y 0, because computers start counting at 0. So coordinate 0,0 is actually the first pixel on the left on the first row from the top, (physically pixel 1,1 if you will). The second pixel from the left on the first row would then be coordinate 1,0 (physically 2,0). So then the 800th pixel from the 480th row would be at coordinate 799, 479 (physically 800, 480).

So when I draw a box from point 0,0 to point 799,479, I've drawn a box that contains 800 pixels in width and 480 pixels in height,
Think of it like an array. When using an array, the first spot has an index of 0, so the 10th spot has an index of 9.

Does that make any sense?

Re: Using 7" Touchscreen with Omxplayer

Posted: Fri Jul 20, 2018 5:36 am
by aBUGSworstnightmare
800x480pixels TFT array
pixel_1.jpeg (64.17 KiB) Viewed 2049 times
Fully understood!
Let's look at the picture above (showing a display with 800x600pixels as an example).
I only look at the 1st line now, so to me 1st pixel is index 0 and 800th pixel is index 799 from matrix point of view.

If one wants to write 255 to all the matrix elements (pixels) of 1st Iine simplified this would look like:
'write 255 to pixel (matrix element)';
} while (i < 800);

You see where the 800 goes? Does this make sense to you?
If not, replace 'write 255 to pixel (matrix element)' with 'printf("%d\n",i);'. What would be the first and the last value printed? How many values will be printed in total?

Re: Using 7" Touchscreen with Omxplayer

Posted: Fri Jul 20, 2018 7:46 am
by Daeir
Ok, so as I understand you say in the case of the command being --win x1 y1 x2 y2 that the value of the x and y would be the same as saying a for loop or a while loop. So you would get the following pseudo code

Code: Select all

void drawScreen(int x1, int y1, int x2, int y2){

	for(int row=y1; row<y2; row++){
	   for(int column=x1; column<x2; column++){
	       applySomePrettyColorAt(column, row);
So that would mean the x1 and y1 would be the starting point of the loop and you would count to excluding x2 and y2. Using the < operator instead of my initial thought essentially using the <= operator, counting to including x2, y2.

Interesting, I hadn't thought of it in that way.

Re: Using 7" Touchscreen with Omxplayer

Posted: Fri Jul 20, 2018 10:06 am
by aBUGSworstnightmare
You may have a magnifier lens (or a good camera on your mobile in case your eyes are not that good any more due to age i.e.). Then simply make a shell script where you play the same video clip (preferrably a short one) with different window sizes.
Use your magnifier lens to see what will happen (as you can see individual pixels) and count them