Experiences with the easycap DC60 audio and video capture adapter on Linux

This Blog is dedicated to all owners of the STK1160 chip based EasyCAP (or identical) devices, who want to use it under Linux.

Activating audio for the STK1160 device: read the this post

German speaking users: read my article on ubuntuusers.de

The EasyCAP DC60 and its clones are cheap little USB analogue capturing devices which can be used for viewing and recording video under Linux from different sources like VHS tape recorders, satellitereceivers, camcorders ...

Command Line TV

At a first glance command line applications in Linux seem to be complicated.  After some experience with Linux, command line media programs like mplayer/ mencoder turn out to be the best choice for TV viewing and recording.
Not only due to the lack of TV GUI programs, after some practice users appreciate the high flexibility of these command line players.

After all, using a template command (like provided below) often reaches a special goal more quickly than heavily clicking through a GUI program.

Commandline applications for TV viewing and recording

  • MPlayer
  • MEncoder
  • AVplay/ AVconv
  • cvlc
  • gstreamer 
  • sox (audio) 

What you need to know in general for setting up command line TV programs

In the viewing/ capturing program (e.g. mplayer) you must specify
  • the videodevicenode of yor TV-card (/dev/videoN),
  • the input number of the cable/ input where the source is plugged in,
  • the TV norm of the videosource and (e.g. PAL, NTSC)
  • the ALSA sounddevice if you want to capture audio. Get a list of ALSA soundcards with this command:
    cat /proc/asound/cards
    If you encounter audio problems while capturing you need to specify the correct audiorate for
    your device in the capturing program.

Some notes on ALSA 

In the commad line progam you can either use the hardware number of the ALSA soudcard you want to capture from or alternatively the name of the sound card.
In the output of  cat /proc/asound/cards you can see the ALSA name of the soundcard behind the number in brackets.
Example output:

0 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0xf0580000 irq 43
 1 [EasyALSA0      ]: easycapdc60 - easycap_alsa
                      easycap_alsa
 2 [SAA7134        ]: SAA7134 - SAA7134
                      saa7134[0] at 0x48000000 irq 18

MPlayer

Mplayer, beyond doubt, is the most prominent "media player" for Linux and available for almost every distribution. That's why mplayer is always the first choice application for testing a Linux TV installation.

A new project called mplayer2 is on its way. This project is a fork of the original MPlayer project with the focus on further development.
By now the command line syntax between mplayer and mplayer2 is identical, but if you install mplayer2 you cannot use mencoder on your system anymore!

Mplayer template command: The yellow highlighted options need to be changed according to your TV-card, system and video source.
mplayer tv:// -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:amode=1:forcechan=2:audiorate=48000:adevice=hw.1,0:forceaudio:immediatemode=0 -vf pp=lb -aspect 16:9 -ao sdl -vo sdl

Explanation

  • mplayer tv://
    • Switches mplayer to analogue TV mode. This command alone will work if all other needed options are specified in ~/.mplayer/config.
  • -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25
    • With the -tv option all settings for TV capturing are defined. Norm, device and input must be set right to see a picture. The FPS setting is only needed if mplayer doesn't  recognize the right framerate. Consult mplayers manpage for more detailed description.
  • :alsa:amode=1:forcechan=2:audiorate=48000:adevice=hw.1,0:forceaudio:immediatemode=0
    • This line is the ALSA audio part of the TV settings. The audiorate must be appropriate for your device, 8000 is low quality but always safe.
    • If you do not want to capture audio, cut out this part of the command and add the -nosound option at the end of the mplayer command
  • -vf pp=lb -aspect 16:9 -ao sdl -vo sdl
    • Additional options: -vf opens a filter chain, -aspect sets the aspect of the mplayer window, -ao sdl defines sdl as audio-out driver and -vo sdl defines sdl as video-out driver to avoid  picture problems (flickering, picture freeze).
      Read more about filters below at MEncoder.
More information about TV capturing with mplayer on linuxtv.org.

Mencoder

In opposition to some other people I'm convinced in my experience that mencoder is the application of choice in Linux for recording analogue TV sources, even old VHS tapes. I personally cannot complain about the quality of all recordings I've made with mencoder.

For people who rather use GUI programs exists a flexible GUI frontend for MEncoder: Mtvcgui.

With the following templates and the appropriate filters you can create compressed output files by realtime encoding that only need to be cut after recording (e.g. with avidemux). 

