Score:0

ffmpeg alsa can not capture audio from UVC USB HDMI capture card to HLS server

it flag

in the same context before, I have been helped by brother ( llogan ) on Oct 15 at 16:35 , by using syntax his suggestion, and i've tried it, at first i got the sound stuttering, then it went back to silent,but for some reason I haven't accessed this blog for a long time, so communication is loss, so anyone can help me ? current condition we using syntax :

ffmpeg -f alsa -channels 2 -sample_rate 44100 -i hw:0 -f video4linux2 -i /dev/video0 -c:a aac -b:a 128k -c:v libx264 -preset veryfast -b:v 4000k -maxrate 4000k -bufsize 12000k -g 10 -vf "scale=1280:720,format=yuv420p" -f flv rtmp://localhost/show/stream

and i have informati running from ffmpeg :

[alsa @ 0x556854b35c60] ALSA buffer xrun. 
frame=  237 fps=5.0 q=13.0 size=   21447kB time=00:00:43.23 bitrate=4063.4kbits/s speed=0.9 
frame=  239 fps=5.0 q=13.0 size=   21633kB time=00:00:43.23 bitrate=4098.6kbits/s speed=0.9 
[alsa @ 0x556854b35c60] ALSA buffer xrun. 
frame=  242 fps=5.0 q=13.0 size=   21932kB time=00:00:44.23 bitrate=4061.5kbits/s speed=0.9 
frame=  244 fps=5.0 q=13.0 size=   22124kB time=00:00:44.23 bitrate=4097.1kbits/s speed=0.9

is something wrong?, and we stop the encoder have a information is :

