2012-08-18

Setting up a cyberJack chipcard reader under Fedora 17 x86_64

  • Get the latest driver source code release from Reiner's web site, at the time of writing the file is pcsc-cyberjack-3.99.5final.SP03.tar.gz.
  • Install needed packages
  • yum install gcc gcc-c++ libusb1-devel pcsc-lite-devel
  • Unpack the driver tarball
  • Edit the source file libcyberjack/checksuite/cm_distri.cpp to add #include <unistd.h> at line 22, otherwise the compile will fail with the error message error: ‘unlink’ was not declared in this scope
  • From within the top level directory of the unpacked and modified source run
    • ./configure && make
  • Then from the same directory run as root
    • mkdir -p /usr/lib64/pcsc/drivers/libifd-cyberjack.bundle/Contents/Linux
    • install -m 644 ifd/Info.plist /usr/lib64/pcsc/drivers/libifd-cyberjack.bundle/Contents
    • ./libtool --mode=install /usr/bin/install -c ifd/libifd-cyberjack.la '/usr/lib64/pcsc/drivers/libifd-cyberjack.bundle/Contents/Linux'
    • install -s tools/cyberjack/cyberjack /usr/local/bin/
  • Now make sure that pcscd is not running as a background service on your system then start it as root: pcscd -f -d
  • If it worked the reader should flash its LEDs and there should be lots of output to the terminal, with this somewhere in the middle
  • 00000011 hotplug_libudev.c:311:HPAddDevice() Adding USB device: REINER SCT cyberJack pp_a
    00000023 readerfactory.c:936:RFInitializeReader() Attempting startup of REINER SCT cyberJack pp_a (5745748205) 00 00 using /usr/lib64/pcsc/drivers/libifd-cyberjack.bund
    CYBERJACK: Started
    00000615 readerfactory.c:826:RFBindFunctions() Loading IFD Handler 3.0
    00006834 readerfactory.c:291:RFAddReader() Using the pcscd polling thread
    

2012-08-16

Processing HD DVR recordings

As it so happens, I own a DVR device that will record DVB-S and DVB-S2 TV into segments of a MPEG transport stream.

For DVB-S2 HD programs, the stream already contains h.264 compressed video. However since we don't live in the 80's anymore where there used to be a thing called VPS that would make sure your VCR starts and stops when the program does – even if that does not match the time printed in the program guide – the recording will be enclosed by parts of the surrounding broadcast.

Getting rid of that "garbage" is a bit tedious, but here's how I managed.

The receiver writes files 00001.ts, 00002.ts...00012.ts of one gigabyte each to the attached USB drive. So first turn that into one nice big file by using cat (the target better be ext4 or something else that can handle 2G+ files).
cat *.ts > <name>.ts
Now the problem is we can't just use a media player and seek to the cut points because the data in this transport stream is not properly timestamped.

But first we need to figure out which streams (tracks) are present in the raw material. Often broadcasters transmit a bunch of redundant audio streams. Just in a single language of course, apparently to make sure viewers are not getting too much value for their license fee.
$ ffprobe <name>.ts
[...]
    Stream #0:0[0x18a6]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x18b0](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16, 256 kb/s
    Stream #0:2[0x18b1](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16, 192 kb/s
    Stream #0:3[0x18b3](mul): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16, 192 kb/s
    Stream #0:4[0x18b2](deu): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, stereo, s16, 448 kb/s
    Stream #0:5[0x18ba](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
In this case, I'm only going to keep streams 0:0 (the h.264 video) and 0:4 (the AC3 audio). You can use mplayer with the -aid/-vid options to check out the various streams. To play the file with audio stream 0:3 for example, run as
mplayer -aid 0x18b2 <name>.ts
So now to get a seekable file with only the wanted streams, do this:
ffmpeg -i <name>.ts -f mpegts -c copy -bsf:v h264_mp4toannexb -map 0:0 -map 0:4 <intermediate>.mkv
Then open the file e.g. in gnome-mplayer, seek to the start and the end of  the actual content and make note of the timestamps.

Finally, fire up mmg (mkvmerge GUI), and add the freshly created <intermediate>.mkv file on the Input tab.
Then switch to the Global tab and enter the title of the recording into the File/segment title field.
Now check the Enable splitting... checkbox and select ...by parts.
Enter the begin/end timestamps noted down earlier into that field, separated by dash like 00:06:45-2:19:31.
Now verify that the Output filename is to your liking and hit the Start muxing button.