Mencoder template command for creating a DivX 5 compatible mpeg4-mp3 video file (~10 MB/minute).
mencoder tv:// -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:amode=1:forcechan=2:audiorate=48000:adevice=hw.1,0:forceaudio:immediatemode=0 -ffourcc DX50 -ovc lavc -lavcopts  vcodec=mpeg4:mbd=2:turbo:vbitrate=1200:keyint=100 -oac mp3lame -lameopts cbr:br=128 -vf pp=lb,scale=640:480  -o test.avi 

Mencoder template command for creating a DVD compatible mpeg2-ac3 video file (~32 MB/minute).
mencoder tv:// -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:adevice=hw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0  -of mpeg -mpegopts format=dvd -oac lavc -ovc lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=8000:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192 -o test.mpg

 

 Explanation 

  • The -tv option with all settings is identically equal to mencoder (see above).
  • Explanation of the "DivX 5" command options
    • -ffourcc DX50
      • This option makes that the created video will be identified by any player as 'DivX 5' video.
    • -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo:vbitrate=1200:keyint=100
      • The -ovc option declares that the encoding should be done by the lavc codec family, -lavcopts defines the options for libavcodec.
        Control the quality by rising or lowering the bitrate.
    • -oac mp3lame -lameopts cbr:br=128
      • The -oac option defines which codec should be used for audio encoding. The -lameopts cbr:br=128 option sets the audio encoding to a constant bitrate of 128kb/s.
      • If mp3 encoding is not supported by your mplayer version (e.g. in Debian) you can use the ac3 audio codec with the following option  instead:
        -oac lavc -lavcopts acodec=ac3:abitrate=128
  •  Explanation of the "DVD" command options
    • -of mpeg -mpegopts format=dvd
      • These options define the created video to be DVD compatible
    • -oac lavc -ovc lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=8000:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192
      • Video and audio encoding should be done by the lavc codec family. The specific codecs for video vcodec and audio acodec and options are defined by -lavcopts.
  • -vf pp=lb,scale=640:480
    • The -vf option opens a filter chain in mencoder, the filters are deliminated by comma.
      Here the pp=lb filter deinterlaces the video stream and then scales the video down to 640x480 pixels.
      See more filter templates below.
  •  -o test.avi
    • The -o option defines the name of the output file.
      Write a full path if you want to save the video in a destined folder

Sample video filter chains

The -vf option opens the video filter chain. After one blank the filters are deliminated by comma.
If you encode interlaced material the deinterlace filter (pp=lb) always should be the first in the filterchain.

Note:  You can reach best quality if you capture the video at the full range of your TV-card (720x576px PAL, 720x480px NTSC for EasyCAP and similar devices) regardless if the source material has 4/3 or 16/9 or any different aspect.
Use the filters to correct the aspect and for cutting away black borders.

These filter examples are for PAL source material, you need to recalculate it for NTSC source material.
The px values need to be a multiple of 4 to be compliant to the AVI standard!
  • pp=lb,scale=640:480 
    • Scales down a deinterlaced 4/3 (720x576 PAL) video about 25%. Downscaling reduces the size of the outputfile and reduces artifacts!
  • scale=720:406
    • Scales down a 4/3 source to 16/9 aspect.
  • crop=720:406:0:68,scale=704:396 
    • Crops the black borders from a 16:9 movie captured from a 4:3 DVD or VHS source and scales down the output about 5%.
  • crop=720:320:0:128
    • Crops (with some tolerance pixels) the black borders from a cinemascope (2.35:1 aspect ~= 720x306 px) movie captured from a 4:3 DVD or VHS source.
  • scale=720:406,crop=720:320:0:43
    • This filter is for capturing a cinemascope movie from a 16/9 TV station broadcasting (most stations in Europe).
      At first the 4/3 capture from the TV-card is scaled to 16/9 and then the black borders of the film are cut away.
    • Chart for this example:
MEncoder scale and crop filter example

Audio filters

The -af option opens an audio filter chain. After one blank the filters are deliminated by comma.
  • Adding the following option to the mencoder command enhances the sound level of your recording. You can rise and lower the decibel rate according to your needs.
    -af volume=+20db

More information about about TV recording with mencoder:




AVPlay and AVConv (libav.org)

The  avplay and avconv commands are the successors of ffplay and ffmpeg in Ubuntu (and many other distros).

