dashcloud
16th May 2008, 04:32
What this guide is:
My research and experience into recording VHS tapes to my computer from my VCR using solely Linux programs. It doesn't cover post-processing or moving the files to DVD's yet.
Suggestions and corrections are greatly appreciated as I've almost certainly missed something important.
I. Equipment needed
A capture card is needed: I'm using a PVR-250. This is a very solid TV capture card with hardware encoding capabilities. It covers all TV regions, with several variations for each region. It's very well supported by the kernel, and you shouldn't have to do anything to get it recognized. Next is your VCR. It sounds strange to talk about quality with analog sources, but if you can find a S-VHS player (VCR with S-Video), you should get a better picture (how much likely depends on a number of factors, including the quality of your tape, and how good the player is, but every little bit helps when trying to convert a VHS tape).
II. Setting up the card
For the Hauppauge cards, you'll need to download the firmware from here: http://dl.ivtvdriver.org/ivtv/firmware/firmware.tar.gz
and extract it to your firmware folder: possibly /lib/firmware or /usr/lib/hotplug/firmware.
Next, you'll need to setup your VCR with a test tape- anything will do, its purpose is to check if your card is setup correctly to grab the video. The next step depends on how your VCR is hooked up to the capture card: if it's anything other than composite, then just connect them, and everything should be good. Skip the next section, and go to the Testing the Card section below.
If you're using composite for video, then you need to change the default input on the card. You'll need to have V4L2-ctl available; on my mythbuntu system the package is v4l-conf.
On PVR-250 card, there's 6 inputs, only 3 of which are physically present on the card. The other 3 are "virtual" for lack of a better word: they work just like their physical counterparts (and in fact won't work unless the corresponding physical input has a connection).
0: Coax
1: S-video 1
2: Composite 1
3: S-video 2
4: Composite 2
5: Composite 3
Of the "virtual" inputs, only Composite 3 is of interest here. I was not able to get video from my VCR until I switched the input to Composite 3.
You can switch to Composite 3 by using
v4l2-conf --set-input=5
.
---Testing the Card---
The simplest way to test if you're setup correctly is to press play on the VCR, do
cat /dev/video0 > tmp.mpg
and then press crtl-c after a few seconds. Play the video back, and if you see what's on the tape, you're all set. If not, try changing the input you're using.
III. Recording Basics
With your card ready to record from a VCR, you can start recording with any number of programs: I'll cover a few here, along with my experiences of using them.
---1. Use cat to dump the stream ---
cat /dev/video0 >filename.mpg
This is the most basic method, and provides you with no control of anything- everything will have to be set before hand.
---2. VLC---
This very capable media player can grab from any video device you have on your system, and it can save your capture to disk or re-stream it across the network or beyond. Strangely, although the PVR-250 appears to be a V4L2 device, when you attempt to use the default V4L2 grabber, it fails. In order to grab from the card, you must use
pvr:// :pvr-device="/dev/video0"
. If you don't want VLC to transcode your material for you on capture, make sure to select RAW for encapsulation method after you've chosen to save the stream.
I chose a different method to record my video, but I see no reason why this wouldn't work.
---3. MPlayer---
As one of the countless things MPlayer can do, it can record from your TV card as well. As with VLC above, video capture only worked on the PVR-250 when I used pvr:// instead of one. MPlayer can actually set many of the basic options for the card (bit rate, aspect ratio, audio bit rate,and format).
Check the manpage for more details.
---4. MythTV---
It should be possible to record your tape by manually scheduling however long your tape is, as long as you set up the appropriate video source (s-video or composite 3). I have no experience with this,so I'd love to hear from anyone who has tried this.
---5. FFmpeg---
My choice for recording from the VCR, it's a solid project, and the choice of many for their video and audio needs. There are lots of ways to tweak what you get from the capture card, but I just set everything on the card itself, and then copied from the card to the harddrive. I used the following command line:
ffmpeg -t hh:mm:ss -i /dev/video0 -acodec copy -vcodec copy moviename.mpg
This just copies from my input device for the specified length of time, and writes it to moviename.mpg.
IV. Advanced Usage
The average person may be satisfied with the quality provided by the defaults, but some want more, and are always looking for ways to make it better or faster. This sections also includes details on the other encoders available on the card (YUV and PCM, plus VBI).
Many of these involve using v4l2-ctl to change the card from its defaults.
---Card Defaults---
Format Video Capture:
Width/Height : 720/480
Pixel Format : MPEG
Field : Interlaced
Bytes per Line: 0
Size Image : 131072
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Format Sliced VBI Capture:
Service Set :
Service Line 0: /
Service Line 1: /
Service Line 2: /
Service Line 3: /
Service Line 4: /
Service Line 5: /
Service Line 6: /
Service Line 7: /
Service Line 8: /
Service Line 9: /
Service Line 10: /
Service Line 11: /
Service Line 12: /
Service Line 13: /
Service Line 14: /
Service Line 15: /
Service Line 16: /
Service Line 17: /
Service Line 18: /
Service Line 19: /
Service Line 20: /
Service Line 21: /
Service Line 22: /
Service Line 23: /
I/O Size : 0
Format VBI Capture:
Sampling Rate : 27000000 Hz
Offset : 248 samples (9.18519e-06 secs after leading edge)
Samples per Line: 1439
Sample Format : GREY
Start 1st Field : 10
Count 1st Field : 12
Start 2nd Field : 273
Count 2nd Field : 12
Framebuffer Format:
Capability :
Flags :
Width : 0
Height : 0
Pixel Format :
Bytes per Line: 0
Size image : 0
Colorspace : Unknown (00000000)
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 720, Height 480
Default : Left 0, Top 0, Width 720, Height 480
Pixel Aspect: 10/11
Crop Capability Video Output:
Bounds : Left 0, Top 0, Width 720, Height 480
Default : Left 0, Top 0, Width 720, Height 480
Pixel Aspect: 10/11
Video input : 2 (Composite 1)
Audio input : 1 (Line In 1)
Frequency: 1076 (67.250000 MHz)
Video Standard = 0x0000b000
NTSC-M/M-JP/M-KR
Tuner:
Capabilities : 62.5 kHz multi-standard stereo lang1 lang2
Frequency range : 44.0 MHz - 958.0 MHz
Signal strength : 0%
Current audio mode : stereo
Available subchannels: stereo
I slightly tweaked those, and use the following for my last conversion:
v4l2-ctl --set-ctrl=stream_type=3,audio_layer_ii_bitrate=11,video_bitrate=12000000,video_peak_bitrate=14000000
What these settings mean:
stream_type=3 : Encode a DVD compatible stream
audio_layer_ii_bitrate=11 : 256KB mp2 stream (stereo is the default)
video_bitrate 12000000 : set the bitrate to 12M (default 6M)
video_peak_rate 14000000 : set the peak bitrate to 14M (default is 8M)
---Card Options---
You can get a list of the options for v4l2-ctl by running it with no arguments, or by visting: http://ivtvdriver.org/index.php/V4l2-ctl
---Card Encoder Options---
You'll see at the bottom that it has a list of MPEG Encoder controls, and they say (menu) next to them, yet there is no menu to be seen. Below I have reproduced the menu for the section (also viewable by using v4l2-ctl -L or --list-ctrls-menu
MPEG Encoder Controls
stream_type (menu) : min=0 max=5 default=0 value=0 flags=update
0: MPEG-2 Program Stream
2: MPEG-1 System Stream
3: MPEG-2 DVD-compatible Stream
4: MPEG-1 VCD-compatible Stream
5: MPEG-2 SVCD-compatible Stream
stream_vbi_format (menu) : min=0 max=1 default=0 value=0
0: No VBI
1: Private packet, IVTV format
audio_sampling_frequency (menu) : min=0 max=2 default=1 value=1
0: 44.1 kHz
1: 48 kHz
2: 32 kHz
audio_encoding_layer (menu) : min=1 max=1 default=1 value=1 flags=update
1: Layer II
audio_layer_ii_bitrate (menu) : min=9 max=13 default=10 value=10
9: 192 kbps
10: 224 kbps
11: 256 kbps
12: 320 kbps
13: 384 kbps
audio_stereo_mode (menu) : min=0 max=3 default=0 value=0 flags=update
0: Stereo
1: Joint Stereo
2: Dual
3: Mono
audio_stereo_mode_extension (menu) : min=0 max=3 default=0 value=0 flags=inactive
0: Bound 4
1: Bound 8
2: Bound 12
3: Bound 16
audio_emphasis (menu) : min=0 max=2 default=0 value=0
0: No Emphasis
1: 50/15 us
2: CCITT J17
audio_crc (menu) : min=0 max=1 default=0 value=0
0: No CRC
1: 16-bit CRC
audio_mute (bool) : default=0 value=0
video_encoding (menu) : min=0 max=1 default=1 value=1 flags=readonly
0: MPEG-1
1: MPEG-2
video_aspect (menu) : min=0 max=3 default=1 value=1
0: 1x1
1: 4x3
2: 16x9
3: 2.21x1
video_b_frames (int) : min=0 max=33 step=1 default=2 value=2 flags=update
video_gop_size (int) : min=1 max=34 step=1 default=12 value=15
video_gop_closure (bool) : default=1 value=1
video_bitrate_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Variable Bitrate
1: Constant Bitrate
video_bitrate (int) : min=0 max=27000000 step=1 default=6000000 value=6000000
video_peak_bitrate (int) : min=0 max=27000000 step=1 default=8000000 value=8000000
video_temporal_decimation (int) : min=0 max=255 step=1 default=0 value=0
video_mute (int) : min=0 max=1 step=1 default=0 value=0
video_mute_yuv (int) : min=0 max=16777215 step=1 default=32896 value=32896
spatial_filter_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Manual
1: Auto
spatial_filter (int) : min=0 max=15 step=1 default=0 value=0 flags=slider
spatial_luma_filter_type (menu) : min=0 max=4 default=0 value=1
0: Off
1: 1D Horizontal
2: 1D Vertical
3: 2D H/V Separable
4: 2D Symmetric non-separable
spatial_chroma_filter_type (menu) : min=0 max=1 default=0 value=1
0: Off
1: 1D Horizontal
temporal_filter_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Manual
1: Auto
temporal_filter (int) : min=0 max=31 step=1 default=0 value=8 flags=slider
median_filter_type (menu) : min=0 max=4 default=0 value=0 flags=update
0: Off
1: Horizontal
2: Vertical
3: Horizontal/Vertical
4: Diagonal
median_luma_filter_minimum (int) : min=0 max=255 step=1 default=0 value=0 flags=inactive slider
median_luma_filter_maximum (int) : min=0 max=255 step=1 default=255 value=255 flags=inactive slider
median_chroma_filter_minimum (int) : min=0 max=255 step=1 default=0 value=0 flags=inactive slider
median_chroma_filter_maximum (int) : min=0 max=255 step=1 default=255 value=255 flags=inactive slider
insert_navigation_packets (bool) : default=0 value=0
---Other encoder devices (on-board)---
On the PVR-250, there are 4 encoder devices:
/dev/video0: the MPEG encoder
/dev/video32: YUV encoder
/dev/vbi0: VBI encoder
/dev/video24: PCM encoder
Each one of these can be selected as your device of choice instead of /dev/video0 by using this command:
-d, --device=<dev> use device <dev> instead of /dev/video0
if <dev> is a single digit, then /dev/video<dev> is used
If you'd rather not change from the default, but would still like to use one of the other encoders, just use your capture program of choice to capture from the device listed above.
---Details on the RAW formats from video24 and video32---
Some details on what the YUV and PCM encoder provide:
The YUV encoder uses 4:1:1, and is HM12 colorspace. This can be played by MPlayer using the following commandline:
mplayer -rawvideo w=x:h=y:format=hm12 -demuxer rawvideo filename
The PCM encoder outputs 2 channel s16le raw audio at the frequency selected in the encoder menu.
Results from using
mplayer -demuxer rawaudio /media/disk/test3.wav
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 1411.2 kbit/100.00% (ratio: 176400->176400)
My research and experience into recording VHS tapes to my computer from my VCR using solely Linux programs. It doesn't cover post-processing or moving the files to DVD's yet.
Suggestions and corrections are greatly appreciated as I've almost certainly missed something important.
I. Equipment needed
A capture card is needed: I'm using a PVR-250. This is a very solid TV capture card with hardware encoding capabilities. It covers all TV regions, with several variations for each region. It's very well supported by the kernel, and you shouldn't have to do anything to get it recognized. Next is your VCR. It sounds strange to talk about quality with analog sources, but if you can find a S-VHS player (VCR with S-Video), you should get a better picture (how much likely depends on a number of factors, including the quality of your tape, and how good the player is, but every little bit helps when trying to convert a VHS tape).
II. Setting up the card
For the Hauppauge cards, you'll need to download the firmware from here: http://dl.ivtvdriver.org/ivtv/firmware/firmware.tar.gz
and extract it to your firmware folder: possibly /lib/firmware or /usr/lib/hotplug/firmware.
Next, you'll need to setup your VCR with a test tape- anything will do, its purpose is to check if your card is setup correctly to grab the video. The next step depends on how your VCR is hooked up to the capture card: if it's anything other than composite, then just connect them, and everything should be good. Skip the next section, and go to the Testing the Card section below.
If you're using composite for video, then you need to change the default input on the card. You'll need to have V4L2-ctl available; on my mythbuntu system the package is v4l-conf.
On PVR-250 card, there's 6 inputs, only 3 of which are physically present on the card. The other 3 are "virtual" for lack of a better word: they work just like their physical counterparts (and in fact won't work unless the corresponding physical input has a connection).
0: Coax
1: S-video 1
2: Composite 1
3: S-video 2
4: Composite 2
5: Composite 3
Of the "virtual" inputs, only Composite 3 is of interest here. I was not able to get video from my VCR until I switched the input to Composite 3.
You can switch to Composite 3 by using
v4l2-conf --set-input=5
.
---Testing the Card---
The simplest way to test if you're setup correctly is to press play on the VCR, do
cat /dev/video0 > tmp.mpg
and then press crtl-c after a few seconds. Play the video back, and if you see what's on the tape, you're all set. If not, try changing the input you're using.
III. Recording Basics
With your card ready to record from a VCR, you can start recording with any number of programs: I'll cover a few here, along with my experiences of using them.
---1. Use cat to dump the stream ---
cat /dev/video0 >filename.mpg
This is the most basic method, and provides you with no control of anything- everything will have to be set before hand.
---2. VLC---
This very capable media player can grab from any video device you have on your system, and it can save your capture to disk or re-stream it across the network or beyond. Strangely, although the PVR-250 appears to be a V4L2 device, when you attempt to use the default V4L2 grabber, it fails. In order to grab from the card, you must use
pvr:// :pvr-device="/dev/video0"
. If you don't want VLC to transcode your material for you on capture, make sure to select RAW for encapsulation method after you've chosen to save the stream.
I chose a different method to record my video, but I see no reason why this wouldn't work.
---3. MPlayer---
As one of the countless things MPlayer can do, it can record from your TV card as well. As with VLC above, video capture only worked on the PVR-250 when I used pvr:// instead of one. MPlayer can actually set many of the basic options for the card (bit rate, aspect ratio, audio bit rate,and format).
Check the manpage for more details.
---4. MythTV---
It should be possible to record your tape by manually scheduling however long your tape is, as long as you set up the appropriate video source (s-video or composite 3). I have no experience with this,so I'd love to hear from anyone who has tried this.
---5. FFmpeg---
My choice for recording from the VCR, it's a solid project, and the choice of many for their video and audio needs. There are lots of ways to tweak what you get from the capture card, but I just set everything on the card itself, and then copied from the card to the harddrive. I used the following command line:
ffmpeg -t hh:mm:ss -i /dev/video0 -acodec copy -vcodec copy moviename.mpg
This just copies from my input device for the specified length of time, and writes it to moviename.mpg.
IV. Advanced Usage
The average person may be satisfied with the quality provided by the defaults, but some want more, and are always looking for ways to make it better or faster. This sections also includes details on the other encoders available on the card (YUV and PCM, plus VBI).
Many of these involve using v4l2-ctl to change the card from its defaults.
---Card Defaults---
Format Video Capture:
Width/Height : 720/480
Pixel Format : MPEG
Field : Interlaced
Bytes per Line: 0
Size Image : 131072
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Format Sliced VBI Capture:
Service Set :
Service Line 0: /
Service Line 1: /
Service Line 2: /
Service Line 3: /
Service Line 4: /
Service Line 5: /
Service Line 6: /
Service Line 7: /
Service Line 8: /
Service Line 9: /
Service Line 10: /
Service Line 11: /
Service Line 12: /
Service Line 13: /
Service Line 14: /
Service Line 15: /
Service Line 16: /
Service Line 17: /
Service Line 18: /
Service Line 19: /
Service Line 20: /
Service Line 21: /
Service Line 22: /
Service Line 23: /
I/O Size : 0
Format VBI Capture:
Sampling Rate : 27000000 Hz
Offset : 248 samples (9.18519e-06 secs after leading edge)
Samples per Line: 1439
Sample Format : GREY
Start 1st Field : 10
Count 1st Field : 12
Start 2nd Field : 273
Count 2nd Field : 12
Framebuffer Format:
Capability :
Flags :
Width : 0
Height : 0
Pixel Format :
Bytes per Line: 0
Size image : 0
Colorspace : Unknown (00000000)
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 720, Height 480
Default : Left 0, Top 0, Width 720, Height 480
Pixel Aspect: 10/11
Crop Capability Video Output:
Bounds : Left 0, Top 0, Width 720, Height 480
Default : Left 0, Top 0, Width 720, Height 480
Pixel Aspect: 10/11
Video input : 2 (Composite 1)
Audio input : 1 (Line In 1)
Frequency: 1076 (67.250000 MHz)
Video Standard = 0x0000b000
NTSC-M/M-JP/M-KR
Tuner:
Capabilities : 62.5 kHz multi-standard stereo lang1 lang2
Frequency range : 44.0 MHz - 958.0 MHz
Signal strength : 0%
Current audio mode : stereo
Available subchannels: stereo
I slightly tweaked those, and use the following for my last conversion:
v4l2-ctl --set-ctrl=stream_type=3,audio_layer_ii_bitrate=11,video_bitrate=12000000,video_peak_bitrate=14000000
What these settings mean:
stream_type=3 : Encode a DVD compatible stream
audio_layer_ii_bitrate=11 : 256KB mp2 stream (stereo is the default)
video_bitrate 12000000 : set the bitrate to 12M (default 6M)
video_peak_rate 14000000 : set the peak bitrate to 14M (default is 8M)
---Card Options---
You can get a list of the options for v4l2-ctl by running it with no arguments, or by visting: http://ivtvdriver.org/index.php/V4l2-ctl
---Card Encoder Options---
You'll see at the bottom that it has a list of MPEG Encoder controls, and they say (menu) next to them, yet there is no menu to be seen. Below I have reproduced the menu for the section (also viewable by using v4l2-ctl -L or --list-ctrls-menu
MPEG Encoder Controls
stream_type (menu) : min=0 max=5 default=0 value=0 flags=update
0: MPEG-2 Program Stream
2: MPEG-1 System Stream
3: MPEG-2 DVD-compatible Stream
4: MPEG-1 VCD-compatible Stream
5: MPEG-2 SVCD-compatible Stream
stream_vbi_format (menu) : min=0 max=1 default=0 value=0
0: No VBI
1: Private packet, IVTV format
audio_sampling_frequency (menu) : min=0 max=2 default=1 value=1
0: 44.1 kHz
1: 48 kHz
2: 32 kHz
audio_encoding_layer (menu) : min=1 max=1 default=1 value=1 flags=update
1: Layer II
audio_layer_ii_bitrate (menu) : min=9 max=13 default=10 value=10
9: 192 kbps
10: 224 kbps
11: 256 kbps
12: 320 kbps
13: 384 kbps
audio_stereo_mode (menu) : min=0 max=3 default=0 value=0 flags=update
0: Stereo
1: Joint Stereo
2: Dual
3: Mono
audio_stereo_mode_extension (menu) : min=0 max=3 default=0 value=0 flags=inactive
0: Bound 4
1: Bound 8
2: Bound 12
3: Bound 16
audio_emphasis (menu) : min=0 max=2 default=0 value=0
0: No Emphasis
1: 50/15 us
2: CCITT J17
audio_crc (menu) : min=0 max=1 default=0 value=0
0: No CRC
1: 16-bit CRC
audio_mute (bool) : default=0 value=0
video_encoding (menu) : min=0 max=1 default=1 value=1 flags=readonly
0: MPEG-1
1: MPEG-2
video_aspect (menu) : min=0 max=3 default=1 value=1
0: 1x1
1: 4x3
2: 16x9
3: 2.21x1
video_b_frames (int) : min=0 max=33 step=1 default=2 value=2 flags=update
video_gop_size (int) : min=1 max=34 step=1 default=12 value=15
video_gop_closure (bool) : default=1 value=1
video_bitrate_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Variable Bitrate
1: Constant Bitrate
video_bitrate (int) : min=0 max=27000000 step=1 default=6000000 value=6000000
video_peak_bitrate (int) : min=0 max=27000000 step=1 default=8000000 value=8000000
video_temporal_decimation (int) : min=0 max=255 step=1 default=0 value=0
video_mute (int) : min=0 max=1 step=1 default=0 value=0
video_mute_yuv (int) : min=0 max=16777215 step=1 default=32896 value=32896
spatial_filter_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Manual
1: Auto
spatial_filter (int) : min=0 max=15 step=1 default=0 value=0 flags=slider
spatial_luma_filter_type (menu) : min=0 max=4 default=0 value=1
0: Off
1: 1D Horizontal
2: 1D Vertical
3: 2D H/V Separable
4: 2D Symmetric non-separable
spatial_chroma_filter_type (menu) : min=0 max=1 default=0 value=1
0: Off
1: 1D Horizontal
temporal_filter_mode (menu) : min=0 max=1 default=0 value=0 flags=update
0: Manual
1: Auto
temporal_filter (int) : min=0 max=31 step=1 default=0 value=8 flags=slider
median_filter_type (menu) : min=0 max=4 default=0 value=0 flags=update
0: Off
1: Horizontal
2: Vertical
3: Horizontal/Vertical
4: Diagonal
median_luma_filter_minimum (int) : min=0 max=255 step=1 default=0 value=0 flags=inactive slider
median_luma_filter_maximum (int) : min=0 max=255 step=1 default=255 value=255 flags=inactive slider
median_chroma_filter_minimum (int) : min=0 max=255 step=1 default=0 value=0 flags=inactive slider
median_chroma_filter_maximum (int) : min=0 max=255 step=1 default=255 value=255 flags=inactive slider
insert_navigation_packets (bool) : default=0 value=0
---Other encoder devices (on-board)---
On the PVR-250, there are 4 encoder devices:
/dev/video0: the MPEG encoder
/dev/video32: YUV encoder
/dev/vbi0: VBI encoder
/dev/video24: PCM encoder
Each one of these can be selected as your device of choice instead of /dev/video0 by using this command:
-d, --device=<dev> use device <dev> instead of /dev/video0
if <dev> is a single digit, then /dev/video<dev> is used
If you'd rather not change from the default, but would still like to use one of the other encoders, just use your capture program of choice to capture from the device listed above.
---Details on the RAW formats from video24 and video32---
Some details on what the YUV and PCM encoder provide:
The YUV encoder uses 4:1:1, and is HM12 colorspace. This can be played by MPlayer using the following commandline:
mplayer -rawvideo w=x:h=y:format=hm12 -demuxer rawvideo filename
The PCM encoder outputs 2 channel s16le raw audio at the frequency selected in the encoder menu.
Results from using
mplayer -demuxer rawaudio /media/disk/test3.wav
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 1411.2 kbit/100.00% (ratio: 176400->176400)