LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-18-2021, 01:06 PM   #31
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123

Quote:
/dev/video0: Device or resource busy
Did you have other programs grabbing the feed from '/dev/video0' when you ran the ffmpeg command? Only one program can access it at a time.

Also, be sure to try both '-f alsa -i default' and '-f pulse -i default'.

-----

That command was meant to confirm that you're able to get both video and audio from the usb capture device. If it's anything like my experience with this device, the former will be out of sync and the latter will (occasionally) be in sync (with plenty of non-monotonous dts warnings). Both of them will give you a 'dirty' video file that a media player would be "smart" enough to know how to play them.

I get different results when I play these videos in different media players. VLC play them; sometime with sounds, sometime without. ffplay play some of them really fast at incorrect fps. mpv actually give out an explanation in the terminal on what the issue is;
Code:
Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).
In the playbacks of all of the samples I've recorded thus far, it sounded like the audio in the usb capture device is slow to initialize. Either that or ffmpeg is unable to initialize the audio properly and in a timely manner.

gs-streamer is apparently the better tool for this task but I have not been able to figure out how to run gs-streamer.
https://www.linuxtv.org/wiki/index.p...at_encoding.3F (see the three bullets)

Last edited by SW64; 10-18-2021 at 01:29 PM.
 
Old 10-18-2021, 01:29 PM   #32
borgward
Member
 
Registered: Apr 2005
Location: Austin, Texas
Distribution: Feather, Darn Small Linux
Posts: 529

Original Poster
Rep: Reputation: 21
Volume Control was open but not running. I turned closed it and ran the command again w/same result. Maybe the built in camcorder is the problem. It's indicator light is not on however. That would be /dev/Video2 or 3.

Don't know what to do w/ '-f alsa -i default' and '-f pulse -i default'.
 
Old 10-18-2021, 02:01 PM   #33
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123
Use 'ffmpeg -sources' to find the correct /dev/videoX to call up with.

I don't know if this is the correct way of looking at ffmpeg but this is how I see ffmpeg as.

Code:
ffmpeg [audio input section] [video input section] [affect video section] [affect audio section] [output section]
so, with this simple command,
Code:
ffmpeg -f pulse -i default -f video4linux2 -i /dev/video0 -q 1 -f mpeg output-mpeg.mp4
'-f pulse -i default'
This is the audio input section. We're telling ffmpeg to use this audio device specifically. This is the section I was asking you to swap out with.

'-f video4linux2 -i /dev/video0'
This is the video input section. Usually, this is a video file. In this example, we are specifying what video device to capture and basically, what it is.

In a more complex ffmpeg command, we can also specify what input settings to use as some devices have multiple options (screen sizes, frame rates, etc). Same thing for the audio input section.

'-q 1'
This is the affect video section. I put this in here to bump up mpeg's quality to a better level. This is also where we put the codec flag in if we want to convert source's codec into something else (rawvideo to mpeg or x264, for example).

There is no affect audio section in this command because we are testing your audio port and we're letting ffmpeg fall back to defaults. ffprobe will tell you what this was. If there was a need to put in something in this section, it could be '-c:a aac', '-ar 48000' and/or '-ac 2' to specify the codec, sample rate and number of channels.

'-f mpeg output-mpeg.mp4'
This is the output section. Here, we've told ffmpeg to format the mp4 container as mpeg. You can give it any filename you want but you must specify the correct extension. ffmpeg check the extension to determine the format of the container and the correct codec.

I've been looking for programs that make this an easier process. SimpleScreenRecorder gave me the closet result but it still gave me out-of-sync videos and I find its options limiting in getting the usb capture device to work.

Last edited by SW64; 10-18-2021 at 02:56 PM.
 
Old 10-18-2021, 07:04 PM   #34
borgward
Member
 
Registered: Apr 2005
Location: Austin, Texas
Distribution: Feather, Darn Small Linux
Posts: 529

Original Poster
Rep: Reputation: 21
I realized to run those 2 commands after my reply. I ran them with still no audio. Thanks anyway. I am wondering about how to find what other process is currently being used. It's that or else a false error message. I get those with my car sometimes.
 
