Hardware-accelerated transcoding on the Raspberry Pi 4 Model B with DietPi

8 years after buying a Raspberry Pi Model 1B, I finally bit the bullet and invested in an upgrade, this time to the 8GB model of the Raspberry Pi 4 Model B (at the time on sale from Okdo for £62). This was largely because I wanted it to do video transcoding using ffmpeg. More specifically, I wanted to concatenate some H.264 files together and compress them at the same time.

Having installed DietPi as my distro of choice, my first attempt at this went something like:

The problem with this is that it’s very slow (even when using -profile ultrafast). The CPU in the 4B, while much better than the 1B, is just not capable enough to encode H264 video very quickly. In particular, I needed it to transcode at a rate greater than 1x (i.e. to transcode more than one second of video per second) – a target it was missing by some way. I was just about to despair when I realised that the 4B supports hardware acceleration for H264, as set out in this excellent blog post by Will Usher.

Suitably enthused, but expecting something bright green, I switched to h264_v4l2m2m:

and… it didn’t work:

To cut a (very) long story short, the probem I was having was with DietPi and its reduced driver set. In particular, bcm2835-v4l2 is hidden behind a config option (“RPI Camera” under “Display options”). Without bcm2835-v4l2, h264_v4l2m2m can’t access the necessary video devices. To fix this problem, simply enable RPI Camera and reboot.

Oh, and I still had to build my own version of ffmpeg, as Will did, but he’d done the hard detective work there.

Installing Pi-Hole

Once I’d got my Raspberry Pi back up and running, one of the things I was desperate to try out was Pi-Hole, a DNS sinkhole capable of running even on my extremely old Pi. DNS sinkholes make it possible to block ads, trackers and malware at source, speeding up browsing and improving privacy. The particular advantage of a Pi-Hole is that it cannot operate at the network level, blocking ads automatically on every device that connects to a WiFi network. Well, it’s got to be worth a go, right?

Continue reading Installing Pi-Hole

Raspberry Pi revisited

As documented a long, long time ago, I’ve got an old Raspberry Pi (B 1.2) kicking around. I wanted to try to teach it some new tricks, but once again my first challenge was getting it set up. This time, I don’t even have a TV I can plug its composite output into and I couldn’t be bothered to get HDMI working. I’m going to have to do this completely blind. Continue reading Raspberry Pi revisited

Constitution of Uganda: primary sources

I’m doing quite a lot of research at the moment into the history of Uganda (1890 to present). Unfortunately it is not always easy to find primary sources and documents online. This is my running list, published here in case it helps anyone else:

SSD part 3: Upgrading to Windows 10

The first SSD I installed was into my laptop, back in April 2014. But since then I’ve shuffled them around, and I was back to having an old HDD. This was just about tolerable, but with the 240GB OCZ Trion 100 (a ‘meh’ quality SSD) available for under £40, and Windows 10 upgrades nagging, I thought I’d rectify the situation. Unfortunately, it didn’t exactly go well.

Continue reading SSD part 3: Upgrading to Windows 10

Installing CyanogenMod 12.1 onto a Nexus 4

And so it came to pass that the Nexus 4, which was already a year old when I bought two years ago, started getting slow. I was hopefully initially that Android M (marshmallow), Google’s latest version of the operating system, would help: it apparently has a lower RAM footprint than L (lollipop). But unlike in the case of my Nexus 5 (which has already received the update) Google does not intend to ship M to Nexus 4s. Thus I had three three options: slug it out; hack a version of Android M onto it; or install a maintained fork that would (eventually) pick up the benefits of M. I chose the latter, going with the most popular fork: CyanogenMod, version 12.1 (a stable version 13 – i.e. one based on M – is expected around the New Year).

Installing CyanogenMod is not a walk in the park, even following the detailed instructions available on the CyanogenMod website and working out of Ubuntu. The following commands were useful (gapps.zip is an OpenGApps package and TWRP is, well, TWRP).

Unfortunately the “stock” OpenGApps package doesn’t seem to fit in the system partition of a Nexus 4 (and hence use of Advanced Options is advisable). To ascertain how many Google Apps needed excluding, and to effect that change, the following commands were useful:

Factorise

factoriseAs I mentioned in my previous blogpost, I am now the proud owner of a Pebble Time. This week I took the plunge and decided to make my own watchface in honour of xkcd #247 (“Factoring the time”). Pebble watchfaces have historically been written in the programming language C, although (given the relative unpopularity of C) the team there have also built a JavaScipt API, PebbleJS. I mean, I’ve never written any C before, but there’s no time like the present eh?

C turns out to be a particularly intensive language to work in, especially without the benefit of large utility libraries. For example, its array handling is poor, lacking push/pop functions, an accurate count function or indeed join/implode. The other thing I struggled with was performance enhancement. The major challenge when developing a watchface is battery conservation. Although Pebble provides some guidance covering this aspect, it remains vague (and difficult to even deduce through trial and error. For example, my initial design factorises the time afresh every minute using a blunt force recursive technique (given the maximum target is 2359, this is not too inefficient). But equally, I could store the pre-computed factorisations in a file. Would this be better or worse for battery conservation? Who knows.

The full code to the Factorise watchface is available from Github under the MIT licence.

Pebble Time: First Thoughts

Pebble TimeAbout a fortnight ago I added at Pebble Time to my collection of gadgetry. It’s one of the more basic second gen smartwatches, with a 64-colour e-ink screen rather than a touchscreen, as well as a microphone. Most of its functionality is derived from a bluetooth connection to a mobile phone. To buy one in the shops will set you back around £200. Continue reading Pebble Time: First Thoughts

SSD transfer (again)

Sims 3 screenshotThis week’s task was move by existing my old SSD from my laptop to my gaming desktop, which I’ve had since September and am otherwise very happy with — certainly, the AMD FX-6300 Six Core CPU + Radeon R9 270X can handle most things thrown at them, with the unusual exception of The Sims 3 (no idea why the Sims is an exception; maybe something to do with the age of the game). Continue reading SSD transfer (again)