Converting MP4 with subtitles for Roku

28 Oct 2015 06:37

I recently bought a HiSense Roku TV and it's awesome (I've never had a Roku device before).

The problem is that even though the TV has an USB port and Roku has a "Roku Media Player" channel that allows you plan video and audio files from the USB disk, not all formats are accepted.

Interestingly Roku has support for subtitles, but the support is quite limited. I found out that one of the options that work nicely is to have the subtitles embedded into the movie itself, given the movie uses Matroska container (.mkv files).

On a side note, if the files are not encoded "properly" (Roku only supports a selection of video and audio codecs), you'll need to re-encode the video using ffmpeg or avconv, but how to do it is much simpler to Google than how to deal with the subtitles. In this post I'll only show you how to deal with the subtitles.

So let's see what we have:

quake@quake-laptop:~/movies$ ls
movie.mp4 movie.txt

There's a MP4 file and subtitles in a separate file.

quake@quake-laptop:~/movies$ avconv -i movie.mp4 -f microdvd -sub_charenc cp1250 -i movie.txt -c:v copy -c:a copy movie-with-subs.mkv

Let's look at this command part by part:

  • avconv — the tool we're using
  • -i movie.mp4 — the movie to convert
  • -f microdvd — format for the subtitles (this part is actually optional)
  • -sub_charenc cp1250 — the encoding of the subtitles (optional if UTF-8)
  • -i movie.txt — the subtitles
  • -c:v copy -c:a copy — copy the audio and video stream (rather than re-encode)
  • movie-with-subs.mkv — the output file

Which is very nice is this command will not do any re-coding, it will only repackage the movie from MPEG to Matroska container and convert the subtitles. This means there's no quality lost and it only takes a few seconds.

As noted above if the file is not playable on Roku (or there's audio missing) you may actually need to transcode the file (omitting or modifying the -c:v copy -c:a copy line).

Comments: 0

Working around a buggy sound card

02 Dec 2014 23:34

I found the laptop I bought recently has a weird thing with its soundcard. It plays music OK, it also allows you to change the mixer levels, nothing special, but when you try changing mixer setting while the music is playing the music starts getting choppy and the process handling the mixer tend to freeze. Also you cannot pause the music, sometimes it repeats the same sample over and over and it gets very annoying.

My approach to this issue was to use PulseAudio software mixer capabilities, so the hardware mixer is never adjusted (other than for the initial setup).

Step 1. Getting PulseAudio to use the software mixer

I found no good documentation on this other than PulseAudio uses paths to convert the desired volume to the hardware mixer settings and if it lacks the ability to do so it would turn the volume up/down using software. Reading between the lines I realized if I remove the paths I will get what I want. Just do this and restart pulseaudio and you'll have PulseAudio doing all the mixing in software:

sudo mv /usr/share/pulseaudio/alsa-mixer/paths /usr/share/pulseaudio/alsa-mixer/paths.bak

Verifying it works

Open two terminal windows. In each of them open alsamixer. Both should display very simple controls and say Card: PulseAudio. Use F6 to switch to the real card in one of the windows. Usually the cards have plethora of controls, so should yours.

Now change the output volume in the alsamixer still saying "Card: PulseAudio". If the volume reported by the other alsamixer does not change, it works as expected!

If you now rename the paths directory back and restart the pulseaudio process, updating the PulseAudio volume should update the real device volume as well.

Step 2. Integrating this with XFCE (or other DE)

The way xfce4 handles the volume is two-fold:

  • There's a xfce4-volumed daemon. It only controls the key bindings. It binds volume up, volume down and mute keys to control the real device controls
  • There's a panel applet called "Audio Mixer" that shows the current volume level and lets you change the volume as well.

Both component are optional and both seem to not work with PulseAudio (even through PulseAudio ALSA emulation which tricks alsamixer for instance).

We're going to overcome this problem by replacing these components with two other programs.


pa-applet will replace the "Audio Mixer" applet. The difference is the pa-applet docks to the systray, so is not XFCE-specific. The downside is we don't have control over the specific position of the icon, all we know is it will appear in the systray (so don't forget to have the systray applet added to the panel).