Old 10-19-2021, 12:41 AM   #35
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123
So I've finally figured out how to run gstreamer. I used this webpage https://www.linuxtv.org/wiki/index.php/V4L_capturing as a guide to create a small script that worked for me. It's pretty neat that this guide combined ffmpeg and gstreamer together to create a command that will capture tapes. The video and audio in the resulting video files are perfectly synchronized. As far as I can tell, I am no longer getting the non-monotonous dts warnings in the media players. I am still getting 'clipping 1 dct coefficients' warnings from the mpeg1video script, though.

I've copied and pasted two scripts to this post. I've left them unaltered as they are what worked on my computer. Copy each one to its own text file and name them accordingly to their titles. You may need to make adjustments to the AUDIO_DEVICE variable to get it working with your audio device on your computer. That might be 'hw:1' for you, borgward. To run the script, ensure that your usb video capture device is plugged in, open a terminal where the scripts reside at, and type in 'sh tape-capture-libx264.sh'. You can start the tape before or after starting up a script. I recommend the 'tape-capture-libx264.sh' script over the 'tape-capture-mpeg1video.sh' script but they both worked well.

This quote from the webpage is important to note.
Quote:
"Note: always use an ALSA hw device, as they are closest to the hardware. Pulse audio devices and ALSA's plughw devices add extra layers that, while more convenient for most uses, only cause headaches for us."
I am not convinced running 'pasuspender -- ffmpeg' that I found in this link did anything on my computer but it may help you out: https://askubuntu.com/questions/1684...-and-alsa-only

gstreamer and ffmpeg will need to be installed on your system first before you can run these scripts.

'tape-capture-mpeg1video.sh'
Code:
#!/bin/bash
# https://www.linuxtv.org/wiki/index.php/V4L_capturing

TV_NORM=NTSC-M
VIDEO_DEVICE=/dev/video0
VIDEO_INPUT=0
AUDIO_DEVICE=hw:2
VIDEO_CAPABILITIES="video/x-raw, format=(string)YUY2, width=(int)720, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1"
AUDIO_CAPABILITIES="audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)96000, channels=(int)1"

ENCODE_VIDEO_FORMAT=mpeg1video
ENCODE_AUDIO_FORMAT=mp2
ENCODE_MUXER_FORMAT=mpeg
ENCODE_VIDEO_OPTIONS="-q 2"
ENCODE_AUDIO_OPTIONS="-ac 1 -ar 44100 -ab 192k"
ENCODE_MUXER_OPTIONS=""
ENCODE_FILENAME="tape-capture_$(date +%Y%m%d_%H%M%S).mpg"

ffmpeg \
    -i <(
        gst-launch-1.0 -q \
            v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
                ! $VIDEO_CAPABILITIES \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! mux. \
            alsasrc device="$AUDIO_DEVICE" do-timestamp=true \
                ! $AUDIO_CAPABILITIES \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! mux. \
            matroskamux name=mux \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! fdsink fd=1
    ) \
    -c:v $ENCODE_VIDEO_FORMAT $ENCODE_VIDEO_OPTIONS \
    -c:a $ENCODE_AUDIO_FORMAT $ENCODE_AUDIO_OPTIONS \
    -f   $ENCODE_MUXER_FORMAT $ENCODE_MUXER_OPTIONS \
    "$ENCODE_FILENAME"
'tape-capture-libx264.sh'
Code:
#!/bin/bash
# https://www.linuxtv.org/wiki/index.php/V4L_capturing

TV_NORM=NTSC-M
VIDEO_DEVICE=/dev/video0
VIDEO_INPUT=0
AUDIO_DEVICE=hw:2
VIDEO_CAPABILITIES="video/x-raw, format=(string)YUY2, width=(int)720, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1"
AUDIO_CAPABILITIES="audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)96000, channels=(int)1"

ENCODE_VIDEO_FORMAT=libx264
ENCODE_AUDIO_FORMAT=aac
ENCODE_MUXER_FORMAT=mp4
ENCODE_VIDEO_OPTIONS="-crf 23 -preset ultrafast -pix_fmt yuv420p"
ENCODE_AUDIO_OPTIONS="-ac 1 -ar 44100 -ab 192k"
ENCODE_MUXER_OPTIONS=""
ENCODE_FILENAME="tape-capture_$(date +%Y%m%d_%H%M%S).mp4"

