JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

omxplayer subtitles are poorly rendered.

Sat Oct 26, 2013 2:30 pm

So my Raspberry Pi, which I had been thinking of getting for a while as a combined games console/media centre, arrived today. After a lot of faffing around with emulators before it arrived, I am finding the real thing so easy to use.

I was going to use VLC to play movies, but after some searching around I found out about omxplayer - how it is better because it uses hardware acceleration, and also that it comes pre-installed in the default official Raspbian build. In less than a day I am playing MKV files from a Windows share that previously my £200 blu-ray player refused to play and which I had to transfer on a USB drive.

There is one problem. The subtitles. Using left align leaves a big gap on the left and then the subtitles shoot across the screen and disappear off the right hand side. Using centre align actually works much better, but when the subtitle is too long, I lose the start and end of it.

The subtitles work fine on VLC on my PC. They are also in a much nicer font, and don't have a semi-transparent black frame around them.

I'm guessing that omxplayer doesn't use the font included in the MKV file for use with the subtitles. Ok, fine, no biggie really. when I get around to it I can extract them myself and push them onto the Raspberry Pi. But word wrap is a biggie.

Can anyone offer any advice and help?

I'd have a go at editing the source code myself, but right now I cannot cross-compile a simple "hello world" program :(

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5343
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: omxplayer subtitles are poorly rendered.

Sat Oct 26, 2013 2:56 pm

I'd suggest you open an issue here:
https://github.com/popcornmix/omxplayer ... state=open

and include a link to the srt (or a cutdown sample of the mkv file)

You could also try xbmc (look for openelec or raspbmc for installs that include xbmc) which has more advanced subtitle support.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Sat Oct 26, 2013 3:44 pm

I thought omxplayer was the player used by XBMC.

Also, while demo-ing my new toy to a friend, I found that for an old AVI file I haven't watched in years, the subtitles were perfect. They even used the font included in the file.

I can't include a cut down version of the file, unless you know a way I don't. You see I think there is something different about the way the files are put together, something subtle. Although VLC plays the files perfectly, when I tried to convert them so that they would play on my Blu-ray player (which cannot handle certain types of MKV files - possibly variable frame rate ones) I managed to get the audio and video to convert perfectly, but VLC adamantly refused to include the subtitles, no matter what command line options or GUI options I used. When I then reconstructed the converted video and audio back into a new MKV file, together with the subtitle track from the original, the file played audio and video perfectly on my Blu-ray player, but there was no sign of subtitles.

The only way I know to cut a file down is using VLC, and since it refuses to include the subtitles...


Also, while demoing my new toy, I found that all the MP4 files I created using VLC won't play properly - omxplayer doesn't show any video.

I'll raise a bug report (or two) at that site you mentioned.

Thanks.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5343
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: omxplayer subtitles are poorly rendered.

Sat Oct 26, 2013 9:36 pm

xbmc handles rendering the subtitles itself and is far more advanced than the basic subtitle support added to the command line omxplayer.
What was the video codec used in the mp4 files that didn't play? (mediainfo will show you).

I'd use mmg from http://www.bunkus.org/videotools/mkvtoolnix/ for cutting down mkv files.

henle
Posts: 65
Joined: Sat Apr 21, 2012 7:23 pm

Re: omxplayer subtitles are poorly rendered.

Sat Oct 26, 2013 11:54 pm

Omxplayer has options for font and font size, and --no-ghost-box disables black boxes.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 7:23 am

The video mp4 codec that doesn't play is "H264 - MPEG-4 AVC (part 10) (avc1)" according to VLC. I transcoded using VLC on the command line with ":sout=#transcode{vcodec=h264,vb=0,scale=1:std{access=file,mux=mp4,dst=${DEST}}".

I have mkvtoolnix. I'll give mmg a go. What is a good file size or should I just experiment until I reach the subtitle that is too long?



Thanks for the info, Henle. I had already tweaked font to a nice font, and font size down a bit, but I really need them to word wrap. I wasn't aware of the "--no-ghost-box" option though - I missed that. Thanks for the info. I suspect that the AVI with the perfect subtitles was because the subtitles had been rendered into the video.

Also worth noting that the MKV file contains 13 font attachments!

I'm working on a Cygwin cross-compiler now, and once I have that I may try to implement word wrap on subtitles myself.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 8:28 am

I have a cut down mkv file (60 seconds) with really long subtitles at about 30 seconds, and long subtitles at other places too. It's 20Mb. I don't think I can attach it here. Any suggestions?

I also have an mp4 converted version which should show the issues with the mp4 playback I was talking about. It's about 14Mb long.

henle
Posts: 65
Joined: Sat Apr 21, 2012 7:23 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 11:42 am

I don't think we need a sample file to demonstrate that there is need for word wrapping with certain files. If you want, you can write a function that takes a vector of strings and returns a wrapped vector of strings, and I'll do the necessary plumbing inside omxplayer to integrate it.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 12:35 pm

There is no "--no-ghost-box" option on my version of omxplayer.