[flv @ 0x5585283c6a40] Failed to update header with correct duration.
[flv @ 0x5585283c6a40] Failed to update header with correct filesize.
frame=428826 fps=5.0 q=-1.0 Lsize=40706449kB time=23:49:20.70 bitrate=3888.1kbits/s speed=0.958x
video:428826kB audio:767kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.025860%
[libx264 @ 0x5585283c8200] frame I:57274    Avg QP: 7.20  size:151544
[libx264 @ 0x5585283c8200] frame P:263139    Avg QP: 10.57  size:96778
[libx264 @ 0x5585283c8200] frame B:108413    Avg QP:10.50  size: 69423
[libx264 @ 0x5585283c8200] consecutive B-frames: 63.0%  7.8%  6.5% 22.7%
[libx264 @ 0x5585283c8200] mb I  I16..4: 14.2% 12.6% 73.2%
[libx264 @ 0x5585283c8200] mb P  I16..4: 12.6% 11.5% 27.5%  P16..4:  8.2% 17.2% 20.3%  0.0%  0.0% skip: 2.7%
[libx264 @ 0x5585283c8200] mb B  I16..4:  4.2%  2.4%  4.7%  B16..8: 23.7% 26.8% 14.9%  direct:14.1%  skip:9.1%  L0:36.9% L1:34.7% BI:28.4%
[libx264 @ 0x5585283c8200] 8x8 transform intra:19.5% inter:35.3%
[libx264 @ 0x5585283c8200] coded y,uvDC,uvAC intra: 83.4% 88.7% 85.2% inter: 78.4% 76.8% 46.4%
[libx264 @ 0x5585283c8200] i16 v,h,dc,p: 45% 40% 10%  5%
[libx264 @ 0x5585283c8200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 41% 12%  3%  3%  3%  5%  3%  5%
[libx264 @ 0x5585283c8200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 34%  8%  4%  6%  5%  6%  5%  6%
[libx264 @ 0x5585283c8200] i8c dc,h,v,p: 34% 35% 18% 13%
[libx264 @ 0x5585283c8200] Weighted P-Frames: Y:2.6% UV:1.9%
[libx264 @ 0x5585283c8200] kb/s:3887.06
[aac @ 0x5585283cc760] Qavg: 65536.000
s710@sensorsip:~$

We first start the ffmpg msg is :

s710@sensorsip:~$ ffmpeg -f alsa -channels 2 -sample_rate 44100 -i hw:0 -f video4linux2 -i /dev/video0 -c:a aac -b:a 128k -c:v libx264 -preset veryfast -b:v 4000k -maxrate 4000k -bufsize 12000k -g 10 -vf "scale=1280:720,format=yuv420p" -f flv rtmp://localhost/show/stream
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:0':
  Duration: N/A, start: 1635926018.864251, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Input #1, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 89255.399764, bitrate: 165888 kb/s
    Stream #1:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[alsa @ 0x5585283b2c60] ALSA buffer xrun.
[libx264 @ 0x5585283c8200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x5585283c8200] profile High, level 3.1
[libx264 @ 0x5585283c8200] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=10 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=cbr mbtree=1 bitrate=4000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=4000 vbv_bufsize=12000 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://localhost/show/stream':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p(progressive), 1280x720, q=-1--1, 4000 kb/s, 5 fps, 1k tbn, 5 tbc
    Metadata:
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 4000000/0/4000000 buffer size: 12000000 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.107.100 aac
[alsa @ 0x5585283b2c60] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)

So where is the validity huh ?, is the CPU hardware too low ? , my spec CPU is Intel i5 Gen 2, Ram 8Gb , SSD 500GB ( Futjisu lifebook S Series S710 ), OS ubuntu 18.4 ( I just started learning on Linux )

I see from VLC the captured audio codec is ADTS and static is also there, but there is no sound, If I remember correctly, when I shutdown HLS Server, at the last second there was a sound and die the stream.

I try to capture information in VLC like this : codec audio captured on VLC statistics capture on VLC

if my problem is in the hardware aspect, is it possible to add an NVEDIA GPU card with the help of using the CUDA hardware accelerator, can it be solved?

we running aplay -l and v4l2-ctl --list-device msg is :

**** List of PLAYBACK Hardware Devices ****
card 0: MID [HDA Intel MID], device 0: ALC269 Analog [ALC269 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: MID [HDA Intel MID], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: MID [HDA Intel MID], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

s710@sensorsip:~$ v4l2-ctl --list-device
USB Video: USB Video (usb-0000:00:1a.0-1.2):
        /dev/video0

USB Video: USB Video (usb-0000:00:1a.0-1.3):
        /dev/video1

USB Webcam: USB Webcam (usb-0000:00:1d.0-1.3):
        /dev/video2

we using now is USB Video 0 using command is HW:0

Thanks for your help..

regards,

Christian Hung

llogan avatar
jp flag
1) Your ffmpeg is old. [Download](https://johnvansickle.com/ffmpeg/) "git master" version (not release version), or [compile](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu) a new ffmpeg. 2) You got warning message `Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)`. Try increasing this (after upgrading), such as `ffmpeg -f alsa -channels 2 -sample_rate 44100 -thread_queue_size 128 -i hw:0 ...`. 128 is an arbitrary number just as an example: you need to experiment to find what works for you. Increase until the warning message goes away.
llogan avatar
jp flag
Also, test capturing audio with `arecord`. Does it also not work or sound bad? If yes, then problem is likely not ffmpeg.
Hung Christian avatar
it flag
Thanks your bro, tomorrow Will download and try
Hung Christian avatar
it flag
1. thanks , we can upgrade the ffmpeg to version 4,4, how to upgrade ?, can teach me ? 2. we using codec mpeg4 encoder to file mp4 also good sound, but using codec libx264 dan libx265 can not get the sound, can get, but falter can help me agian ?, thanks.
llogan avatar
jp flag
To upgrade [download](https://johnvansickle.com/ffmpeg/) ffmpeg and put in `/usr/local/bin`. Or follow [compile](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu) instructions. As for libx264 you need to test new ffmpeg before doing anything else, then try raising the thread_queue_size option. Did you test arecord yet?
Hung Christian avatar
it flag
@llogan , Last day im already upgrade my ubuntu from 18.04 to ubuntu 20.04.3 , and install back ffmpeg now version 4.2.4, but im running v4l2-ctl showing my UBS Capture card now is USB Video: USB Video (usb-0000:00:1a.0-1.3): /dev/video0 /dev/video1 how i can distinguish which one is audio and video, and what command should I use for ALSA ?, thanks for help
Hung Christian avatar
it flag
@llogan, im try running back your suggest "ffmpeg -f alsa -channels 2 -sample_rate 44100 -i hw:0 -f video4linux2 -i /dev/video0 -c:a aac -b:a 128k -c:v libx264 -preset veryfast -b:v 4000k -maxrate 4000k -bufsize 12000k -g 10 -vf "scale=1280:720,format=yuv420p" -f flv rtmp://localhost/show/stream " , and now, we can not running alsa hw:0 or hw:1 , the error msg is hw:0: protocol not found , Did you mean file:hw:0 ? , and is i using hw:1 , the msg is hw:1: protocol not found, Did you mean file:hw:1 ?, what should I do? , thanks for your help
Hung Christian avatar
it flag
just now i tried to run with command " s710@sensorsip:~$ ffmpeg -f alsa -channels 2 -sample_rate 44100 -i /dev/video0 -f video4linux2 -i /dev/video1 -c:a aac -b:a 128k -c:v libx264 -preset veryfast -b:v 4000k -maxrate 4000k -bufsize 12000k -g 10 -vf "scale=1280:720,format=yuv420p" -f flv rtmp://localhost/show/stream " , i got error msg : " [alsa @ 0x56355f45dac0] cannot open audio device /dev/video0 (No such file or directory) /dev/video0: Input/output error " , and I tried to replace the command " /dev/video0 to dev/video1 " , the result is an error is same too , please help me, thanks.
Hung Christian avatar
it flag
@llogan, sorry forget answer your questions accord test, I haven't tried it, because before I used the mpeg4 codec I could get the audio, only is im using libx264 or libx265 codecs which can't get the sound, and I've tried streaming audio only, it works (on version 18.4 ubuntu, now i don't know the command to get the device in alsa , sorry to bother you, thanks for your help again
Hung Christian avatar
it flag
me sound card device now is : s710@sensorsip:~$ arecord -l **** List of CAPTURE Hardware Devices **** card 0: MS2109_1 [MS2109], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: MS2109 [MS2109], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0 card 2: MID [HDA Intel MID], device 0: ALC269 Analog [ALC269 Analog] Subdevices: 1/1 Subdevice #0: subdevice #0
llogan avatar
jp flag
FFmpeg 4.2 release branch is old. Download or compile new version before doing anything else.
Hung Christian avatar
it flag
already install 4.4.1 the alsa encoder bitrate sound is 48000 but im setting is 44100 using hw:0 , and if im using hw:2 the encoder bitrate sound is 44100, but still not have a song , thanks
Hung Christian avatar
it flag
@llogan, looks like I've got the problem I'm facing, my capture card hw:0 in alsamixer no audio configuration detected, only show "This sound device does not have any playback controls.", but detected Card: MS2109, Chip: USB Mixer, View: F3 [Playback] , and as soon as I press F3, the result is quit alsamixer , I don't know what to do anymore, but I'll try to run from windows solution, who knows help, thanks
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.