ffmpeg \
    -i <(
        gst-launch-1.0 -q \
            v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
                ! $VIDEO_CAPABILITIES \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! mux. \
            alsasrc device="$AUDIO_DEVICE" do-timestamp=true \
                ! $AUDIO_CAPABILITIES \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! mux. \
            matroskamux name=mux \
                ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
                ! fdsink fd=1
    ) \
    -c:v $ENCODE_VIDEO_FORMAT $ENCODE_VIDEO_OPTIONS \
    -c:a $ENCODE_AUDIO_FORMAT $ENCODE_AUDIO_OPTIONS \
    -f   $ENCODE_MUXER_FORMAT $ENCODE_MUXER_OPTIONS \
    "$ENCODE_FILENAME"

Last edited by SW64; 10-19-2021 at 01:03 AM.
 
Old 10-19-2021, 09:44 AM   #36
borgward
Member
 
Registered: Apr 2005
Location: Austin, Texas
Distribution: Feather, Darn Small Linux
Posts: 529

Original Poster
Rep: Reputation: 21
About Pulse and Alsa. Do I quit , kill pulse? As for Alsa I do not see it in the Processes tab of the System Monitor. Do I need to install it?
 
Old 10-19-2021, 02:23 PM   #37
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123
I don't know. I'm weak in my knowledge of the alsa/pulse stuff. Hopefully someone else will answer your questions.

I did not really change anything in my system regarding this. I kept testing each audio option/configuration until something worked. '-f pulse -i default' worked. '-f alsa -i default' worked. '-pulse -i {whatever the source number was}' worked. But those options gave me either out-of-sync sounds and/or had errors in their timing. They were also slow to kick in when capturing.

Then I found that quote in my previous post. Using 'hw:2' gave me much better results. Based on the result of your 'cat /proc/asound/cards' in your post #26, you'll need to change the 'AUDIO_DEVICE=hw:2' line to 'AUDIO_DEVICE=hw:1' in both of the scripts. Hopefully, that will work for you. Mine was on 2 because my system has two other audio cards/devices installed.

Try one of the scripts and see what happen.

Last edited by SW64; 10-19-2021 at 02:44 PM.
 
Old 10-21-2021, 09:05 PM   #38
borgward
Member
 
Registered: Apr 2005
Location: Austin, Texas
Distribution: Feather, Darn Small Linux
Posts: 529

Original Poster
Rep: Reputation: 21
Been taking a break to clear my mind. Fresh start this weekend. Been quite a while since I have done anything with scripts. I save the scripts to /usr/bin? I guess I should go back and review the Linuxcommand line.

What is the exclamation point for before /user/bin at the top of your script. I do realize those first 2 lines are comments.
 
Old 10-21-2021, 09:47 PM   #39
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123
Quote:
Originally Posted by borgward View Post
Been taking a break to clear my mind. Fresh start this weekend. Been quite a while since I have done anything with scripts. I save the scripts to /usr/bin? I guess I should go back and review the Linuxcommand line.
A mind break is good now and then. As for these two scripts, they can be place anywhere and they'll produce the videos on the spot. I keep mine in the Videos folder.
Quote:
What is the exclamation point for before /user/bin at the top of your script. I do realize those first 2 lines are comments.
I searched for '#!/bin/bash' and this was the first result: https://stackoverflow.com/questions/...-bin-bash-mean
 
  


Reply

Tags
capture, ffmpeg, tape, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recording from a VCR to your computer using a TV capture card. dashcloud LinuxAnswers Discussion 1 05-03-2008 06:47 PM
Can I run a VCR with my computer. heffo_j Linux - Newbie 4 04-04-2008 03:43 AM
video encoder (Tv-tuner + VCR) windowsrefugeeX Linux - Software 2 07-16-2005 05:59 PM
VCR to DVD Capture iotc247 Slackware 4 05-26-2004 08:56 AM
Digitize my VCR TAPES.... mrlucio79 Linux - Hardware 5 07-14-2003 03:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration