Write two webcam video with avconv - ffmpeg

Have problem capture video with avconv
I using this commands video0 in shell 0 and video1 in shell 1
avconv -f video4linux2 -i /dev/video0 video0.avi
avconv -f video4linux2 -i /dev/video1 video1.avi
But with start second video recorder message
/dev/video1: No space left on device
Question there is the possibility of recording two videos simultaneously?
Other
First capture of video0.avi is work perfectly, but if I interrupt with Ctrl+C and try execute same command the video is not captured.
This message displayed in shell
uvcvideo: Failed to resubmit video URB (-27)
The process still running?
Removing webcam and reconnect work fine in first time.

I ran into the same issue - in my case I resolved it by connecting the webcams to separate USB2 buses. I still cannot make 2 USB webcams work simultaneously on the same bus. I have also found that I must run ffmpeg (now avconv) as root in order to capture and encode both sound and video from both cams simultaneously.
Also, I run this from a bash script, and found I must background one avconv command to run both simultaneously. The script looks like this:
nohup avconv -f video4linux2 -s 640x360 -r 30 /dev/video0 -f alsa -ac 2 -i hw:1,0 -acodec libmp3lame -ab 96k -async1 stream1.mp4
P1=$!
avconv -f video4linux2 -s 640x360 -r 30 /dev/video1 -f alsa -ac 2 -i hw:2,0 -acodec libmp3lame -ab 96k -async1 stream2.mp4
kill $P1

Related

Is there a way to add/modify/delete one of the outputs of a running ffmpeg core which has multiple ones?

The task is to stream a video feed from a webcam, watch it live on a display, then start/stop a recording of same into a file, while maintaining the live video feed.
This will record a 5-s clip (with no audio), while simultaneously watching it on the screen:
ffmpeg -v error -f v4l2 -framerate 30 -video_size 640x480 -t 5 -i /dev/video0 -an \
clip.mp4 -y -map 0:v -pix_fmt yuv420p -f xv "Capturing a 5-s clip"
however I need to surround it before and after with live display:
ffmpeg -v error -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video0 -an \
-map 0:v -pix_fmt yuv420p -f xv "Live display"
which I then kill in order to launch the recording version and re-launch when that one terminates. This creates a noticeable break as one ffmpeg dies and another launches.
This explains how to pause/resume ffmpeg process itself using
kill -s SIGSTOP <PID> and kill -s SIGCONT <PID> as needed, but what I want is to pause/resume (or start/stop) just the recording output, while keeping the display output continuous.
Another way to think about it is whether it is possible to add an extra output stream to a running ffmpeg core, and either pass a time restriction to it - so it disconnects itself when done, or have an ability to delete an output from a running ffmpeg core, without killing the other outputs.

Extracting frames from video while recording using ffmpeg

I am using ffmpeg to record a video using a Raspberry Pi with its camera module.
I would like to run a image classifier on a regular interval for which I need to extract a frame from the stream.
This is the command I currently use for recording:
$ ffmpeg -f video4linux2 -input_format h264 -video_size 1280x720 -framerate 30 -i /dev/video0 -vcodec copy -an test.h264
In other threads this command is recommended:
ffmpeg -i file.mpg -r 1/1 $filename%03d.bmp
I don't think this is intended to be used with files that are still appended to and I get the error "Cannot use -sseof, duration of test.h264 not known".
Is there any way that ffmpeg allows this?
I don't have a Raspberry Pi set up with a camera at the moment to test with, but you should be able to simply append a second output stream to your original command, as follows to get, say, 1 frame/second of BMP images:
ffmpeg -f video4linux2 -input_format h264 -video_size 1280x720 -framerate 30 -i /dev/video0 -vcodec copy -an test.h264 -r 1 frame-%03d.bmp

ffmpeg how to record and preview at the same time

