Jun 28

Capturing VHS video with vlc via v4l2

Category: Linux,multimedia   — Published by goeszen on June 28, 2015 at 2:01 pm

After re-using my VHS mencoder avconv capture pipeline today, on a Ubuntu 14.04 system, I've found that things had degraded since my last post. It seems the stk1160 driver, in relation to my kernel, or my halfbaked install of it, or anything else was raising issues again. Capture framerate dropped to an unusable rate (with mencoder skipping frames like mad), so the recorded video appeared sped-up.

Time to try something new and it turned out, this time, I've found a great solution: vlc.

Playing back Video4Linux sources worked out of the box, simply by opening the /dev/video0 device via GUI. Same for audio, which even trusty tvtime refused to deliver today, rendering the image as a green mess. vlc took all hurdles.

First, on Ubuntu 14.04, audio was back to muted, so I had to issue $ amixer -c stk1160mixer sset Line unmute cap
but after that, I could start capturing video. Don't forget to check out the naming of your audio device (the "hw:..." bit), which changes between boots, with $ cat /proc/asound/cards

So here it is, the command-line command to capture from the stk1160 EasyCap stick, complete with a GUI/display output to monitor what you're recording:

sudo nice -n -19 vlc v4l:///dev/video0 :v4l-norm=0 :input-slave=alsa://hw:2,0 :live-caching=300 '--sout=#transcode{vcodec=HFYU,acodec=s16l,channels=2,samplerate=48000}:duplicate{dst=display,dst=std{access=file{no-overwrite},mux=avi,dst='VHS_vlc.avi'}}'

As you can see, I stick with the previously introduced 2-step encoding + compression stance, first I capture with vlc to HuffyYUV + WAV in an AVI container, then I'll compress this "raw" video to mp4. top tells me capture runs at about ~60% CPU on an Intel Core2 CPU 4300 @ 1.80GHz.

15 Responses to “Capturing VHS video with vlc via v4l2”

  1. Karl says:

    Thanks for this, works great. I just had to change the norm to PAL to suit our videos here and hw to 3.
    One question though, I haven't been able to get it to output/save file.
    It should go to VHS_vlc.avi in the directory running command right?

  2. goes says:

    Yes, v4l-norm has to be adapted to whatever input material you're encoding, values are: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour) (from param_definition v4l_params).

    But I don't know why vlc is not saving to file. Normally the "dst=" bit would write to file, when used as in the example. See, I use the "duplicate" sink, which writes to dst=display and dst=std. I would check if your command-line has all quotes and curly brackets right. Another test would be to let vlc generate the command for you, which should be doable via GUI and its wizard. Possible but not very probable would be that your version of vlc has issues with the "duplicate" output module, and chokes on some parameters. Run vlc with -vvv for very verbose output and see if it tells you something.

  3. Karl says:

    Thanks for this, works great. I just had to change the norm to PAL to suit our videos here and hw to 3.
    One question though, I haven't been able to get it to output/save file.
    It should go to VHS_vlc.avi in the directory running command right?

  4. goes says:

    Yes, v4l-norm has to be adapted to whatever input material you're encoding, values are: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour) (from param_definition v4l_params).

    But I don't know why vlc is not saving to file. Normally the "dst=" bit would write to file, when used as in the example. See, I use the "duplicate" sink, which writes to dst=display and dst=std. I would check if your command-line has all quotes and curly brackets right. Another test would be to let vlc generate the command for you, which should be doable via GUI and its wizard. Possible but not very probable would be that your version of vlc has issues with the "duplicate" output module, and chokes on some parameters. Run vlc with -vvv for very verbose output and see if it tells you something.

  5. Nicolas says:

    Hi,
    I've tried to use your command line but when I try to launch it, I have an error message "VLC is not supposed to be run as root. Sorry.". Is it normal ?
    Thank you !

  6. goeszen says:

    Yes, it is. I don't know why I didn't have this back then when I wrote the post, but it pops up with recent VLCs. Just do what the message suggests, use vlc-wrapper if you need (or want to try real-time priorities). But I would suggest just running vlc without sudo, and to "renice" vlc use the nice command + process number or fire up top, press r for "renice" select the vlc process and raise it's priority by lowering the nice value. Or have a fast CPU...

  7. Nicolas says:

    Hi,
    I've tried to use your command line but when I try to launch it, I have an error message "VLC is not supposed to be run as root. Sorry.". Is it normal ?
    Thank you !

  8. goeszen says:

    Yes, it is. I don't know why I didn't have this back then when I wrote the post, but it pops up with recent VLCs. Just do what the message suggests, use vlc-wrapper if you need (or want to try real-time priorities). But I would suggest just running vlc without sudo, and to "renice" vlc use the nice command + process number or fire up top, press r for "renice" select the vlc process and raise it's priority by lowering the nice value. Or have a fast CPU...

  9. Nicolas says:

    Hi,
    I have the same issue, VLC doesn't write any file. I've used copy and paste of your command line. Is there a solution ?
    Thank you !

  10. goeszen says:

    I compiled the command by trial and error myself, and these filter/sout pipelines sometimes need a different verb here or there, or tiny things. You can preview commands by using the GUI, configuring things and then see in "resulting command" (or it is worded similar) how vlc itself would assemble the command-line. Also, try different quotes. vlc needs the right quotes. I have single quotes in the command line here, but try double quotes around the sout chain. Or, make sure you have '"double minus" --sout' there! This blog here tends to render "two minus chars" as one hyphen/dash. (Just compare vlc commands elsewhere to see what I mean) ... Darn, I really need to fix this hyphen translation one day...

  11. Nicolas says:

    Hi,
    I have the same issue, VLC doesn't write any file. I've used copy and paste of your command line. Is there a solution ?
    Thank you !

  12. goeszen says:

    I compiled the command by trial and error myself, and these filter/sout pipelines sometimes need a different verb here or there, or tiny things. You can preview commands by using the GUI, configuring things and then see in "resulting command" (or it is worded similar) how vlc itself would assemble the command-line. Also, try different quotes. vlc needs the right quotes. I have single quotes in the command line here, but try double quotes around the sout chain. Or, make sure you have '"double minus" --sout' there! This blog here tends to render "two minus chars" as one hyphen/dash. (Just compare vlc commands elsewhere to see what I mean) ... Darn, I really need to fix this hyphen translation one day...

  13. Jake says:

    Caution! This generates only 720x480 HuffyYUV videos (crops almost 100 lines). You should put scale=1 inte the transcode to keep the original resolution.

  14. goeszen says:

    Hi Jake, I've posted an update - please read: you are right, and it's related with something else. Were you able to capture proper video with scale added?

  15. Jake says:

    Yes, i was able to capture proper video (with scale) a few days ago... but now i experience also the issues that you describe in the update. I use Manjaro (Arch Linux based) and an EasyCAP with UTV007 chipset.
    Today i tested it with a STK1160 and in addition to the wrong resolution it shows only black/white video.
    I installed many updates in the meantime, i think that broke it. The driver comes with the kernel, or not? I tried serveral older versions but it did not change anything. What else is there involved?
    It even does not work properly on a PC that is at least 2 weeks behind (stable repos) and 4.1 kernel.

Leave a Reply

=