I can have a go writing a word wrap routine, but I would need to know how the rendering engine works, specifically APIs to calculate width of rendered text. The routine would also need access to information such as the width of the video stream and so on. It'll take some time to dig into the omxplayer code to figure out how all that stuff works.

To do the wrapping, would inserting newlines work, or would the routine need to return a vector of smaller strings? If so then surely if the routine is passed a vector of strings, it would need to return a vector of vectors of strings, one vector for each input string. I also think the return for each string would need to return some sort of positional information. You could calculate the positioning for each string in the output vector in turn, but it would probably be more efficient to calculate it as part of the word-wrapping routine.


I'm not sure if it is related to omxplayer specifically, but when I switched my TV to HDMI just now, there was none of the usual boot up and login prompt showing. I SSHed in and ran omxplayer, and got sound and subtitles but no video. When I started X, the desktop appeared, but still just sound and subtitles from omxplayer. I killed the X server and got the bootup text and login prompt appearing, but still only sound and subtitles and no video. In the end I rebooted the Raspberry Pi and it worked fine after that.

henle
Posts: 65
Joined: Sat Apr 21, 2012 7:23 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 1:12 pm

You can get the latest version here: http://omxplayer.sconde.net/

Use the character count for deciding when to break lines. It will work well enough since you're not trying to perfectly justify the lines, you just want to make sure their lengths are reasonable.

Actually, the function should take and return a vector (the lines of a single subtitle) of vectors of UTF-8 codepoints, you can consider them ints.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 6:51 pm

Three words - variable width fonts. And even if I approximated to fixed width, I still need to know how wide the text renderer will render them since both font and size are configurable. I'd also still need to know the image width. I get the impression that omxplayer renders video at native resolution unless the -r option is given to make it fill the screen, and even then it sounds like it is just resetting the output display size, so either way I'd need to know the image width.

And clearly the text renderer on "center" align is taking the width of the string into account to display it centred - it must do. So since we are calculating the render width of each sub-string when working out the word wrapping, it makes sense to remember that value and pass it back to save having to repeat the calculation. The Raspberry Pi is hardly over-endowed when it comes to processing power.

i'm sorry if I am sounding picky, but one reason I just got given the worst written piece of crap at work is because the people who gave it know that I am extremely picky when it comes to the quality of the software I write and am a bit of a perfectionist, and they are fed up with the quantity of bugs in this thing. That's who I am - I don't believe in doing a half-arsed job of work.

I'm currently struggling to build my own cygwin based cross-compiler because my Windows 7 install refuses to act case sensitive when dealing with the file system despite me setting all the relevant registry entries. Once I have a cross-compiler I'll do a compare of omxplayer and VLC with hardware support enabled and if omxplayer wins (from what I have read it will) then I'll implement a proper fix and offer it up as a pull request.

From what you say, you want UTF8 strings encoded as vectors of UTF 8 code points, by which I guess you mean characters. They are not ints. UTF8 is variable width. Why do it as a vector of characters? It's extremely memory inefficient to encode the whole string in that way when a simple null terminated byte array is sufficient. Putting each sub-string in a vector is fair enough, if you must suffer the memory overhead of using C++ vectors in the first place ;) but putting each character as an individual element in a vector... What's the overhead of each element of a vector? I'd be surprised if it was less than 4 bytes, so the overhead will be more than 100% of the actual data size!

henle
Posts: 65
Joined: Sat Apr 21, 2012 7:23 pm

Re: omxplayer subtitles are poorly rendered.

Sun Oct 27, 2013 7:10 pm

Oops, I meant Unicode code points.

JontomXire
Posts: 18
Joined: Sat Oct 26, 2013 2:22 pm

Re: omxplayer subtitles are poorly rendered.

Wed Oct 30, 2013 8:22 am

I still need to know:

Display width
Rendered character width for each character


I still think:

Using a vector to return a string is incredibly inefficient in memory.
Not returning the calculated width of each row of subtitles is missing a chance to be more efficient.

Better to return a vector of structures containing an unsigned int of width and a null terminated string. omxplayer uses unicode strings then? Not UTF-8 or something like that which is more memory efficient?

henle
Posts: 65
Joined: Sat Apr 21, 2012 7:23 pm

Re: omxplayer subtitles are poorly rendered.

Wed Oct 30, 2013 5:07 pm

The cleanest way of introducing word wrapping into the current code, is to base it on the character count. The maximum length of a line can be specified on the command line, so there is no need to try to calculate what a good maximum may be. People even have different preferences (I prefer 40, regardless of font size). I have a program that does this with srt files, and it works great, though it is not written in C++.
Better to return a vector of structures containing an unsigned int of width and a null terminated string. omxplayer uses unicode strings then? Not UTF-8 or something like that which is more memory efficient?
The UTF-8 strings must be decoded and formatted before rendering, and that is when word wrapping should be performed.

You are of course free to propose a more complicated implementation, but I'm afraid I don't have time to help with that.

Return to “Troubleshooting”