…of information on capturing HD console game video on the Linux platform. This is mostly due to the fact that there is very little support for HD video capture devices in the kernel. A Google search really only provides one device that has a reasonable level of support for this type of job, the Hauppauge HD-PVR (1st generation). And most of the documentation for that, exists within the MythTV wiki, to enable you to record TV shows from Cable or Satellite broadcasts – http://www.mythtv.org/wiki/Hauppauge_HD-PVR – So how do we record games?
Why is this a problem? Use Windows…
Our house is an Linux house, we don’t have a single Windows PC anywhere. This includes my 8 year old son, who thanks to Ubuntu and Mojang’s cross-platform gaming architecture (Java) is a massive fan of Minecraft and the now infamous stampylonghead. This has worked well and I have been able to provide pretty much any game, with a little research, he has requested. And if I can’t, there is always the Playstation 3 (we have Minecraft for both platforms).
As I said, this has worked well until the other week when my son asked:
“Can I create videos with the PS3 and add commentary like Stampy?”…..
The Mission begins…
Ok, so we know we are restricted to the first generation of Hauppauge HD-PVR capture devices, these have now been out of production for a short while so we have to resort to our favourite auction site. The MythTV wiki states that only hardware models with revisions 1212 and 1445 are supported by the linux kernel. Searching eBay it becomes difficult to find models with these numbers but there are plenty with revision number 1228 – (look at boxed items – zoom into bottom left of front image).
As it turns out these 1228 models are the later revision of the first generation devices and are fully supported by recent kernels. This is a stroke of luck as I bought a boxed 1228 that was advertised as 1212 on the site… once in hand Ubuntu 14.04 LTS detected and loaded the device (using ‘dmesg’):
[6138207.477355] usb 2-1.8: new high-speed USB device number 49 using ehci-pci [6138207.601104] usb 2-1.8: New USB device found, idVendor=2040, idProduct=4903 [6138207.601110] usb 2-1.8: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [6138207.601115] usb 2-1.8: Product: Hauppauge HD PVR [6138207.601118] usb 2-1.8: Manufacturer: AMBA [6138207.601122] usb 2-1.8: SerialNumber: 00XXXXXX [6138207.602343] hdpvr 2-1.8:1.0: firmware version 0x14 dated May 12 2010 10:29:31 [6138207.602348] hdpvr 2-1.8:1.0: untested firmware, the driver might not work. [6138207.817719] hdpvr 2-1.8:1.0: device now attached to video0
But wait “untested firmware, the driver might not work” doesn’t sound good!
OK, this is where there is no way around the Windows requirement. As it turned out the my device came with a firmware from 2010 (v1.5.6), the MythTV wiki states (as does the Hauppauge download page) that much stability is gained from updating the firmware to v1.7.1. I used a Windows PC at work to run the firmware upgrade utility. I read many posts in forums that have used earlier versions of firmware. In fact on older kernels (earlier than 3.2.34) the v1.5.6 firmware is preferred to correct issues with hue and saturation, see the MythTV wiki for future details. On Ubuntu 14.04 we are on kernel 3.13, we can use the latest firmware, and I wanted to play safe so updated – you only need to do this once.
It may be possible to perform the firmware upgrade via VirtualBox on Linux, however, the MythTV wiki states: “It is known to not work from VMWare Fusion, or with VirtualBox running on OS X”. I didn’t attempt this route, your mileage may vary.
Grab the latest firmware from here: hdpvr_18.104.22.168059
Or from Hauppauge: http://www.hauppauge.com/site/support/support_hdpvr.html
That looks better in ‘dmesg’:
[6140294.132054] hdpvr 2-1.8:1.0: firmware version 0x1e dated Mar 7 2012 08:25:15 [6140294.507308] hdpvr 2-1.8:1.0: device now attached to video0
N.B. Ensure you note the videoX device number, as you may need to alter this in later commands and scripts accordingly – default as shown /dev/video0
Provided you got the device with all the original cables, all you should now need are the cables to connect your console to the device.
Cables, in this case PS3…
The first generation HD-PVR does not have an
HDMI interface, only component, s-video and composite. This means we don’t have to deal with HDCP encryption, which is a good thing as the Playstation 3 will use HDCP over HDMI. However, we can still get 1080p, 1080i, 720p and lesser resolutions from the component output of the PS3. Be aware that your PC has to deal with this stream, so ensure it can deal with the bitrate and resolution via USB – as these were for YouTube I decided that 720p would be more than enough for an 8 year old.
For the best picture quality, or 720p and above, we need a PS3 component cable:
Use your normal channels to purchase this, Amazon, eBay etc, but be aware that quality varies and as component connections are analogue, picture quality can suffer on lower quality cables. Lots of forum posts state that the Official Sony PS3 Component cable is the way to go, again this is now out of production. I found the original Sony cables available to be prohibitively expensive. The Logic3 brand seems to be also recommended, and these are still available at the time of writing. I found others produced a picture without issue for me.
You can of course drop to lower resolutions: composite (RCA) or s-video with 480i or 576i resolution – the HD-PVR will record these with ease. I am intending to use this functionality for transferring VHS or Super 8 videos I have archived away, but older consoles like GameCube, Nintendo64 or Dreamcast also fall into this category using the cables that were provided with the consoles.
To record an audio track, for commentary, you also need a microphone on your Ubuntu PC. You could of course use the built-in mic on your PC, if it has one. I got hold of a cheap USB head-set microphone, you are unlikely to run into linux compatibility here:
You need to ensure that your microphone is correctly selected as the default device in the ‘Input’ section of Sound Settings within Ubuntu. I found best results using ‘Unamplified’ setting – if you get no sound on recordings you need to look here.
Connect it all together…
Thus far we could have followed any Game Capture tutorial, and we have all the hardware connected to our PS3, TV and Ubuntu PC, we tell the PS3 to output 720p video via component (Sony Instructions) and we are ready to record……. argh but wait this is linux…..
The MythTV wiki provides us with a simple test to see if video is being streamed while the PS3 is playing:
All the commands shown as below are performed in ‘Terminal’:
cat /dev/video0 > dump.ts
This will provide us with a Transport Stream (.ts) of video into a file called dump.ts, which we can use the ever useful mplayer to view. Excellent the HD-PVR lights up, we have a stream and can record it…. now what…
Searching for linux software that can now provide us with a frontend to manage capturing and adding an audio channel (commentary in this case) turns up nothing, only MythTV appears to do anything useful with the device.
There are forums that mention capturing video using the ‘cat’ method above , then recording a commentary channel at a later point using audacity and the video as a guide. Then stitching it all together with kdenlive. This is not going to work with an impatient 8 year old, not to mention missing the thrill of live commentary catching all the surprises and tumbles in the game. It wouldn’t be like Stampy…..
Here is a solution that works for us on a very average specification laptop:
- Works from a launcher on the Ubuntu Desktop
- Provides video feedback to the screen
- Provides live commentary
- Easy to start/stop recording
- Video and commentary audio track combined on completion
Nothing is ever straightforward…
The sleeping ‘cat’
So with the ‘cat’ method we can pipe to mplayer to give us some video feedback:
sudo apt-get install mplayer
cat /dev/video0 | mplayer -cache 1024 -
Excellent we can mirror the video to screen. Let’s load up a game… screen change… wait… mplayer freezes… light goes off on HD-PVR to signify it’s stopped streaming….. what gives….?!?
The problem is we are using ‘cat’. As the PS3 screen refreshes on a resolution change, buffering on the device pauses, throwing ‘cat’ off the scent and causing it to bail out as the /dev/video device is momentarily not passing data. This proves a problem within the games at points such as level changes etc.
To fix this we need a ‘cat’ replacement that can handle the pauses, after some searching I found some code that I modified to handle this:
You may need just the basic compilation tools to compile this:
sudo apt-get install build-essential
cc capture.c -o capture
The compiled ‘capture’ C binary should be copied to /usr/local/bin/capture
capture /dev/video0 | mplayer -cache 1024 -
Now works between all screen changes. So we have video to screen, how do we get mplayer to also dump to file? It can’t, but this is where our friend ‘tee‘ helps out:
capture /dev/video0 | tee -a -i dump.ts | mplayer -cache 1024 -
Excellent, we can watch and dump video to file (dump.ts) simultaneously. Quitting mplayer (‘q’ key) stops recording and streaming video. Just what we want.
Sound as a pound
You remembered to configure your microphone as the default ‘Input’ sound device – right?
Then, we test sound recording using ‘sox’:
sudo apt-get install sox
sox -t alsa default dump.wav
Again we can use mplayer to test the outputted audio file (dump.wav).
If you got this far, then everything is in place. All we need now is a script we can launch from the Desktop to tie all this together in time and combine the video and audio…
First we need to ensure all the utilities we need are installed:
sudo apt-get install mplayer sox v4l-utils lame mkvtoolnix
As we have updated the firmware we can ‘tune’ the HD-PVR with v4l-utils – the script will only setup some defaults. More options are on the MythTV wiki page. The other utilities provide MP3 encoding for use with the MKV creation tools for the final file. The final file will be .mkv format.
Place this Bash SCRIPT in your home directory and make executable, things to check in script:
- The DEVICE variable will need changing if /dev/video0 is not your device name.
- The bottom line of the script can be enabled to cleanup files better.
- By default, the script will create all filenames based on the timestamp at the time you ran the script.
- You can setup the INPUTS you are using on the HD-PVR:- Default is ‘rear component’ connectors.
chmod 755 HDR.sh
Then create a desktop launcher, make sure it’s set with ‘Application in Terminal’:
- Start via the launcher.
- Play your game, record your commentary.
- To quit hit ‘q’ in the mplayer video screen.
- Watch the Terminal screen to see encoding progress
- Watch your .mkv video from your ‘Videos’ Folder
- Upload to YouTube….. and don’t run out of disk space.
- While playing, the video on screen can lag behind the TV display, this is due to mplayer buffering.
- The on-screen display is really only useful for visual feedback that the process is running and a method to introduce user interaction for quitting the recording process – ‘q’ in mplayer.
- Commentary should be based on events on the TV display.
- Of course, this method relies on the fact you record the perfect video from beginning to end – if this doesn’t work for you kdenlive will edit the videos, and you don’t have to worry about separate audio tracks.
Hope this is useful to others.