The "old" FFmpeg project was splitted in two branches, ffmpeg.org and libav.org. The ffmpeg and ffplay command in libav are deprecated and will be entirely replaced by 'avconv' and 'avplay'. The libav versions 0.8.x and newer (Ubuntu 12.04) support v4l2 capturing again

Installation

Install the libav-tools package if you want to use avplay and avconv.
If you want to use mp3 encoding the libavcodec-extra-53 package must be installed.

Before capturing with avplay and avconv

  • Note that you must activate the right video source (norm) with qv4l2, mplayer or another tool before launching avconv.
    Simply start that tool for some seconds with the the right norm sttings for your source.
  • When you have a device with tuner you also must tune the channel you want to capture from with any TV viewer such as tvtime or xawtv
  • Note. With the -channel option in the avconv command you can only specify the input numbers of your device.
  • You also have to set the audio recording levels correctly with a standard mixer.  

Personal note

In my experiments with avplay and avconv (0.8.4) on my system (1.8 Ghz dualcore; 1GB) only video viewing without sound did work properly. When I captured video with sound, the picture freezes after some seconds. Recording video with sound did work for some minutes but after ~ 5 to 8 minutes the audio was heavily delayed.
At the moment I cannot recommend avconv or avplay for v4l2 capturing.

Avplay


Avplay template command for viewing any v4l2 source:

avplay -f video4linux2 /dev/video0 

Avplay template command for viewing with sound:

avplay -f video4linux2 -channel 1 -i /dev/video0 | avplay -f alsa -i hw:1 -nodisp

 

More information about about TV viewing with avplay: 

Avconv


Avconv template command for creating a DivX 5 compatible mpeg4-mp3 video file (~10 MB/minute)
 
avconv -f video4linux2 -channel 1 -i /dev/video0 -f alsa -i hw:1 -vcodec mpeg4 -vtag DX50 -b 1200k -r 25 -acodec libmp3lame -ar 44100 -ac 2 -ab 128k -vf yadif,scale=720:406  -y test.avi  



_______________________________________________________________________________ 
outdated information

 The EasyCAP DC60 works with the following applications on Linux
  • mplayer / mencoder
  • Tvtime
  • Vlc
  • Xawtv
  • Zoneminder
  • motion
  • gstreamer  (cheese; you cannot select a different input than 0 in cheese)
  • gmerlin recorder
  • sox (audio) 
Setting up the viewing/ capturing program
In general, the videodevice, the input number, the TV norm and the sounddevice must be specified in the program.
So, you "simply" have to find out, how to do this in your favourite program.

1. Viewing with the tvcap-script
The  tvcap-script supports viewing with mplayer, vlc, tvtime and cheese and capturing with mencoder.
Read more on the tvcap page.

2. Viewing with MPlayer
Simply copy and paste the mplayer line into the terminal.
Change the highlighted parameters, if needed, according to your device, TV standard and system.

Note, that only one input can be used at the same time.

Viewing with MPlayer  ALSA:
mplayer tv:// -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:amode=1:forcechan=2:audiorate=48000:adevice=plughw.1,0:forceaudio:immediatemode=0 -ao sdl,alsa

Viewing with MPlayer OSS:
mplayer tv:// -tv driver=v4l2:norm=PAL:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:amode=1:forcechan=2:audiorate=48000:adevice=/dev/dsp:forceaudio:immediatemode=0 -ao sdl ,oss

3. Viewing with Tvtime
Tvtime needs SoX to be installed if you want to hear sound.

Simply copy and paste the tvtime and sox line into the terminal.
Change the highlighted parameters, if needed, according to your device and system.

Note, that only one input can be used at the same time.

Viewing with tvtime and SoX (ALSA):
tvtime -d /dev/video0 -i 1 -n PAL | sox -t alsa plughw:1,0 -s2 -c 2 -r 48000 -s2 -t alsa default

Viewing with tvtime and SoX (OSS):
tvtime -d /dev/video0 -i 1 -n PAL | sox -t raw -s2 -c 2 -r 48000 -s2 -t ossdsp /dev/dsp

4. Other possibilities

For viewing you can use the provided scripts which come with the driver package.

These scripts also work with the easycapdriver in the Kernel (2.6.38 an onward).

For usage read the README file from the drivers source package or open the scripts in your favourite editor to understand all options
(in particular, if you experience poor or absent sound)

Alternatively you can use