delay time in live ultrasound converter
Hello, I'm using the following batch file (Windows 7) for a live ultrasound conversion. set "SR=44100" :: Sample rate set "F=14000" :: Subtracted frequency set "VOL=10" :: Volume factor set /a "N=4096*%F%/%SR%" :: N = 4096 * F / SR c:\ffmpeg\ffmpeg -f dshow -sample_rate %SR% -sample_size 16 -channels 2 -i audio="Microphone (SoundMAX Integrated" -af volume=%VOL%,afftfilt='real=if(lt(b+%N%,nb),real(b+%N%,ch),0)':'imag=if(lt(b+%N%,nb),imag(b+%N%,ch),0)' -f nut - | c:\ffmpeg\ffplay - FFmpeg gets the audio input from the computer's microphone input and passes the converted output to FFplay. This works fine for hearing bats, but it has about 1-2 seconds delay between input and output. Are there any options for minimizing the delay? The console output is copied below. Thanks, Michael C:\Users\mkoch\Desktop\Ultrasound Live>c:\ffmpeg\ffmpeg -f dshow -sample_rate 44 100 -sample_size 16 -channels 2 -i audio="Microphone (SoundMAX Integrated" -af v olume=10,afftfilt='real=if(lt(b+1300,nb),real(b+1300,ch),0)':'imag=if(lt(b+1300, nb),imag(b+1300,ch),0)' -f nut - | c:\ffmpeg\ffplay - ffmpeg version N-92857-g3e461f9d4c Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8.2.1 (GCC) 20181201 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi g --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-lib freetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amr wb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy -- enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-l ibwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 -- enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --en able-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --en able-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --e nable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enab le-avisynth --enable-libopenmpt libavutil 56. 25.100 / 56. 25.100 libavcodec 58. 42.104 / 58. 42.104 libavformat 58. 25.100 / 58. 25.100 ffplay version N-92857-g3e461f9d4c libavdevice 58. 6.101 / 58. 6.101 Copyr ight (c) 2003-2018 the FFmpeg developers libavfilter 7. 46.101 / 7. 46.101 built with gcc 8.2.1 (GCC) 20181201 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi g --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-lib freetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amr wb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy -- enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-l ibwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 -- enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --en able-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --en able-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --e nable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enab le-avisynth --enable-libopenmpt libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 libavutil 56. 25.100 / 56. 25.100 libavcodec 58. 42.104 / 58. 42.104 libavformat 58. 25.100 / 58. 25.100 libavdevice 58. 6.101 / 58. 6.101 libavfilter 7. 46.101 / 7. 46.101 libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 Guessed Channel Layout for Input Stream #0.0 : stereo 0B f=0/0 Input #0, dshow, from 'audio=Microphone (SoundMAX Integrated': Duration: N/A, start: 1701.243000, bitrate: 1411 kb/s Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s Stream mapping: Stream #0:0 -> #0:0 (pcm_s16le (native) -> vorbis (libvorbis)) Press [q] to stop, [?] for help Output #0, nut, to 'pipe:': aq= 0KB vq= 0KB sq= 0B f=0/0 Metadata: encoder : Lavf58.25.100 Stream #0:0: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 44100 Hz, stereo , fltp Metadata: encoder : Lavc58.42.104 libvorbis Input #0, nut, from 'pipe:': Metadata: encoder : Lavf58.25.100 Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Audio: vorbis (oV[0][0] / 0x566F), 44100 Hz, stereo, fltp Metadata: encoder : Lavc58.42.104 libvorbis 16.27 M-A: 0.000 fd= 0 aq= 3KB vq= 0KB sq= 0B f=0/0
On Thu, Aug 22, 2019 at 7:07 PM Michael Koch <astroelectronic@t-online.de> wrote:
Hello,
I'm using the following batch file (Windows 7) for a live ultrasound conversion.
set "SR=44100" :: Sample rate set "F=14000" :: Subtracted frequency set "VOL=10" :: Volume factor set /a "N=4096*%F%/%SR%" :: N = 4096 * F / SR
c:\ffmpeg\ffmpeg -f dshow -sample_rate %SR% -sample_size 16 -channels 2 -i audio="Microphone (SoundMAX Integrated" -af volume=%VOL%,afftfilt='real=if(lt(b+%N%,nb),real(b+%N%,ch),0)':'imag=if(lt(b+%N%,nb),imag(b+%N%,ch),0)'
-f nut - | c:\ffmpeg\ffplay -
FFmpeg gets the audio input from the computer's microphone input and passes the converted output to FFplay. This works fine for hearing bats, but it has about 1-2 seconds delay between input and output. Are there any options for minimizing the delay?
ffplay and using pipe gives you huge delay. By using mpv and filtergraph directly you would get much lesser delay. Default delay introduced by this filter is the one set by win_size in number of samples, which is by default 4096. If you need less delay even than this one and can not use lower win_size because of lesser precision use amultiply solution which inherently have 0 delay. Consult documentation of this filter for more info.
The console output is copied below.
Thanks, Michael
C:\Users\mkoch\Desktop\Ultrasound Live>c:\ffmpeg\ffmpeg -f dshow -sample_rate 44 100 -sample_size 16 -channels 2 -i audio="Microphone (SoundMAX Integrated" -af v
olume=10,afftfilt='real=if(lt(b+1300,nb),real(b+1300,ch),0)':'imag=if(lt(b+1300, nb),imag(b+1300,ch),0)' -f nut - | c:\ffmpeg\ffplay - ffmpeg version N-92857-g3e461f9d4c Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181201 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi g --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-lib freetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amr wb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy -- enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-l ibwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 -- enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --en able-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --en able-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --e nable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enab le-avisynth --enable-libopenmpt libavutil 56. 25.100 / 56. 25.100 libavcodec 58. 42.104 / 58. 42.104 libavformat 58. 25.100 / 58. 25.100 ffplay version N-92857-g3e461f9d4c libavdevice 58. 6.101 / 58. 6.101 Copyr ight (c) 2003-2018 the FFmpeg developers
libavfilter 7. 46.101 / 7. 46.101 built with gcc 8.2.1 (GCC) 20181201
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi g --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-lib freetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amr wb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy -- enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-l ibwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 -- enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --en able-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --en able-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --e nable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enab le-avisynth --enable-libopenmpt libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 libavutil 56. 25.100 / 56. 25.100 libavcodec 58. 42.104 / 58. 42.104 libavformat 58. 25.100 / 58. 25.100 libavdevice 58. 6.101 / 58. 6.101 libavfilter 7. 46.101 / 7. 46.101 libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 Guessed Channel Layout for Input Stream #0.0 : stereo 0B f=0/0 Input #0, dshow, from 'audio=Microphone (SoundMAX Integrated': Duration: N/A, start: 1701.243000, bitrate: 1411 kb/s Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s Stream mapping: Stream #0:0 -> #0:0 (pcm_s16le (native) -> vorbis (libvorbis)) Press [q] to stop, [?] for help Output #0, nut, to 'pipe:': aq= 0KB vq= 0KB sq= 0B f=0/0 Metadata: encoder : Lavf58.25.100 Stream #0:0: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 44100 Hz, stereo , fltp Metadata: encoder : Lavc58.42.104 libvorbis Input #0, nut, from 'pipe:': Metadata: encoder : Lavf58.25.100 Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Audio: vorbis (oV[0][0] / 0x566F), 44100 Hz, stereo, fltp Metadata: encoder : Lavc58.42.104 libvorbis 16.27 M-A: 0.000 fd= 0 aq= 3KB vq= 0KB sq= 0B f=0/0 _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
Hello Paul,
ffplay and using pipe gives you huge delay. By using mpv and filtergraph directly you would get much lesser delay. Default delay introduced by this filter is the one set by win_size in number of samples, which is by default 4096. If you need less delay even than this one and can not use lower win_size because of lesser precision use amultiply solution which inherently have 0 delay.
In my test the FFT method has a shorter delay time than the amultiply method. I just found out that the delay can be minimized by setting -audio_buffer_size to a very small value (10ms). Delay is now about 0.5 seconds. Short enough to see and hear the bats simultaneously. Michael
On Thu, Aug 22, 2019 at 3:16 PM Michael Koch <astroelectronic@t-online.de> wrote:
Hello Paul,
ffplay and using pipe gives you huge delay. By using mpv and filtergraph directly you would get much lesser delay. Default delay introduced by this filter is the one set by win_size in number of samples, which is by default 4096. If you need less delay even than this one and can not use lower win_size because of lesser precision use amultiply solution which inherently have 0 delay.
In my test the FFT method has a shorter delay time than the amultiply method. I just found out that the delay can be minimized by setting -audio_buffer_size to a very small value (10ms). Delay is now about 0.5 seconds. Short enough to see and hear the bats simultaneously.
Se also https://trac.ffmpeg.org/wiki/DirectShow#BufferingLatency GL! :)
Am 18.04.2020 um 00:54 schrieb Roger Pack:
In my test the FFT method has a shorter delay time than the amultiply method. I just found out that the delay can be minimized by setting -audio_buffer_size to a very small value (10ms). Delay is now about 0.5 seconds. Short enough to see and hear the bats simultaneously. Se also https://trac.ffmpeg.org/wiki/DirectShow#BufferingLatency
Yes, that's the same that I found out some time ago by try and error. In the above article is mentioned a "-rtbufsize" parameter. I can't find any documentation for it in ffmpeg-all.html Michael
Am 18.04.2020 um 08:41 schrieb Michael Koch:
Am 18.04.2020 um 00:54 schrieb Roger Pack:
In my test the FFT method has a shorter delay time than the amultiply method. I just found out that the delay can be minimized by setting -audio_buffer_size to a very small value (10ms). Delay is now about 0.5 seconds. Short enough to see and hear the bats simultaneously. Se also https://trac.ffmpeg.org/wiki/DirectShow#BufferingLatency
Yes, that's the same that I found out some time ago by try and error. In the above article is mentioned a "-rtbufsize" parameter. I can't find any documentation for it in ffmpeg-all.html
I just realized that it's in the documentation without the leading minus sign. Michael
The subject line about ultrasound caught me eye on this thread that woke up from last year. Can anyone tell us what the original interest in ffmpeg and ultrasound is? Thank you! On Fri, Apr 17, 2020 at 3:55 PM Roger Pack <rogerdpack2@gmail.com> wrote:
On Thu, Aug 22, 2019 at 3:16 PM Michael Koch <astroelectronic@t-online.de> wrote:
Hello Paul,
ffplay and using pipe gives you huge delay. By using mpv and
filtergraph
directly you would get much lesser delay. Default delay introduced by this filter is the one set by win_size in number of samples, which is by default 4096. If you need less delay even than this one and can not use lower win_size because of lesser precision use amultiply solution which inherently have 0 delay.
In my test the FFT method has a shorter delay time than the amultiply method. I just found out that the delay can be minimized by setting -audio_buffer_size to a very small value (10ms). Delay is now about 0.5 seconds. Short enough to see and hear the bats simultaneously.
Se also https://trac.ffmpeg.org/wiki/DirectShow#BufferingLatency GL! :) _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
Am 18.04.2020 um 16:52 schrieb Michael Glenn Williams:
The subject line about ultrasound caught me eye on this thread that woke up from last year. Can anyone tell us what the original interest in ffmpeg and ultrasound is?
Well, you can use FFmpeg to convert ultrasound to lower frequencies, for example if you want to hear bats. I have described that in my book, see chapters 3.14 and 3.19 (but the chapter numbers may change in future) www.astro-electronic.de/FFmpeg_Book.pdf Michael
I don't know where I can find bats nearby so I couldn't try it but how does it work? The book makes it sound like you can use any mic, even one built into a laptop for this? I suppose that's plausible looking at a typical mic's frequency response graph, they are just cut off at 20khz, and don't roll off after 20khz like I thought they would, but what about the sample rate? At 44.1kHz doesn't that mean anything over 22khz is more aliasing or harmonic distortion than an actual recording of bat sounds? On Sat, Apr 18, 2020 at 11:37 AM Michael Koch <astroelectronic@t-online.de> wrote:
Am 18.04.2020 um 16:52 schrieb Michael Glenn Williams:
The subject line about ultrasound caught me eye on this thread that woke up from last year. Can anyone tell us what the original interest in ffmpeg and ultrasound is?
Well, you can use FFmpeg to convert ultrasound to lower frequencies, for example if you want to hear bats. I have described that in my book, see chapters 3.14 and 3.19 (but the chapter numbers may change in future) www.astro-electronic.de/FFmpeg_Book.pdf
Michael _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
Am 18.04.2020 um 18:25 schrieb Ted Park:
I don't know where I can find bats nearby so I couldn't try it but how does it work? The book makes it sound like you can use any mic, even one built into a laptop for this? I suppose that's plausible looking at a typical mic's frequency response graph, they are just cut off at 20khz, and don't roll off after 20khz like I thought they would, but what about the sample rate? At 44.1kHz doesn't that mean anything over 22khz is more aliasing or harmonic distortion than an actual recording of bat sounds?
The sounds of those bats that I did record were in the 12kHz to 15kHz range. 44.1kHz sample rate is sufficient. I did use two Rode NT1 microphones, connected to a Tascam DR-70D recorder. If I record the ultrasound in the recorder, I use 48kHz sample rate. If live processing is required, I connect the Tascam's output to my notebook's audio input, which has only 44.1kHz sample rate. That works as well. It is important that you disable the low pass filter in the Windows control panel (properties of the microphone). Michael
Wow that is so cool! Will ffmpeg generate ultrasound sounds to, or do we know of a plugin or other that could do that, then feed the signal to ffmpeg? Thank you! On Sat, Apr 18, 2020 at 9:48 AM Michael Koch <astroelectronic@t-online.de> wrote:
Am 18.04.2020 um 18:25 schrieb Ted Park:
I don't know where I can find bats nearby so I couldn't try it but how does it work? The book makes it sound like you can use any mic, even one built into a laptop for this? I suppose that's plausible looking at a typical mic's frequency response graph, they are just cut off at 20khz, and don't roll off after 20khz like I thought they would, but what about the sample rate? At 44.1kHz doesn't that mean anything over 22khz is more aliasing or harmonic distortion than an actual recording of bat sounds?
The sounds of those bats that I did record were in the 12kHz to 15kHz range. 44.1kHz sample rate is sufficient. I did use two Rode NT1 microphones, connected to a Tascam DR-70D recorder. If I record the ultrasound in the recorder, I use 48kHz sample rate. If live processing is required, I connect the Tascam's output to my notebook's audio input, which has only 44.1kHz sample rate. That works as well. It is important that you disable the low pass filter in the Windows control panel (properties of the microphone).
Michael
_______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
Am 18.04.2020 um 19:30 schrieb Michael Glenn Williams:
Wow that is so cool! Will ffmpeg generate ultrasound sounds to, or do we know of a plugin or other that could do that, then feed the signal to ffmpeg?
Sure, you can generate ultrasound with FFmpeg. Try the first example in chapter 3.24. Of course, the frequency must be smaller than half the sample rate. Make a 12kHz sine file and then try to convert it down to 2kHz. Michael
participants (5)
-
Michael Glenn Williams -
Michael Koch -
Paul B Mahol -
Roger Pack -
Ted Park