In order to install this software you need to clone the source, and run ./, ./configure, make, sudo make install. You will get information about deps missing, for instance:

configure: error: Package requirements (glib-2.0) were not met:

No package 'glib-2.0' found

You need to find the proper *-dev package for each unmet dependency (for this one it will be libglib2.0-dev).

I came across one additional problem. The software seems not updated after some GTK+ 3 updates and it uses a deprecated function. Because the code is configured in a way that every warning stops the compilation, it wouldn't let you compile the code unless you open the src/Makefile file and then find and remove the -Werror flag from it.


This part will take care of binding the media keys to the pulse audio controls (rather than to the sound card controls).

You need to download the tar package, untar it, ./configure, make, sudo make install. It also requires quite a few libs to be installed, but I didn't found any issues when compiling.

Hooking this up together

Since I didn't need the original xfce4-volume anymore I decided to remove it:

apt-get remove xfce4-volumed

But because XFCE will try to launch this anyway on each start, I decided to take advantage of it and replace it with a script:



Add the executable bit, restart the laptop and all should be working correctly at this moment.

Setting the hw mixer controls

Since PulseAudio won't update the hw controls after you follow up this little howto, it's quite important to set all the important channels to 100% (or other number up to your taste). The way to update the hw controls was described before.

Open the terminal, type alsamixer and hit F6. This will give the list of ALSA devices besides the PulseAudio emulation, your real sound cards should display as well. Choose the right one and you should be given access to tweak the real card controls.

Note if you removed the PulseAudio paths, the PulseAudio controls wouldn't update when you tweak the hw controls.

Comments: 0

Accessing HTTPS Over HTTP

01 Nov 2014 16:47

For one my internal projects, I needed a HTTP-to-HTTPS proxy in a way that a client connects to HTTP network inside the trusted network and the server connects through the Internet to the service via HTTPS.

I quickly set this up using Apache. Here's the virtual host file:

<VirtualHost *:8371>
        ServerName              localhost
        ProxyPreserveHost       Off
        SSLProxyEngine          On
        Header                  edit Set-Cookie secure;.HttpOnly HttpOnly
        RewriteEngine           On
        RewriteRule             ^/(.*)$1 [P,L]
        ProxyPassReverse        /

You need to enable the following modules for that: proxy, proxy_http, rewrite, headers

Note, above I also mangle the Set-Cookie response headers in a way, that every http-only secure cookie (this means a cookie is transmitted to the server only over a secure transport and is not available on the client side) is converted to a http-only but non-secure.

The rule I produced (convert regexp "secure;.HttpOnly" to just "HttpOnly") may not work for you because I targeted one particular service and the construction of such cookies may be different for the one you want to proxy.

The second note is that, the service you're proxying might actually check the protocol on the client side as well, which we cannot mock on the server-level. I was lucky my service didn't have such checks.

Comments: 0

Cups And Easy Printer Sharing

22 Apr 2014 20:53

Today I decided I want to share an USB printer via CUPS. This has always been fun and easy thing to do.

After spending some time figuring out why this doesn't work out of the box, I learned most of the tutorials are not right about one thing. They claim to share the network in the same (sub)network you don't need any special configuration on the client. That's wrong. You need to install cups-browsed package on the client:

sudo apt-get install cups-browsed

Then you just wait 30 seconds and you're remote printers should appear in http://localhost:631/printers

If you want to print from a different network (or your stupid router doesn't bridge Wifi and Ethernet networks) you may need to add a line like that:

BrowsePoll server-name

to the /etc/cups/cups-browsed.conf file.

An update: actually BrowsePoll server-name doesn't seem to work. I needed to replace the server name with the server IP address.

Comments: 0

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License