Project

General

Profile

Script for analog V4L2 device support in TVH (via pipe:// mux)

Added by Diego Rivera almost 9 years ago

Hi, all!

In my setup, I have need to tune analog channels via Kodi/TVH, which is currently not supported in TVHeadEnd. My solution was to make use of the pipe:// mux capability, and the attached script. The script supports indicating multiple sources, and round-robins through them until it's able to lock one (using flock). Once that's done, it then launches VLC command-line for streaming the output. I tried to use ffmpeg (and indeed the command is commented out in the script), but stream synchronization issues proved challenging, and I didn't know how to address them.

This script however requires the presence of VLC (cvlc, really) and IPTV. Here are the setup steps

  1. Make sure VLC is installed, and cvlc is in the path
  2. Make sure ivtv-utils is installed, and ivtv-tune is in the path
  3. Make sure the script is in the path, and works fine from the command-line (instructions below)
  4. Define a new IPTV Network in which the muxes would live for each channel I wished to support (this will be improved upon later, for now bear with me)
  5. Define a new MUX for each channel on that network, with the URL being of the pipe:// variety, and triggering the invocation of the script (with -o - for stdout output). Let the MUX "scan"
    • Here's the line from my setup: pipe://capture-analog -c <channel> -s /dev/video1 -o -
  6. Once each MUX has been scanned, its named service should appear on the "Services" tab - simply map each service to its (set of) channels like you normally would
    • If the services don't appear, then check the TVH logs - it's likely the script isn't on the path, or there's a typo somewhere. Simply fix it, then set the MUX's scan status to "PEND" (editing the MUX), and it'll re-attempt the scan. Once the scan is successful, the service will show up.
  7. Voliá! You're done!

The attached script uses simple round-robin logic to iterate over whatever devices are available until one is successfully "_acquired_" (i.e. locked via flock). Once that happens, then that device will be tuned to the given channel, and its output will be written out to wherever the "-o" option (see below) points, encoded to an MPEGTS stream (MPEG2/AC3/TS).

The script can use a configuration file in /etc/default/capture-analog.conf. Please note that if you decide to name the script something else, that configuration file's name must also match the script's new name (i.e. ${scriptName}.conf), but must always reside in /etc/default. In the configurations, a single SOURCES="" line is supported, where you may specify which devices (i.e. /dev/video0, /dev/video1, etc.) the script will use by default (can be separated by commas or spaces). The devices will be tried in order. The script will not try the same device twice.

Finally, if no "SOURCES" line is present, or its contents are empty (all-spaces, etc.), then devices will be discovered via find command (specifically, find /dev/video* -type c).

The script itself accepts the following command-line arguments:

  • -s devices: the list of devices to consider as candidates (same syntax as SOURCES, above. Comma-separated so be mindful of that)
    • This overrides the value from the configuration file
  • -c channel: the channel to which you wish to tune (mutually exclusive with -f)
  • -t table: the tuning table to use (not used if -f is in use)
  • -f frequency: the frequency to which you wish to tune (mutually exclusive with -c)
  • -o output: the file to which output will be written (use - for stdout, this is what TVH needs, the default is stdout)
  • -g: enable trace mode, showing every instruction as it's executed
  • -h: help message
  • -?: help message

Interestingly, this script can also be used to display the feed from cameras (as long as they're V4L2 devices as /dev/video*), simply point it at the device and don't include tuning information (-c/-t, or -f).

Hope this works! And thanks to the TVH team for all the great work on TVHeadEnd!!

capture-analog (6.53 KB) capture-analog Script to capture from analog tuners and V4L2 devices

Replies (45)

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera almost 9 years ago

Oops... the original script has a bug with service discovery. Here's the updated version.

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera almost 9 years ago

Updated version with alternate ffmpeg support (-E ffmpeg, or -E vlc...the default is still vlc), and much more robust overall.

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 almost 9 years ago

Hi

Thank you for this script.

I tried to use it within Tvheadend, but I'll get ivtv-tune is not installed.
I also tried to add PATH=/directory to ivtv-tune/ in tvheadend under prefix with same result.
I checked with $echo PATH on the user that runs tvheadend and I can run the command / script from shell without hardcoded path to ivtv-tune.
ivtv-utils is replaced by v4l2-utils in my running distro, I had to compile it manually.
Where do it look for ivtv-tune in user path?

Could you possible add support for 'scantv' package? or use v4l2-ctl to set freq/channel?

Thank you
Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera almost 9 years ago

This is an updated script, much improved after more use and with the option to use ffmpeg as the playback engine instead of vlc. It doesn't address your concerns, though. I'll look into those over the weekend.

You're right about using v4l2-ctl for tuning as that would be more "standard", but then again the problem with tuning channels is mapping the channel to a frequency, and that's where ivtv comes in as it does both (can tune directly by channel number, or use it to map the channel to a frequency).

What distro are you running? Is an ivtv-utils package not already available? That would be easier than compiling yourself. As for putting "ivtv-tune" in the path, just put it in /usr/bin (you'll have to do so as root). Just check the user's PATH variable for the list of directories where you may put it - /usr/bin should be near the top (usually).

Hope this clarifies. I'll look into using only v4l2 tools for the tuning and whatnot, but it's the channel tables that are the sticking point so I'm not sure how successful I'll be. If it ends up that I still need to use ivtv to do the channel mapping, then it makes no sense to stop using it for the tuning as it won't save me anything.

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

Have either of you any updates on this, I have the same issue as Nicklas in that ivtv-utils is not available on Debian (Raspbian)

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

Here's the latest version of the script, fully supporting all V4L2 devices I'm able to test with (an MPEG-encoding PVRUSB2 device in the Hauppauge HVR-1950, and a raw-encoding device in the Hauppauge HVR-950Q).

IVTV isn't installed by default, but I can tell you right now it can definitely be installed as I have it on one of my RPi units (with which I tested the script precisely for compatiblity with RPi). So that's your solution - install the v4l-utils package from the Debian repositories. To do that:

  1. Create a file called /etc/apt/sources.list.d/debian-contrib.list, with the following contents (pointing to the contrib branch of Debian packages):
    deb http://httpredir.debian.org/debian wheezy contrib
    #deb-src http://httpredir.debian.org/debian wheezy contrib
    deb http://httpredir.debian.org/debian wheezy-updates contrib
    #deb-src http://httpredir.debian.org/debian wheezy-updates contrib
    
  2. Import the Debian repository signing keys with this command:
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7638D0442B90D010 8B48AD6246925553 6FB2A1C265FFB764
    
  3. Install the ivtv-utils package
    sudo apt-get update
    sudo apt-get install ivtv-utils
    

And that should do it. The IVTV-Utils are in the contrib branch, which as I recall is disabled by default. It's possible that the contrib branch is already referenced in some other APT list file (either /etc/apt/sources.list or some other file in /etc/apt/sources.list.d), but simply commented out. That would explain why you were unable to install ivtv-utils.

Hope this helps!

Cheers!

capture-analog (11 KB) capture-analog Latest version of the script

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

Hello!

Thanks, I got ivtv-utils working on jessie release on raspberry pi.

With dependencies libc6, libstdc++6, perl, licconfig-inifiles-perl, libvideo-ivtv-perl, libvideo-capture-v4l-perl, v4l-utils
However the ivtv-utils did not work from backports (jessie backports) I compiled source and put bin files in /usr/bin/

However, when I run the script from tvheadend it can't detect channel.

Log >

Loglevel debug: enabled
2016-03-06 16:38:43.586 mpegts: in Analog-TV - tuning on IPTV
2016-03-06 16:38:43.606 spawn: Executing "/home/tvheadend/capture-analog"
2016-03-06 16:38:43.611 subscription: 000C: "scan" subscribing to mux "", weight: 6, adapter: "IPTV", network: "Analog-TV", service: "Raw PID Subscription"
2016-03-06 16:38:43.769 spawn: SOURCES=[/dev/video0]
2016-03-06 16:38:43.843 spawn: Will tune to channel [7] (table=default)
2016-03-06 16:38:43.924 spawn: Begin capture from /dev/video0 (TUNER=true)
2016-03-06 16:38:44.003 spawn: ffmpeg version N-78927-gf3c00be Copyright (c) 2000-2016 the FFmpeg developers
2016-03-06 16:38:44.007 spawn: built with gcc 4.9.2 (Raspbian 4.9.2-10)
2016-03-06 16:38:44.008 spawn: configuration: --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
2016-03-06 16:38:44.013 spawn: libavutil 55. 19.100 / 55. 19.100
2016-03-06 16:38:44.013 spawn: libavcodec 57. 27.101 / 57. 27.101
2016-03-06 16:38:44.014 spawn: libavformat 57. 28.100 / 57. 28.100
2016-03-06 16:38:44.014 spawn: libavdevice 57. 0.101 / 57. 0.101
2016-03-06 16:38:44.015 spawn: libavfilter 6. 39.100 / 6. 39.100
2016-03-06 16:38:44.020 spawn: libswscale 4. 0.100 / 4. 0.100
2016-03-06 16:38:44.021 spawn: libswresample 2. 0.101 / 2. 0.101
2016-03-06 16:38:44.021 spawn: libpostproc 54. 0.100 / 54. 0.100
2016-03-06 16:38:48.000 mpegts: in Analog-TV - scan no data, failed
2016-03-06 16:38:48.000 subscription: 000C: "scan" unsubscribing

If I run it from CLI (shell) It works.

Log >

$ ./capture-analog -c 7 -s /dev/video0 -o 3.mpg
SOURCES=[/dev/video0]
Will tune to channel [7] (table=default)
Begin capture from /dev/video0 (TUNER=true)
/dev/video0: 175.250 MHz (Signal Detected)
ffmpeg version N-78927-gf3c00be Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 27.101 / 57. 27.101
libavformat 57. 28.100 / 57. 28.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 39.100 / 6. 39.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mpeg, from 'pipe:///dev/stdin':
Duration: N/A, start: 0.156089, bitrate: N/A
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 720x576 [SAR 16:15 DAR 4:3], max. 8000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 224 kb/s
Output #0, mpegts, to '3.mpg':
Metadata:
encoder : Lavf57.28.100
Stream #0:0: Video: mpeg2video, yuv420p, 720x576 [SAR 16:15 DAR 4:3], q=2-31, max. 8000 kb/s, 25 fps, 25 tbr, 90k tbn, 90k tbc
Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
Metadata:
encoder : Lavc57.27.101 ac3
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (mp2 (native) -> ac3 (native))
frame= 206 fps= 65 q=-1.0 size= 6780kB time=00:00:08.32 bitrate=6671.8kbits/s speed=2.63x

I tried with the -E vlc flag but it loads ffmpeg.

Any ideas?

Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

The fact that it works from command line suggests that the issue is with the pipe:// URL you configured the mux with. Double check that and make sure it matches your command-line version (without the -o flag, since for pipe:// you want the output to go to stdout).

I think I removed VLC support since it was unnecessary. Did you check to see if the captured file (3.mpg) was actual video from the TV channel you're trying to capture?

Also, you may need to double-check that the channels table in use is the correct one for your provider. The default is "us-cable". You can find the list of available tables with ivtv-tune -L, and tell the script which one to use with the -t flag. The script does no channel scanning of its own, and simply tunes based off of ivtv's tables and whatever you tell it to tune into.

Cheers!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

Importantly, ${service_name} is broken in all current stable versions, so even though the docs say you can use it, don't. That could also be a source of trouble.

Cheers!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

Hello!

Got it working with tvheadend 4.0.8.
I did changes in (.ivtv-tune)

device /dev/video0
freqtable europe-west

Is it possible to add support for 'character'?
Example, the europe-west have channel named E8, SE10 etc.

Thank you.

Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

I managed to install ivtv using the instructions you have provided, then I compiled & installed FFMPEG

Now when running the script (in the CLI shell initially just to check its working) I get the following error:

./capture-analog -c 68 -s /dev/video0 -o 3.mpg
SOURCES=[/dev/video0]
Will tune to channel [68] (table=default)
Begin capture from /dev/video0 (VBI=none AUDIO=hw:1,0 TUNER=true)
Querying audio capabilities for [hw:1,0]...
/dev/video0: 487.250 MHz
+ /usr/local/bin/ffmpeg -r 30000/1001 -f v4l2 -i /dev/video0 -f alsa -ac 2 -ar 48000 -i hw:1,0 -f mpegts -c:v mpeg2video -b:v 8000k -filter:v yadif=0:-1:0 -c:a ac3 -b:a 224k -y 3.mpg
ffmpeg version N-78958-g8c24523 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration:
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 28.100 / 57. 28.100
libavformat 57. 28.100 / 57. 28.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 39.102 / 6. 39.102
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
[video4linux2,v4l2 @ 0x2570330] The driver does not permit changing the time per frame
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 10572.298594, bitrate: 165722 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Unknown input format: 'alsa'
+ set +x

Any pointers or ideas?

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

Hello

What device are you using?
Does it have a MPEG2 encoder?
I use a USB WinTV HVR-1900 Model 73xxx.
I'm not sure about your ffmpeg output but it does not seem like a mpeg2 stream.
This is my ./configure with ffmpeg with Raspbian
--arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree

Could you install mplayer and try

mplayer /dev/video0

Playing /dev/video0.
Detected file format: MPEG-PS (MPEG-2 Program Stream) (libavformat)

Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

Diego Rivera wrote:

Importantly, ${service_name} is broken in all current stable versions, so even though the docs say you can use it, don't. That could also be a source of trouble.

Cheers!

Hello!

Works now, I modify the regex on channel name, I can now use all my analog channels.
Finally one tvheadend server with analog and DVB channels.

Thank you for your work with this script.

Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

Is it possible to add support for 'character'?
Example, the europe-west have channel named E8, SE10 etc.

Sadly, no - this is extremely network specific so you'd have to come up with your own mapping mechanism.

Glad to see you got it running!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

David Blackeby wrote:

I managed to install ivtv using the instructions you have provided, then I compiled & installed FFMPEG

Now when running the script (in the CLI shell initially just to check its working) I get the following error:

./capture-analog -c 68 -s /dev/video0 -o 3.mpg
SOURCES=[/dev/video0]
Will tune to channel [68] (table=default)
Begin capture from /dev/video0 (VBI=none AUDIO=hw:1,0 TUNER=true)
Querying audio capabilities for [hw:1,0]...
/dev/video0: 487.250 MHz
+ /usr/local/bin/ffmpeg -r 30000/1001 -f v4l2 -i /dev/video0 -f alsa -ac 2 -ar 48000 -i hw:1,0 -f mpegts -c:v mpeg2video -b:v 8000k -filter:v yadif=0:-1:0 -c:a ac3 -b:a 224k -y 3.mpg
ffmpeg version N-78958-g8c24523 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration:
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 28.100 / 57. 28.100
libavformat 57. 28.100 / 57. 28.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 39.102 / 6. 39.102
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
[video4linux2,v4l2 @ 0x2570330] The driver does not permit changing the time per frame
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 10572.298594, bitrate: 165722 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Unknown input format: 'alsa'
+ set +x

Any pointers or ideas?

It looks as if your ffmpeg version doesn't support input from ALSA (the Linux sound layer). Instead of rolling your own (uninstall it), why don't you try the one from https://launchpad.net/~mc3man/+archive/ubuntu/ffmpeg-test1 ? That's the one I'm using and I'm certain it works perfectly.

If not, I can certainly help you out to find the issue.

Cheers!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

OK I'm failing miserably here... Doesn't help that I'm pretty new to all of this

I tried to install mplayer using apt-get install mplayer, however on Jessie it installs mplayer2 instead as its a "newer" version

If I then run the command, initially it complains about a lack of input.conf, then I get the following message

root@RPi-TVHE:/etc# mplayer /dev/video0
MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
Cannot open file '/root/.mplayer/input.conf': No such file or directory
Failed to open /root/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.

Playing /dev/video0.
Cannot seek backward in linear streams!
Seek failed
Cannot seek backward in linear streams!
Seek failed
Cannot seek backward in linear streams!
Seek failed
....

My TV card is a WinTV HVR-900H / WinTV USB2-Stick

The following is from the dmesg
[ 5.136949] tm6000: Found Hauppauge WinTV HVR-900H / WinTV USB2-Stick
....
....
[ 5.932309] tuner 3-0061: Tuner -1 found with type(s) Radio TV.
[ 5.948722] xc2028 3-0061: creating new instance
[ 5.948749] xc2028 3-0061: type set to XCeive xc2028/xc3028 tuner
[ 5.948762] Setting firmware parameters for xc2028
[ 5.954262] tm6000 #0: registered device video0
[ 5.954286] Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: 0)
[ 5.955917] xc2028 3-0061: Loading 81 firmware images from xc3028L-v36.fw, type: xc2028 firmware, ver 3.6
[ 6.133125] Registered IR keymap rc-hauppauge
[ 6.133855] input: tm5600/60x0 IR (tm6000 #0) as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/rc/rc0/input0
[ 6.133902] rc0: tm5600/60x0 IR (tm6000 #0) as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/rc/rc0
[ 6.276940] usbcore: registered new interface driver tm6000
[ 6.284466] tm6000 #0: Initialized (TM6000 Audio Extension) extension
[ 6.322101] DVB: registering new adapter (Trident TVMaster 6000 DVB-T)
[ 6.322168] usb 1-1.5: DVB: registering adapter 0 frontend 0 (Zarlink ZL10353 DVB-T)...
[ 6.322611] xc2028 3-0061: attaching existing instance
[ 6.322630] xc2028 3-0061: type set to XCeive xc2028/xc3028 tuner
[ 6.322642] tm6000: XC2028/3028 asked to be attached to frontend!
[ 6.323318] tm6000 #0: Initialized (TM6000 dvb Extension) extension
[ 6.533146] xc2028 3-0061: Loading firmware for type=BASE (1), id 0000000000000000.
[ 10.515414] xc2028 3-0061: Loading firmware for type=(0), id 000000000000b700.
[ 10.585257] SCODE (20000000), id 000000000000b700:
[ 10.585285] xc2028 3-0061: Loading SCODE for type=MONO SCODE HAS_IF_4320 (60008000), id 0000000000008000.

Given I've probably made a mess of my configuration, I'm tempted to start a fresh.

Do you have a source / location for the install of FFMPEG and other required packages you have used (I compiled mine, following an online guide, however not sure whether the configuration settings might be causing issues.)

I'm beginning to wish I took some notes now... ;-)

Anyhow thanks for any pointers you can provide, much appreciated.

fa1 fa1 wrote:

Hello

What device are you using?
Does it have a MPEG2 encoder?
I use a USB WinTV HVR-1900 Model 73xxx.
I'm not sure about your ffmpeg output but it does not seem like a mpeg2 stream.
This is my ./configure with ffmpeg with Raspbian
--arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree

Could you install mplayer and try

mplayer /dev/video0

Playing /dev/video0.
Detected file format: MPEG-PS (MPEG-2 Program Stream) (libavformat)

Regards
fa1

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

Could you do from shell

v4l2-ctl --list-devices --verbose

v4l2-ctl --all

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

His problem is that his ffmpeg version doens't support ALSA capture. This is likely a missing flag during compilation. Two choices: find a pre-compiled ffmpeg package for Jessie (perhaps try one for Ubuntu Wily?), or re-compile enabling ALSA capture support.

You can probably do a configure --help or configure --? (one of the two will work).

For curiosity: what was the configure command you used to build FFMPEG?

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

v4l2-ctl --list-devices --verbose
Trident TVMaster TM5600/6000/60 (usb-3f980000.usb-1.5):
/dev/video0

VIDIOC_QUERYCAP: ok

v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : tm6000
Card type : Trident TVMaster TM5600/6000/60
Bus info : usb-3f980000.usb-1.5
Driver version: 4.1.13
Capabilities : 0x85250001
Video Capture
Tuner
Radio
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x05210001
Video Capture
Tuner
Read/Write
Streaming
Extended Pix Format
Priority: 2
Frequency for tuner 0: 2804 (175.250000 MHz)
Tuner 0:
Name : Television
Capabilities : 62.5 kHz multi-standard stereo freq-bands
Frequency range : 44.000 MHz - 958.000 MHz
Signal strength/AFC : 0%/0
Current audio mode : mono
Available subchannels: stereo
Video input : 0 (Television: ok)
Video Standard = 0x00001000
NTSC-M
Format Video Capture:
Width/Height : 720/480
Pixel Format : 'YUYV'
Field : Interlaced
Bytes per Line: 1440
Size Image : 691200
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Flags :
Streaming Parameters Video Capture:
Frames per second: 29.970 (30000/1001)
Read buffers : 2

User Controls

brightness (int)    : min=0 max=255 step=1 default=54 value=54 flags=slider
contrast (int) : min=0 max=255 step=1 default=119 value=119 flags=slider
saturation (int) : min=0 max=255 step=1 default=112 value=112 flags=slider
hue (int) : min=-128 max=127 step=1 default=0 value=0 flags=slider
volume (int) : min=-15 max=15 step=1 default=0 value=0 flags=slider
mute (bool) : default=0 value=0
brightness (int) : min=0 max=255 step=1 default=54 value=54 flags=slider
contrast (int) : min=0 max=255 step=1 default=119 value=119 flags=slider
saturation (int) : min=0 max=255 step=1 default=112 value=112 flags=slider
hue (int) : min=-128 max=127 step=1 default=0 value=0 flags=slider
volume (int) : min=-15 max=15 step=1 default=0 value=0 flags=slider
mute (bool) : default=0 value=0

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

Try this:

  1. Uninstall the FFMPEG instance you previously installed (I think make uninstall can do the trick)
  2. Create a file called /etc/apt/sources.list.d/deb-multimedia.list, with the following contents:
    deb http://www.deb-multimedia.org jessie main non-free
    #deb-src http://www.deb-multimedia.org jessie main non-free
    
  3. Import the GPG keys for that repository
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 5C808C2B65558117 CBF8D6FD518E17E1
    
  4. Install FFMPEG
    sudo apt-get update
    sudo apt-get install ffmpeg
    

Try the script again :)

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

Great that seemed to do the job, and now I can capture a local MPG (albeit tuned to garbage)

I'm trying to capture UHF C68 in the UK (which is tuned to my Sky TV Box), I believe this should be frequency 850.0 Mhz (based on information found here https://ukfree.tv/maps/uhfchannel/68)

I notice from the logs when the scripts run that its actually trying to capture 487.250 Mhz:

./capture-analog -c 68 -s /dev/video0 -o sky.mpg
SOURCES=[/dev/video0]
Will tune to channel [68] (table=default)
Begin capture from /dev/video0 (VBI=none AUDIO=hw:1,0 TUNER=true)
Querying audio capabilities for [hw:1,0]...
/dev/video0: 487.250 MHz
+ /usr/bin/ffmpeg -r 30000/1001 -f v4l2 -i /dev/video0 -f alsa -ac 2 -ar 48000 -i hw:1,0 -f mpegts -c:v mpeg2video -b:v 8000k -filter:v yadif=0:-1:0 -c:a ac3 -b:a 224k -y sky.mpg
ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/arm-linux-gnueabihf --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2 --enable-libvidstab --enable-libzvbi --enable-avresample --disable-htmlpages --disable-podpages --enable-libutvideo --enable-libfdk-aac --enable-libx265 --enable-libiec61883 --enable-libdc1394 --disable-altivec --shlibdir=/usr/lib/arm-linux-gnueabihf
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
[video4linux2,v4l2 0x1b9c960] The driver does not permit changing the time per frame
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 68879.289732, bitrate: 165722 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, alsa, from 'hw:1,0':
Duration: N/A, start: 1457603064.392267, bitrate: 1536 kb/s
Stream #1:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
No pixel format specified, yuv422p for MPEG-2 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
Output #0, mpegts, to 'sky.mpg':
Metadata:
encoder : Lavf56.25.101
Stream #0:0: Video: mpeg2video, yuv422p, 720x480, q=2-31, 8000 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
Metadata:
encoder : Lavc56.26.100 mpeg2video
Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
Metadata:
encoder : Lavc56.26.100 ac3
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> ac3 (native))
Press [q] to stop, [?] for help
[alsa
0x1b9dce0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[video4linux2,v4l2 @ 0x1b9c960] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame= 135 fps= 12 q=24.8 Lsize= 11656kB time=00:00:04.48 bitrate=21267.7kbits/s
video:10765kB audio:28kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.992982%
Received signal 2: terminating.
+ set +x

So I figured I would try the -f command line to specify a frequency, but it just errors:

./capture-analog -f 850 -s /dev/video0 -o sky.mpg
ERROR: Frequency specification [850] is not valid

I've tried 850, 850.0, 850.0Mhz all of which are not valid options (what is the format for using the -f command setting?)

Regards

David

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

What you're looking for is using the tuning tables. In particular, the tables named europe-west, europe-east, italy, newzealand, ireland, france, and southafrica all tune channel 68 to 847.250MHz. In your case I believe you wish to use the table "europe-west", like so:

./capture-analog -t europe-west -c 68 -s /dev/video0 -o sky.mpg

Try that. I get the feeling that will do the trick.

Also in response to someone else's request earlier for "character" channel names, these tables support them - you can actually request to tune channel "E2" or "SE20" (as examples), since they're referenced by that name in the tuning table.

Finally, the frequency parameter is to be given in the same format that ivtv-tune requires it (i.e. 847.250 - in MHz).

Cheers!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by Diego Rivera over 8 years ago

If you want to see which tuning tables are available, use ivtv-tune -L. You can then use ivtv-tune -t <table> -l (lowercase-L) to list the channel mappings for that table.

Cheers!

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by David Blackeby over 8 years ago

Thanks for the details, I'm getting the following error now though

./capture-analog -t europe-west -c 68 -s /dev/video0 -o sky.mpg
SOURCES=[/dev/video0]
ERROR: Tuning table [europe-west] is invalid

I've checked ivtv-tune -L and can see it listed:

ivtv-tune -L
Frequency Maps:
us-bcast
us-cable
us-cable-hrc
us-cable-irc
japan-bcast
japan-cable
europe-west
europe-east
italy
newzealand
australia
ireland
france
china-bcast
southafrica
argentina
australia-optus

I tried enclosing it in single & double quotes to see if that would make a difference but its not.

RE: Script for analog V4L2 device support in TVH (via pipe:// mux) - Added by fa1 fa1 over 8 years ago

In your home folder example below

/home/pi

in home directory is a file called .ivtv-tune

modify it to your freq provider, for the user that runs the script / tvheadend.

example for europe-west

$ cat .ivtv-tune
device /dev/video0
#freqtable us-cable
freqtable europe-west

should now work for the channels.

(1-25/45)