I want to capture video+audio from directshow device like webcam and stream it to RTMP server. This part no problem. But the problem is that I want to be able to see the preview of it. After a lot of search someone said pipe the input using tee muxer to ffplay. but I couldn't make it work. Here is my code for streaming to rtmp server. how should I change it?
ffmpeg -rtbufsize 8196k -framerate 25 -f dshow -i video="Microsoft® LifeCam Studio(TM)":audio="Desktop Microphone (Microsoft® LifeCam Studio(TM))" -vcodec libx264 -acodec aac -strict -2 -b:v 1024k -b:a 128k -ar 48000 -s 720x576 -f flv "rtmp://ip-address-of-my-server/live/out"
Here is the final code I used and it works.
ffmpeg -rtbufsize 8196k -framerate 25 -f dshow -i video="Microsoft® LifeCam Studio(TM)":audio="Desktop Microphone (Microsoft® LifeCam Studio(TM))" -vcodec libx264 -acodec aac -strict -2 -f tee -map 0:v -map 0:a "[f=flv]rtmp://ip-address-and-path|[f=nut]pipe:" | ffplay pipe:
The core command for those running ffmpeg on a Unix-compatible system (e.g. MacOS, BSD and GNU-Linux) is really quite simple. It's to redirect or to "pipe" one of the outputs of ffmpeg to ffplay. The main problem here is that ffmpeg cannot autodetect the media format (or container) if the output doesn't have a recognizable file extension such as .avi or .mkv.
Therefore you should specify the format with the option -f. You can list the available choices for option -f with the ffmpeg -formats command.
In the following GNU/Linux command example, we record from an input source named /dev/video0 (possibly a webcam). The input source can also be a regular file.
ffmpeg -i /dev/video0 -f matroska - filename.mkv | ffplay -i -
A less ambiguous way of writing this for non-Unix users would be to use the special output specifier pipe.
ffmpeg -i /dev/video0 -f matroska pipe:1 filename.mkv | ffplay -i pipe:0
The above commands should be enough to produce a preview. But to make sure that you get the video and audio quality you want, you also need to specify, among other things, the audio and video codecs.
ffmpeg -i /dev/video -c:v copy -c:a copy -f matroska - filename.mkv | ffplay -i -
If you choose a slow codec like Google's AV1, you'd still get a preview, but one that stutters.

recording live video stream from tv card using ffmpeg in windows

I want to capture thumbnail every 1 second from tv card(tv signal) using ffmpeg in windows.
first of all, to record live video from tv card, I tried below.
ffmpeg -f dshow -i video="SKYTV HD USB Maxx Video Capture" -r 20 -threads 0 D://test.mkv
But it didn't work.
the Error message is
"[dshow#000000000034d920] Could not run filter
video=SKYTV HD USB Maxx Video Capture: Input/output error"
I use the device called 'SKYTV HD USB Maxx Video Capture' for getting tv signal(TV card).
(people usually suggest "ffmpeg -f oss -i dev/dsp -f video4linux2 -i dev/video0/tmp/out.mpg"
but I dont think it works at window. this is the error message i got: "Unknown input format: 'video4linux2'")
what should i do to record live video and get thumbnail every 1 second from tv card(tv signal) using ffmpeg in window?
Please help..!
First be sure that the video label you use is really the label return by:
ffmpeg -list_devices true -f dshow -i dummy
More info here
But another solution should be ti use the old "Video For Windows" (VFW).
To try that, list your device with:
ffmpeg -y -f vfwcap -i list
And use your device number as value of the -ioption:
ffmpeg -y -f vfwcap -r 25 -i 0 out.mp4
And if finally you are able to record your stream, there is different options, but in your case everything is clear describe here
ffmpeg -y -f vfwcap -r 25 -i 0 -f image2 -vf fps=fps=1 out%d.jpg

recording sound from webcam using ffmpeg

Using ffmpeg arecord -L, I am able to identify my Logitech usb webcam as:
hw:CARD=U0x46d0x821,DEV=0
USB Device 0x46d:0x821, USB Audio
Direct hardware device without any conversions
plughw:CARD=U0x46d0x821,DEV=0
USB Device 0x46d:0x821, USB Audio
Hardware device with all software conversions
when I go into /dev/snd/by-id, the webcam is described as:
usb-046d_0821_6813BFD0-00 -> ../controlC1
I know that the command to use a sound device in ffmpeg is
ffmpeg -f alsa -i $ALSA_DEVICE_NAME..
I have tried
ffmpeg -f alsa -i "hw:CARD=U0x46d0x821,DEV=0"
and
ffmpeg -f alsa -i "plughw:CARD=U0x46d0x821,DEV=0"
and in both cases I receive the same error message:
ALSA lib pcm.c:2208:(snd_pcm_open_noupdate) Unknown PCM hw=CARD=U0x46d0x821,DEV=0
[alsa # 0x9c96580] cannot open audio device hw=CARD=U0x46d0x821,DEV=0 (No such file or directory)
hw:CARD=U0x46d0x821,DEV=0: Input/output error
I have also tried:
ffmpeg -f alsa -i "usb-046d_0821_6813BFD0-00"
and
ffmpeg -f alsa -i "usb-046d_0821_6813BFD0-00,DEV=0"
and have still received error message
Could you please help in formulating the correct format of the command
I have finally been able to use the sound portion of the webcam under ffmpeg. The correct way to do it is NOT to enclose the hardware value in quotes. Do not enclose the hardware in quotes:
ffmpeg -f alsa -i plughw:CARD=U0x46d0x821,DEV=0
instead of:
ffmpeg -f alsa -i "plughw:CARD=U0x46d0x821,DEV=0"
I hope this helps someone else.
Maybe this works:
ffmpeg -f alsa -r 16000 -i hw:2,0 -f video4linux2 -s 800x600 -i /dev/video0 -r 30 -f avi -vcodec mpeg4 -vtag xvid -sameq -acodec libmp3lame -ab 96k output.avi
Source

Resources