I hope that this article will help someone save time on customization. The article is designed for beginners, but I hope experienced users will find something useful. All actions were performed in linux mint, but I believe that everything will work on Ububntu and on other debian-like distributions.
So let's get started.
Initial setup
The TV tuner is installed, an antenna is inserted in it, an infrared sensor cord and an audio cable, the second end of which is in the audio card's line-in port. For viewing we will use the tvtime program.
sudo apt-get install tvtime
When installing, you will be asked for the broadcast standard and the frequency grid option. The standard for Russia is SECAM, and the frequency grid is Mozambique Russia.
During installation, a .tvtime directory is created in the user’s directory and is not accessible by the user. Therefore:
sudo chmod 7 ~/.tvtime/
You can run.
tvtime
The files tvtime.xml and stationlist.xml will be created in ~ / .tvtime.
If you saw the image from the TV and heard the sound, you are incredibly lucky. You can proceed to the next item.
If you see the image not from the tuner, but, for example, from a Web camera, add to the tvtime.xml file
<option name="V4LDevice" value="/dev/video1/>
and try to pick up the device number.
If you do not hear the sound (99% the way it is). Run
alsamixer
and turn up the volume on the line. If MM is under the slider, the line is disabled. Turn on - press the "M".

The sound should appear. If not, then it depends on the specific model of the sound card. Check from which channel the card takes Line-In (I have the Line-In and Rear Out variants). There may be other exotic chips associated with your equipment model. For example, integrated audio Via vt1828s has a parameter - loopback. So when he Enebled the sound from the TV tuner is on, but no sounds work any more (silent movies, and inaudible music). When disabled, the opposite is true.
We coped with the sound and to finally close the topic, add a line to tvtime.xml
<option name="MixerDevice" value="hw:0/Master"/>
She tells the program which channel to steer the volume. You can specify Line, and indeed any channel according to your taste. For channel names, see alsamixer. The case of letters matters.
You can add options to mute sound when exiting and on top of all windows.
<option name="MuteOnExit" value="1"/> <option name="AlwaysOnTop" value="1"/>
Channel Setup
Run:
tvtime-scanner -d /dev/video1 -n SECAM
Replace / dev / video1 with your device. If you use the services of a cable provider, then it can broadcast programs in the PAL standard. Nothing wrong with that. The channel will be found anyway. You can change the encoding for a specific channel later in the stationlist.xml file.
After scanning the channels, open the stationlist.xml, delete the extra channels, add if something was not found (but this is unlikely).
This is the line with the channel.
<station name="1" active="1" position="1" band="VHF Russia" channel="R1" finetune="0" norm="SECAM" audio="auto"/>
name - the name of the channel that will be displayed on the screen when switching. If the channel names are not only English letters, add xml to the ad encoding="UTF-8"
Otherwise, after running tvtime, the letters are converted to Unicode codes.
active - if 0, then it will be skipped when scrolling through channels
position - on which button the channel will sit.
The remaining parameters do not need to be changed manually.
')
TV program
The biggest advantage of a computer tuner compared to a regular TV is the ability to display the program guide on the screen. We switch the channel and see the advertisement, but we know WHAT will be right after it and make the sound louder, rather we flip further.

Tvtime can work with xmltv files and we will use this.
In tvtime.xml add.
<option name="XMLTVFile" value="~/.tvtime/xmltv.xml"/> <option name="XMLTVLanguage" value="ru"/>
Download and unpack the program.
cd ~/.tvtime wget http://www.teleguide.info/download/new3/xmltv.xml.gz gzip -f -d xmltv.xml.gz > xmltv.xml
Now you need to link the channels from xmltv.xml and stationlist.xml. Each channel in xmltv.xml has an id. We assign it to the xmltvid attribute in the stationlist.xml file like this:
<station name="" xmltvid="1" active="1" position="1" band="VHF Russia" channel="R1" finetune="0" norm="SECAM" audio="auto"/>
That's all. Now you can turn on the TV and enjoy the program guide on the screen. True, if you do not live in the Default city, the capital of our country, Moscow, then your joy will most likely be incomplete. Since the time of the actual broadcast will not coincide with the time in the program guide. And for different channels, the deviation in time will be different.
Fix this:
sed -i '/channel="1"/s/+0400/+0600/g' xmltv.xml
Initially, the xmltv.xml file contains a time zone of +4 hours (apparently from Greenwich), and we will do +6 hours. You need to execute a similar command for each channel.
Remote control
The most difficult and most time-consuming stage.
There are two ways to work with the remote control:
1. Via lirc,
2. As with the optional keyboard.
We will go the second way. Partially the remote should already work. There are digital keys and volume buttons. The remaining buttons are not.
The fact is that the console has already been defined by the system as a keyboard. Correspondence between scancodes and keycode keyboard is set at the kernel level.
The order of conversion of values ​​is as follows (I describe as I myself understood in amateurish language, corrections and clarifications are welcome):
1. The driver translates the scancode (physical signal) of the button into single-byte or multibyte keycode (key code) and sends it to “interested parties”.
2. The interested party, in our case, is the X server, which, depending on the model of the keyboard, determines how to interpret the received keycode. Those. Even the same code, but the server received from different models of devices X can be interpreted differently. This does not usually apply to alphanumeric characters and basic (such as arrows and enter) buttons. But the multimedia buttons that interest us are very much concerned.
There is another problem. The X server is capable of receiving only single-byte keycodes, and some buttons at the beholder console have a longer code. We will fix it. Install utilities:
sudo apt-get install ir-keytable input-utils
Read the current code table for the console:
sudo ir-keytable -r -d /dev/input/event`cat /proc/bus/input/devices | grep -3 "i2c-.*/.*/ir0" | grep "H:" | awk '{ sub(/event/, "", $3); print $3}'` >/etc/rc_keymaps/behold-key
Explanation for newbies. In fact, everything is not so scary. This line can be replaced by
sudo ir-keytable -r -d /dev/input/event5 > /etc/rc_keymaps/behold-key
and it will work just as well. You just need to know what kind of event your console is listed in the system. The rest of the scary line is just a calculation of the number. This command can read the code table of any keyboard connected to the computer.
A file / etc / rc_keymaps / behold-key appears with the current layout. It looks like this:
scancode 0x6b8600 = KEY_0 (0x0b) scancode 0x6b8601 = KEY_1 (0x02) scancode 0x6b8602 = KEY_2 (0x03) scancode 0x6b8603 = KEY_3 (0x04) scancode 0x6b8604 = KEY_4 (0x05) scancode 0x6b8605 = KEY_5 (0x06) scancode 0x6b8606 = KEY_6 (0x07) scancode 0x6b8607 = KEY_7 (0x08) scancode 0x6b8608 = KEY_8 (0x09) scancode 0x6b8609 = KEY_9 (0x0a) scancode 0x6b860a = KEY_AGAIN (0x81) scancode 0x6b860b = KEY_CHANNELUP (0x192) scancode 0x6b860c = KEY_VOLUMEUP (0x73) scancode 0x6b860d = KEY_INFO (0x166) scancode 0x6b860e = KEY_TEXT (0x184) scancode 0x6b860f = KEY_RECORD (0xa7) scancode 0x6b8610 = KEY_ZOOM (0x174) scancode 0x6b8611 = KEY_MUTE (0x71) scancode 0x6b8612 = KEY_POWER (0x74) scancode 0x6b8613 = KEY_GREEN (0x18f) scancode 0x6b8614 = KEY_SCREEN (0x177) scancode 0x6b8615 = KEY_CHANNELDOWN (0x193) scancode 0x6b8616 = KEY_OK (0x160) scancode 0x6b8617 = KEY_MODE (0x175) scancode 0x6b8618 = KEY_VOLUMEDOWN (0x72) scancode 0x6b8619 = KEY_BLUE (0x191) scancode 0x6b861a = KEY_STOP (0x80) scancode 0x6b861b = KEY_PLAYPAUSE (0xa4) scancode 0x6b861c = KEY_TUNER (0x182) scancode 0x6b861d = KEY_SLEEP (0x8e) scancode 0x6b861e = KEY_VIDEO (0x189) scancode 0x6b861f = KEY_RED (0x18e) scancode 0x6b8658 = KEY_SLOW (0x199) scancode 0x6b865c = KEY_CAMERA (0xd4)
We edit this file so that there are no multibyte codes and codes that the X server does not understand:
gksudo gedit /etc/rc_keymaps/behold-key
Write back:
ir-keytable -c -w /etc/rc_keymaps/behold-key -d /dev/input/event`cat /proc/bus/input/devices | grep -3 "i2c-.*/.*/ir0" | grep "H:" | awk '{ sub(/event/, "", $3); print $3}'`
We receive before reboot the console with a new code table. After rebooting everything will be as before. I do not know how to make the result remain forever, so the last command added the /etc/rc.local file to the autoload.
I give my edited behold-key file as an example:
scancode 0x6b861c = KEY_PROG1 (0x94) scancode 0x6b8612 = KEY_CLOSE (0xce) scancode 0x6b8600 = KEY_0 (0x0b) scancode 0x6b8601 = KEY_1 (0x02) scancode 0x6b8602 = KEY_2 (0x03) scancode 0x6b8603 = KEY_3 (0x04) scancode 0x6b8604 = KEY_4 (0x05) scancode 0x6b8605 = KEY_5 (0x06) scancode 0x6b8606 = KEY_6 (0x07) scancode 0x6b8607 = KEY_7 (0x08) scancode 0x6b8608 = KEY_8 (0x09) scancode 0x6b8609 = KEY_9 (0x0a) scancode 0x6b860a = KEY_PROG2 (0x95) scancode 0x6b8614 = KEY_PROG3 (0xca) scancode 0x6b8617 = KEY_SWITCHVIDEOMODE (0xe3) scancode 0x6b8610 = KEY_F11 (0x57) scancode 0x6b860b = KEY_UP (0x67) scancode 0x6b8615 = KEY_DOWN (0x6c) scancode 0x6b860c = KEY_RIGHT (0x6a) scancode 0x6b8618 = KEY_LEFT (0x69) scancode 0x6b8616 = KEY_ENTER (0x1c) scancode 0x6b8611 = KEY_MUTE (0x71) scancode 0x6b860d = KEY_KPEQUAL (0x75) scancode 0x6b860f = KEY_RECORD (0xa7) scancode 0x6b861b = KEY_PLAYPAUSE (0xa4) scancode 0x6b861a = KEY_STOPCD (0xa6) scancode 0x6b860e = KEY_PAUSECD (0xc9) scancode 0x6b861f = KEY_PREVIOUSSONG (0xa5) scancode 0x6b861e = KEY_NEXTSONG (0xa3) scancode 0x6b861d = KEY_MEDIA (0xe2) scancode 0x6b8613 = KEY_VOLUMEDOWN (0x72) scancode 0x6b8619 = KEY_VOLUMEUP (0x73) scancode 0x6b865c = KEY_CAMERA (0xd4) scancode 0x6b8658 = KEY_SPORT (0xdc)
Here are some codes that are normally taken by the X server (data obtained by the severe brute force method). I draw your attention that this is how codes are perceived from the remote beholder . From other keyboards, the code 0x94 may not be identified at all as KEY_PROG1.
KEY_CLOSE (0xce) KEY_EXIT (0xae) KEY_PROG1 (0x94) KEY_PROG2 (0x95) KEY_PROG3 (0xca) KEY_PROG4 (0xcb) KEY_POWER (0x74) KEY_VOLUMEDOWN (0x72) KEY_VOLUMEUP (0x73) KEY_NEXTSONG (0xa3) KEY_PLAYPAUSE (0xa4) KEY_PREVIOUSSONG (0xa5) KEY_STOPCD (0xa6) KEY_RECORD (0xa7) KEY_PLAYCD (0xc8) KEY_PAUSECD (0xc9) KEY_PLAY (0xcf) KEY_FASTFORWARD (0xd0) KEY_BASSBOOST (0xd1) KEY_CAMERA (0xd4) KEY_SOUND (0xd5) KEY_FINANCE (0xdb) KEY_SPORT (0xdc) KEY_SHOP (0xdd) KEY_ALTERASE (0xde) KEY_MEDIA (0xe2) KEY_VIDEO_NEXT (0xf1) KEY_VIDEO_PREV (0xf2) KEY_LINEFEED (0x65) KEY_MACRO (0x70) KEY_MIN_INTERESTING (0x71) KEY_KPEQUAL (0x75) KEY_KPPLUSMINUS (0x76) KEY_PAUSE (0x77) KEY_KPCOMMA (0x79) KEY_HANJA (0x7b) KEY_YEN (0x7c) KEY_STOP (0x80) KEY_AGAIN (0x81) KEY_PROPS (0x82) KEY_UNDO (0x83) KEY_FRONT (0x84) KEY_COPY (0x85) KEY_OPEN (0x86) KEY_PASTE (0x87) KEY_CUT (0x89) KEY_FIND (0x88) KEY_MENU (0x8b) KEY_CALC (0x8c) KEY_SETUP (0x8d) KEY_WAKEUP (0x8f) KEY_FILE (0x90) KEY_SENDFILE (0x91) KEY_DELETEFILE (0x92) KEY_XFER (0x93) KEY_WWW (0x96) KEY_MSDOS (0x97) KEY_DIRECTION (0x99) KEY_CYCLEWINDOWS (0x9a) KEY_MAIL (0x9b) KEY_BOOKMARKS (0x9c) KEY_COMPUTER (0x9d) KEY_BACK (0x9e) KEY_FORWARD (0x9f) KEY_CLOSECD (0xa0) KEY_EJECTCD (0xa1) KEY_EJECTCLOSECD (0xa2) KEY_REWIND (0xa8) KEY_PHONE (0xa9) KEY_ISO (0xaa) KEY_CONFIG (0xab) KEY_REFRESH (0xad) KEY_EDIT (0xb0) KEY_SCROLLUP (0xb1) KEY_SCROLLDOWN (0xb2) KEY_NEW (0xb5) KEY_REDO (0xb6) KEY_HOMEPAGE (0xac)111 KEY_DASHBOARD (0xcc) KEY_HP (0xd3) KEY_QUESTION (0xd6) KEY_EMAIL (0xd7) KEY_CHAT (0xd8) KEY_CONNECT (0xda) KEY_SEARCH (0xd9) KEY_CANCEL (0xdf) KEY_BRIGHTNESSDOWN (0xe0) KEY_BRIGHTNESSUP (0xe1) KEY_SWITCHVIDEOMODE (0xe3) KEY_KBDILLUMTOGGLE (0xe4) KEY_KBDILLUMDOWN (0xe5) KEY_KBDILLUMUP (0xe6) KEY_SEND (0xe7) KEY_REPLY (0xe8) KEY_FORWARDMAIL (0xe9) KEY_SAVE (0xea) KEY_DOCUMENTS (0xeb) KEY_WLAN (0xee) KEY_UWB (0xef) KEY_BRIGHTNESS_CYCLE (0xf3) KEY_BRIGHTNESS_ZERO (0xf4) KEY_DISPLAY_OFF (0xf5) KEY_WIMAX (0xf6) KEY_RFKILL (0xf7)
When working on setting up the remote control buttons, it is convenient to use the following monitoring method. Run
sudo input-events -t60 5
Where 60 is the wait time for pressing in seconds, 5 is the number of the keyboard in the system. And press the buttons on the remote.
Extradition has approximately the following form.
00:56:27.954276: EV_MSC MSC_SCAN 7046683 00:56:27.954281: EV_KEY KEY_PLAYPAUSE (0xa4) pressed 00:56:27.954281: EV_SYN code=0 value=0 00:56:28.062206: EV_MSC MSC_SCAN 7046683 00:56:28.062207: EV_SYN code=0 value=0 00:56:28.314253: EV_KEY KEY_PLAYPAUSE (0xa4) released 00:56:28.314254: EV_SYN code=0 value=0
The output occurs when you press and when you release the button.
7046683 is the physical scan code of the remote control button in the decimal system. It will be displayed in any case.
(0xa4) - the keycode that the driver sent on. If its length is not equal to one byte, then X server will not see it.
KEY_PLAYPAUSE is the name of the button. If there is no name, then the button cannot be hung on this button. Change the keikod.
Finishing touches
We got the remote perceived by the system as an additional keyboard with multimedia keys. It remains to configure the system response to pressing. The loudness and channel switching at tvtime already work, since the cross buttons are configured as arrows and Enter.
Go to the keyboard settings and set the play keys that will work in most players.

On the rest of the buttons set up additional commands.
I assigned the F11 key to the FullScreen key of the console. This key is understood by most programs as a transition to full-screen mode and back, but not tvtime. Therefore, we add to the tvtime.xml file
<bind command="toggle_fullscreen"> <keyboard key="F11"/> </bind>
Unfortunately, tvtime does not understand multimedia keys, therefore, it is impossible to set an action to press KEY_SWITCHVIDEOMODE. But for this there is another way.
In the additional commands section of the keyboard settings, we set
tvtime-command TOGGLE_ASPECT
For a complete list of tvtime commands, see the documentation.
If you need a button to close the active window, install:
sudo apt-get wmctrl
And add additional command:
wmctrl -c :ACTIVE:
That's all. I will be glad to corrections and clarifications. If the topic is interesting, then it will be possible to explore the issue of setting up the MythTV media combine in a multi-tuner configuration with network clients. By the way, MythTV has frontends for android. You can watch on- air TV from a tablet or a smart ... tempting ?!