Thursday, July 26, 2012

Getting DVB-C to work well

Anysee E7TC and Windows, the horror...

I bought the Anysee E7TC Plus some time ago because I wanted to record some programs from DVB-C. Since the Anysee was one of the few cards which works for a lot of people having Ziggo (Netherlands) as A cable company I bought one as well. The nice thing about this card is that it has a softcam so I could insert the smartcard (which is needed for all Dutch cable companies if you want digital television) directly and should work on Windows quite well. 

Well my experience was different, I tried three different drivers to get all channels working on Windows 7 and when I finally got all the channels working I found out that the recording software was really unstable. I tried several alternatives like MediaPortal and ForTheRecord. ForTheRecord was actually quite nice but I couldn't get the smartcard reader to work. 

Using the Anysee on Linux, with a separate cardreader

I gave up on Windows and read if the card was supported in Linux, luckily it was. Only the SoftCam was not supported (yet?) so I bought a generic cardreader by the name of Smargo SmartReader Pro. It costs around EUR 30,-. I set it up with OSCam, there are enough tutorials around to help you out but I found out that installation is quite a trial-and-error process. If someone is interested in my configuration just ask me and I will post it here. 


Then I had to decide which program to use, I already used TVHeadend in a IPTV environment. The only alternative I heard/read about for Linux was MythTV. It didn't have to be working really quick so I decided to make a temporary switch to MythTV in the IPTV environment to try it out. 

The setup was quite a pain. The server I used it on was headless and the configuration program needed X to configure. The only solution for me was to use X11 forwarding over SSH. It was a disaster. Slow as hell and not very intuitive but after three hours I finally managed to get it working.

I used MythWeb as frontend, this was quite nice. It offers a lot of options and does not look bad. The problem is it ate a lot of resources and after a while it just hangs after a recording. I didn't optimize the MySQL database behind it but I think that should not be needed for something like this.


So back to tvheadend it was then. The webinterface is not perfect but good enough for simple recording  and TV watching. The light footprint of tvheadend makes up for the sometimes in-intuitive way of setting up things. For example in the IPTV environment I had to add each channel one-by-one by hand.

I think tvheadend is more focussed on using it in DVB-C/T/S environments since this part is more user-friendly. They already provide some muxes for a lot of DVB providers in different countries. The Dutch companies like Ziggo and UPC add a lot of channels lately so it didn't surprise me the muxlist was incomplete.
Tvheadend does have an option for automatically finding frequencies (muxes) but that didn't work very well for me. I found a frequency list on the Gathering of Tweakers-forum which I used to add the multiplexes by hand. This worked quite well, sometimes I had to re-add muxes to get all the channels but after a while I got all channels. The EPG worked automatically (I was used to needing a separate XMLTV source). Connecting tvheadend and OSCam was really easy and worked directly. 

Problem frequency

Problems arose when I wanted to record something from channels on the frequency 626,750 MHz, this was a frequency I also had problems with on Windows. After checking the DVB-C signal which showed excellent signal quality on other devices on the same outlet I came to the conclusion I had to get another card.

Getting another card, the Terratec Cinergy T Dual PCIe

Since I already got stuff working without using the built-in cardreader I decided to go for a card without cardreader. I also wanted to be able to record two programs at the same time so I looked on the LinuxTV wiki which dual-tuner was supported and not too expensive. I decided to go with the Terratec Cinergy T Dual PCIe. A card almost at 1/3rd of the price of the Anysee E7. The wiki stated that it was supported in the LinuxTV drivers somewhere in 2011 or that I needed to use a recent kernel (3.3 or 3.4), since I have gained quite some *nix experience both would not be a problem for me.

Installing the kernel was the hardest part, initramfs gave me some problems but after those where solved and booted into 3.4.7 it worked directly in tvheadend. Also the 626,750 MHz channels now work without any problems, so it turned out the Anysee card was indeed the problem.

I also solved the problem of the not-so-intuitive interface of tvheadend by using XBMC PVR and it's TV add-on. It's like a match made in heaven ;) I will post some screenshots later

Monday, July 23, 2012

ffmpeg filters, PTS timestamps and mencoder

Well, today I learned a lot more from ffmpeg and video formats and it's encoding in general.

First of all, i'm really happy with the filters it provides.

The drawtext allows you to burn timestamps in your video. I used it to burn it into my scene detection mosaic (see post below) so I can see at which time the scene changes.

The showinfo filter shows you some detailed frame information, first I was wondering why the (PTS) timestamps didn't match with the timestamps in my mosaic, but then (after a few hours) I discovered that the PTS timestamps are relative and can be changed to zero-baed with the "setpts" video filter.

The command I use to get a nice timestamped mosaic with scene changes and a log file that can be parsed to create a chapters file is:

ffmpeg -i $INPUT -vf drawtext="fontfile='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf':timecode='00\\:00\\:00\\:00':rate=25:fontsize=72:fontcolor=white@0.8: x=0: y=0",select='gt(scene\,0.5)',scale=160:120,showinfo,tile=10x16 -s 1920x1200 -frames:v 1 $OUTPUT 1> output.txt 2>&1

The problem is that there is no audio-filter which modifies the audio "frame" pts, so the audio-track is out-of-sync. There was a patch proposed in the mailinglist some time go but was declined because it share some code with the video-pts-set filter.

Then I found out that mencoder also does things like ffmpeg, so I simply tried to copy the audio and video stream and apparently the PTS timestamps are reset. There are a lot of issues though.

Apparently the mencoder libavformat muxing is broken for a looong time (I see mailinglist messages dated from 2008 with the same message), so now I try repacking it with ffmpeg or just get separate tracks and merge them together with ffmpeg.

ffmpeg scene detection and how to use it

I needed scene detection and since I am using ffmpeg to convert my home movies it would be handy to also use ffmpeg for that.

I found out that it was recently added here:

The related commit I found here:;h=72868144e5862168a4f829557b7a41f686b8b12d

which also included some instructions on how to use it:

2644 Complete example to create a mosaic of the first scenes:
2646 @example
2647 ffmpeg -i video.avi -vf select='gt(scene\,0.4)',scale=160:120,tile -frames:v 1 preview.png
2648 @end example

Luckily I built directly from source yesterday and should been able to use this new functionality right away. Unfortunately I get this error:

Assertion ref->buf->refcount > 0 failed at libavfilter/buffer.c:147

I don't know how to fix that yet.
UPDATE: Apparently, this is because the amount of tiles are to much for the mosaic which apparently has a standard size based on the tile-size, also my recordings were very "dirty" (some of them DVB-recordings). First converting them to MKV fixed the latter issue.

Please note that this is very new functionality and I do not recommend to use this in production.

Related links: