ffmpeg: Could not find audio only device - audio

I'm trying to record something off my sound card through ffmpeg, but it refuses to work.
So I first got the list of my devices.
ffmpeg -list_devices true -f dshow -i dummy
[dshow # 00000228d837f240] "Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio)" (audio)
[dshow # 00000228d837f240] Alternative name "#device_cm_{33D9A762-90C8-1"1D0-BD43-00A0C911CE86}\wave_{B7E10DA0-B1E9-4930-8E38-90AECFE61349}
Then I try to get an input working.
ffmpeg -rtbufsize 1702000k -f dshow -audio_pin_name 1 -channels 2 -sample_rate 48000 -acodec pcm_s16le -i audio="Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio)" -c copy -f wav
However, I get an error message.
Trailing option(s) found in the command: may be ignored.
[dshow # 0000025b849efa80] Could not set audio only options
[dshow # 0000025b849efa80] Searching for audio device within video devices for Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio)
[dshow # 0000025b849efa80] Could not find audio only device with name [Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio)] among source devices of type video.
audio=Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio): I/O error
Don't know why it's saying it can't find an audio only device with that name when there's clearly an audio only device with that name. Tried truncating the name as well, and it didn't work either. Is there a fix for this? I'm running ffmpeg version N-105384-g6a86dd1172-ge102fd98d6+3.

The error is somewhat misleading by saying "Could not find audio only device with name...". You need to pay attention only to the first error: [dshow # 0000025b849efa80] Could not set audio only options.
Some of your options/option values are not supported by your device.
For example, I've tested on my webcam mic, and it does not like -audio_pin_name 1 and -sample_rate 48000. Other options went through fine. Then I changed -sample_rate to 44100 and that option went though.
So you need to figure out which options and what values are supported by your device.
To get supported options, run
ffmpeg -list_options true \
-i audio="Digital Audio (S/PDIF) (2- Sound Blaster X-Fi Xtreme Audio)"
One more tidbit based on my device, which should support
[dshow # 000002163918c080] ch= 1, bits=16, rate= 48000
[dshow # 000002163918c080] ch= 2, bits=16, rate= 48000
[dshow # 00000170bfc1c080] ch= 2, bits=16, rate= 96000
[dshow # 00000170bfc1c080] ch= 1, bits=16, rate= 96000
But I cannot set -sample_rate 48000 or 96000. I don't know if DirectShow is misreporting the mic's capability or there is a bug in FFmpeg dshow device. But be aware of this possibility.

Related

Can I force arecord to record with a certain sampling rate if my sound card allows it?

I am using arecord to record audio using a USB microphone that allows recording up to 384k sampling rate. With Audacity I can easily record with other lower sampling rates (48k, 44.1k ..) but when I use:
arecord -vD hw:4,0 -f S16_LE -d 120 -r 48000 -c 1 sample.wav
It displays a warning message:
Warning: rate is not accurate (requested = 48000Hz, got = 384000Hz)
And records with 384000Hz.
I can't get to fix this.

How to change mjpeg to yuyv422 from a webcam to a v4l2loopback?

Backstory: One livestreaming site I use isn't smart enough to detect the capabilities of my webcam (Logitech Brio, 4k), and instead just uses the default frames per second settings, which is 5fps.
(full solution walk-through in the answer)
The best solution I could think of (besides changing livestream providers) was to create a loopback virtual webcam using v4l2loopback that I could force to have the exact settings I wanted to use on that livestream site.
For the brio, the higher frame rates come with mjpeg, not the default yuyv.
Problem 1:
I could easily read mjpeg, but unfortunately kept banging my head against the wall because v4l2loopback evidently only wanted yuyv.
I tried things like:
ffmpeg -f v4l2 \
-input_format mjpeg \
-framerate 30 \
-video_size 1280x720 \
-i /dev/video0 \
-vcodec copy \
-f v4l2 /dev/video6
and
ffmpeg -f v4l2 \
-input_format mjpeg \
-framerate 30 \
-video_size 1280x720 \
-i /dev/video0 \
-vcodec yuyv422 \ # this line changed (even tried "copy")
-f v4l2 /dev/video6
But they wouldn't work. I got errors like:
Unknown V4L2 pixel format equivalent for yuvj422p
and
...deprecated pixel format used, make sure you did set range correctly...
...V4L2 output device supports only a single raw video stream...
Eventually I got this to work:
ffmpeg -f v4l2 \
-input_format mjpeg \
-framerate 30 \
-video_size 1280x720 \
-i /dev/video0 \
-pix_fmt yuyv422 \ # The winning entry
-f v4l2 /dev/video6
Problem 2
The next problem was getting chrome to see the virtual webcam. It worked correctly with guvcview, and on firefox I could use webcam testing sites and it would pick the virtual camera up without a problem.
Turns out google, in it's overly-protective nature (while it's siphoning off all our data, btw), doesn't want to use webcams that can be read and written to.
So when starting v4l2loopback you have to tell it to announce that it's "read only" to consumers like chrome.
Here's the exact modprobe I use that works:
sudo modprobe v4l2loopback devices=1 exclusive_caps=1
Exact solution.
1. Figure out which webcam is the correct input webcam
Use v4l2-ctl to list all the webcams:
v4l2-ctl --list-devices
My output is this (yours will vary, I'll use mine as an example as I go):
Logitech BRIO (usb-0000:00:14.0-5.2):
/dev/video0
/dev/video1
HP HD Camera: HP HD Camera (usb-0000:00:14.0-9):
/dev/video2
/dev/video3
/dev/video4
/dev/video5
In this case my brio is video0.
2. Start v4l2loopback:
sudo modprobe v4l2loopback devices=1 exclusive_caps=1
3. Confirm your loopback device:
v4l2-ctl --list-devices
Mine now shows this, indicating video6 is the loopback:
Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video6
Logitech BRIO (usb-0000:00:14.0-5.2):
/dev/video0
/dev/video1
HP HD Camera: HP HD Camera (usb-0000:00:14.0-9):
/dev/video2
/dev/video3
/dev/video4
/dev/video5
4. Determine your optimal input settings
Use guvcview to figure out which codec gives you the resolution and framerate you're looking for (you may have to use the menu -> Video -> Video Codec -> Raw camera input).
I got 60fps using mjpeg, I only needed 30. The default yuyv gave a miserable 5fps.
Now use ffmpeg to list the capabilities of the camera and get the matching codec:
ffmpeg -f v4l2 -list_formats all -i /dev/video0 #use your camera here from step 2
In the output you'll see something like this:
[video4linux2,v4l2 # 0x55f1a4e989c0] Raw : yuyv422 : YUYV 4:2:2 : 640x480 160x120 176x144 320x180 320x240 352x288 340x340 424x240 440x440 480x270 640x360 800x448 800x600 848x480 960x540 1024x576 1280x720 1600x896 1920x1080
[video4linux2,v4l2 # 0x55f1a4e989c0] Compressed: mjpeg : Motion-JPEG : 640x480 160x120 176x144 320x180 320x240 352x288 424x240 480x270 640x360 800x448 800x600 848x480 960x540 1024x576 1280x720 1600x896 1920x1080
In my case it was the mjpeg that gave the best output in guvcview, and that was the exact name of the codec (as indicated above).
5. Start ffmpeg using that input codec and changing the pixel format to yuyv:
ffmpeg -f v4l2 \
-input_format mjpeg \
-framerate 30 \
-video_size 1280x720 \
-i /dev/video0 \
-pix_fmt yuyv422 \
-f v4l2 /dev/video6
Update the video size to the highest size your livestream/video record will support, as long as your camera also supports it.
Now when you want to livestream, just use the camera labeled "Dummy"

FFmpeg - how to set output sample_size

Trying to create a simple command line player for .dsf (DSD audio) files, and output to an alsa device that supports up to 24-bit 192 kHz sample rate. The following command almost works and it does play the track. Examining the bold text below, the dsf input file is converted to 24-bit/192 kHz, but the output is then truncated to 16-bit 192 kHz (pcm_s16le i.e, 16 bit little endian).
ffmpeg -i '01 - Sweet Georgia Brown.dsf' -f alsa hw:0,0
After displaying the ffmpeg banner and song metadata (tags), here is the result, bold is my emphasis:
Duration: 00:05:14.83, start: 0.000000, bitrate: 9234 kb/s
Stream #0:0: Audio: flac, 192000 Hz, stereo, s32 (24 bit)
Stream mapping:
Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, alsa, to 'hw:0,0':
Since I can play this and many other tracks at full resolution using another player (foobar2000) it seems there might be an option in the encoder which is part of FFmpeg: Lavf57.83.100 I can find no information in any of the FFmpeg documentation that helps. Tried finding options in FFplay and even guessing using other FFmpeg options like this example.
ffmpeg -sample_fmt s24 -i '01 - Sweet Georgia Brown.dsf' -f alsa hw:0,0 ***** same results.
I'm stuck. Any suggestions?
Environment: Linux Mint 19.2, 64-bit, ASUS Xonar STXii sound card.
Each output format or device has a default encoder registered for each media type it accepts. ALSA accepts audio and its default encoder is 16-bit signed PCM.
You can change the encoder by specifying one.
ffmpeg -i '01 - Sweet Georgia Brown.dsf' -c:a pcm_s24le -f alsa hw:0,0

Linux command to display webcam video output in full screen?

I'm using an rpi1 (running raspbian lite and jwm) with a USB webcam hooked to a CRT TV to display its output. Up until now I've been using Camorama which works nicely, but I lose some of the measly 640x480 screen resolution for the title bar of the app, and also some of it below due to the window manager showing buttons etc that I don't need. Is there any way I can simply show up the video output of the device in a full screen window? so I can just add it to the startup of the window manager and run it on top of it. I really don't need any of the features that Camorama has because all I want is to display video ala security camera.
Display webcam output from Linux
Note: Adjust with and height where necessary
mplayer tv:// -tv driver=v4l:width=352:height=288
or
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2
How to Record a Screencast & Convert it to an mpeg
ffmpeg -f x11grab -r 25 -s 640x480 -i :0.0 /tmp/VideoOutput.mpg
Record audio and video from webcam using ffmpeg
Record webcam audio using ALSA, MP3 encoded & video as MPEG-4.
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 myVideo.avi
Hope this helps.

mplayer output 4 audio channels to jack

I am struggling with getting mplayer to reproduce a 4 audio channel wav file.
I created a 4chn audio file.
Want mplayer to player, and output it to jack.
The problem is that i am only able to get in jack 2 mplayer channels.
if I do:
mplayer -ao jack -channels 4 test_4chan_2.wav
mplayer plays and responds:
laying test_4chan_2.wav.
libavformat version 54.6.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 4 ch, s16le, 2822.4 kbit/100.00% (ratio: 352800->352800)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [jack] 44100Hz 2ch floatle (4 bytes per sample)
Video: no video
Starting playback...
and jack has only the following outputs:
system:capture_1
system:capture_2
system:playback_1
system:playback_2
MPlayer [14434]:out_0
MPlayer [14434]:out_1
So it seems that mplayer recognizes that the input file as 4ch
but on AO: [jack] only 2ch appear
if I try the same with ecasound:
ecasound -f 16,4,44100 -i test_4chan_2.wav -o jack
in Jack ecasoud appears with 4 outputs
system:capture_1
system:capture_2
system:playback_1
system:playback_2
ecasound:out_1
ecasound:out_2
ecasound:out_3
ecasound:out_4
Do you have any idea of what could I be doing wrong??
I am running Debian (Jessy) and mplayer 1.1-4.7
Thanks a lot
Solved. Only need to upgrade mplayer to 4.8, in Debian Sid.
And
mplayer -channels 4 -ao jack:noconnect 4chn_file.wav
did the trick.
The -ao jack:noconnect means:
-ao audio-output: jack
noconnect: prevent mplayer to make 1-to-1 connections. As I have 2 different stereo audio sound cards, mplayer was only giving me 2 channels. And this option disables that start behavior.
hope it will be of help to someone else ,)

Resources