FFmpeg - frame delays double after the audio was added - ffmpeg

single video delays 49ms
ffmpeg -rtbufsize 100M -f dshow -i video="Logitech HD Webcam C270" -vcodec libx264 -r 30-g 5 -preset:v ultrafast -tune:v zerolatency -f rtsp rtsp://127.0.0.1:80/live/test
The delay was 100 ms after adding audio.
ffmpeg -rtbufsize 100M -f dshow -i video="Logitech HD Webcam C270":audio="麦克风 (HD Webcam C270)" -vcodec libx264 -g 5 -r 30 -acodec aac -preset:v ultrafast -tune:v zerolatency -f rtsp rtsp://127.0.0.1:80/live/tao
Is it normal? Is there any solution to reduce the delay?

Related

Pushing Live Smooth Streaming multi track audio to Azure Media Services with FFMPEG

Does anyone has a working command line for FFMPEG that shows how to stream audio from multiple devices (sound cards) using Smooth Ingest and a Basic Pass-through channel type (the cheapest option on Azure Media Services)?
The command should allow me to show multiple audio tracks (with language identifiers) using the Azure Media Player demo site (http://ampdemo.azureedge.net).
Appreciate any help.
I have tried many many examples with no success...
I have this example FFMPEG ingest for Smooth that you can try to play with. First, if you are working on Windows, you will want to list all of your DirectShow devices to get the inputs that are available. Otherwise, follow the usual ffmpeg directions for devices on other OS's.
ffmpeg -list_devices true -f dshow -i dummy
Then you can play around with this sample command line and see if you can match up your audio inputs.
Video and Audio with GoPro need to set rtbufsize to large value and I had to play around with the audio offset delay (-itsoffset) to get av sync correct.
ffmpeg -y -hide_banner -f dshow -fflags nobuffer -i audio="Headset Microphone (Logitech Stereo H650e)" -itsoffset 1.00 -f dshow -fflags nobuffer -rtbufsize 2000M -i video="GoPro Webcam" -map 0:0 -map 1:0 -c:a:0 aac -b:a:0 192k -c:v:1 libx264 -preset ultrafast -tune zerolatency -s:v:0 1280x720 -r 30-g 48 -keyint_min 48 -sc_threshold 0 -minrate:v:0 3000k -maxrate:v:0 3000k -b:v:0 3000k -f ismv -movflags isml+frag_keyframe -frag_duration 1600000 "http://<YOURCHANNEL>-nimbuspm-uswe.channel.media.azure.net/<CHANNEL_ID>/ingest.isml/Streams(video)"
I got this to work nicely with my laptop microphone, and my USB Logitec headset audio. I set one track to "english" and the other to "spanish" so it shows up in the dropdown list in the Azure Media Player demo site (ampdemo.azureedge.net). I still had to mess around with the AVSync setting (-itsoffset) a bit to make it look right.
ffmpeg -y -hide_banner -f dshow -fflags nobuffer -rtbufsize 15M -i audio="Microphone Array (Synaptics Audio)" -f dshow -fflags nobuffer -i audio="Headset Microphone (Logitech Stereo H650e)" -itsoffset 1.00 -f dshow -fflags nobuffer -rtbufsize 2000M -i video="GoPro Webcam" -map 0:a:0 -map 1:a:0 -map 2:v:0 -metadata:s:a:0 language=eng -metadata:s:a:1 language=spa -c:a:0 aac -b:a:0 192k -c:a:1 aac -b:a:1 192k -c:v:2 libx264 -preset ultrafast -tune zerolatency -s:v:0 1280x720 -r 30 -g 48 -keyint_min 48 -sc_threshold 0 -minrate:v:0 3000k -maxrate:v:0 3000k -b:v:0 3000k -f ismv -movflags isml+frag_keyframe -frag_duration 1600000 "http://<YOURCHANNEL>-nimbuspm-uswe.channel.media.azure.net/<CHANNEL_ID>/ingest.isml/Streams(video)"
To do screen recording, depending on what OS you are on, there are many ways to do that - Capture Windows screen with ffmpeg
ffmpeg -y -hide_banner -f dshow -fflags nobuffer -i audio="Headset Microphone (Logitech Stereo H650e)" -itsoffset 1.00 -f gdigrab -framerate 10 -offset_x 0 -offset_y 0 -video_size 1920x1080 -show_region 1 -i desktop -map 0:0 -map 1:0 -c:a:0 aac -b:a:0 192k -c:v:1 libx264 -preset ultrafast -tune zerolatency -s:v:0 1280x720 -r 30 -g 48 -keyint_min 48 -sc_threshold 0 -minrate:v:0 3000k -maxrate:v:0 3000k -b:v:0 3000k -f ismv -movflags isml+frag_keyframe -frag_duration 1600000 "http://<YOURCHANNEL>-nimbuspm-uswe.channel.media.azure.net/<CHANNEL_ID>/ingest.isml/Streams(video)"
I created a new page of example command lines in our Javascript/Node.js SDK sample repo up here:
https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Live/FFmpeg/ffmpeg_commands.md
I gathered up as many samples as I could locate right now. Feel free to add or suggest more if you come up with any good ones.

FFMPEG tee muxer giving "Output file #0 does not contain any stream"

I am trying to create two streams: one is mpegts UDP stream another - rtmp to Twitch servers.
This command works:
ffmpeg -threads:v 2 -threads:a 16 -filter_threads 2 -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k -map 0:v:0 -f mpegts udp://127.0.0.1:5555 \
-pix_fmt yuv420p -c:v libx264 -crf 20 -tune zerolatency -f flv rtmp://live-fra05.twitch.tv/app/stream_key
But it requires double the encoding CPU power.
So, following this, I rewrote the command like this:
ffmpeg -threads:v 2 -threads:a 16 -filter_threads 2 -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k \
-f tee "[select=\'0:v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'0:v:0,1:a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key"
By writing -f tee "[select=\'0:v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'0:v:0,1:a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key", I mean:
create UDP stream at udp://127.0.0.1:5555 and only include video stream from "Decklink Video Capture"
create RTMP stream where we include the same video stream as above and also the audio stream from "Decklink Audio Capture"
I get the error message:
Output file #0 does not contain any stream
How do I fix this? I assume I made a mistake in the command.
As the link shows, streams have to be mapped.
ffmpeg -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-map 0:v -map 1:a \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k \
-f tee "[select=\'v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'v:0,a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key"
See the full official docs for tee at http://ffmpeg.org/ffmpeg-formats.html#tee-1

ffmpeg - reduce background audio noise when recording desktop screen with gdigrab

I have an application that records desktop screen using FFmpeg. Here is the command I use
ffmpeg.exe -threads 4 -rtbufsize 2048m -f dshow -i audio="Microphone (Realtek Audio)" -f gdigrab -offset_x 1 -offset_y 1 -video_size 768x432 -probesize 4096M -i desktop -pix_fmt yuv420p -c:v libx264 -crf 28 -preset ultrafast -tune zerolatency -movflags +faststart -r 15 recording.mp4
It works fine. But I want to reduce the background noise from the audio. I have found some native filters for this
afftdn
anlmdn
arnndn
But not sure how to use them while recording screen. Can you please help?
Add the -af (or -filter_complex) option with the desired filter name:
ffmpeg.exe -threads 4 -rtbufsize 2048m -f dshow -i audio="Microphone (Realtek Audio)" -f gdigrab -offset_x 1 -offset_y 1 -video_size 768x432 -framerate 15 -probesize 4096M -i desktop -pix_fmt yuv420p -c:v libx264 -crf 28 -preset ultrafast -tune zerolatency -af afftdn -movflags +faststart recording.mp4
Unrelated change: I removed -r 15 output option and set the frame rate using the gdigrab -framerate option to avoid the unnecessary 25 fps (gdigrab default) to 15 fps conversion

Secure UDP broadcast with username and password using FFmpeg

Is there any way to have a secure UDP broadcast with FFmpeg by requesting username and password.
I've used this command to broadcast
ffmpeg -f dshow -video_size 1280x720 -rtbufsize 702000K -framerate 30 -i video="Video (00-0 Pro Capture Quad HDMI)" -r 30 -threads 4 -vcodec libx264 -crf 0 -preset ultrafast -f mpegts "udp://192.168.1.12:6666"
and I received it by open VLC using this
udp://#192.168.1.12:6666
How to provide a username and password to open this broadcast ???
It may work for you...
Stream
ffmpeg -f dshow -video_size 1280x720 -rtbufsize 702000K -framerate 30 -i video="Video (00-0 Pro Capture Quad HDMI)" -r 30 -threads 4 -vcodec libx264 -crf 0 -preset ultrafast -f mpegts "udp://username:password#192.168.1.12:6666"
Open
udp://username:password#192.168.1.12:6666

Want to send webcam stream to wowza using ffmpeg

I am new to both Wowza and to FFMPEG. I have been testing with ffmpeg and I am able to create local files with video and audio. For example:
ffmpeg -f dshow -i video="HD Pro Webcam C920" myvideo.mpeg
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920":audio="Microphone (Parallels Audio Con" -pix_fmt yuv420p myvideoandaudio.mp4
What I want to do is send the stream of my webcam to the Wowza server I have installed locally. I have searched several forums, including this one, and have tried multiple commands but still no luck. I would like to have someone point me in the right direction. Following Wowza's instructions, I created a Stream File called mystream, which has a stream UI of udp://0.0.0.0:10100. Also, the application connection settings say that the server's IP is 10.160.XX.XXX and port 1935. I am using Windows, and the "Shared" version of the FFMPEG downloads. I even changed the XML file following the instructions here, trying to send user credentials (during installation, Wowza asked to create credentials if I was going to use streaming):
http://www.wowza.com/forums/content.php?233-How-to-secure-publishing-from-an-RTMP-encoder-that-does-not-support-authentication-(ModuleSecureURLParams)
I have tried all the following commands:
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://localhost:1935/live/mystream
-- failed to connect socket
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://localhost/live/mystream
-- failed to read RTMP packet header
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://10.160.XX.XXX:1935/live/mystream
-- failed to read RTMP packet header
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://10.160.XX.XXX/live/mystream
-- failed to read RTMP packet header
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://127.0.0.1:1935/live/mystream
-- failed to read RTMP packet header
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv rtmp://127.0.0.1/live/mystream
-- writeN, rtmp send error 10053
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920" -f flv -vcodec libx264 -acodec aac -strict -2 rtmp://10.160.XX.XXX:1935/live/ivanstream
-- failed to read RTMP packet header
ffmpeg -f dshow -i video="HD Pro Webcam C920" -vcodec libx264 -tune zerolatency -b:v 900k -pix_fmt yuv420p -f mpegts udp://0.0.0.0:10100
-- conversion failed
ffmpeg -f dshow -i video="HD Pro Webcam C920":audio="Microphone (Parallels Audio Con" -vcodec libx264 -preset ultrafast -tune zerolatency -r 10 -async 1 -acodec libmp3lame -ab 24k -ar 22050 -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -f mpegts udp://0.0.0.0:10100
-- conversion failed
ffmpeg -f dshow -i video="HD Pro Webcam C920" -s 512x288 -vcodec libx264 -b:v 1024k -pix_fmt yuv420p -f flv rtmp://127.0.0.1:1935/live/mystream
-- failed to read rtmp packet header
ffmpeg -f dshow -i video="HD Pro Webcam C920" -c:v copy -c:a copy -f flv rtmp://10.160.XX.XXX:1935/live?doPublish=12345/mystream
-- failed to read rtmp packet header
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920":audio="Microphone (Parallels Audio Con" -r 40 -vcodec libx264 -threads 0 -crf 0 -preset ultrafast -tune zerolatency -f flv rtmp://127.0.0.1:1935/live/mystream
ffmpeg -rtbufsize 1500M -f dshow -i video="HD Pro Webcam C920":audio="Microphone (Parallels Audio Con" -r 40 -vcodec libx264 -threads 0 -crf 0 -preset ultrafast -tune zerolatency -f flv rtmp://10.160.XX.XXX:1935/live/mystream
-- rtmp header error
ffmpeg -y -f dshow -s 640x480 -r:v 15 -i video="HD Pro Webcam C920":audio="Microphone (Parallels Audio Con" -c:v libx264 -b:v -pix_fmt yuv420p -vb 450 -an -map 0:0 -f rtp rtp://127.0.0.1:10000 -flags +global_header -c:a libvo_aacenc -vn -map 0:1 -f rtp rtp://127.0.0.1:10002 > 10000.sdp
--unable to find suitable output format yuv420p
References:
http://www.wowza.com/forums/showthread.php?25777-Live-Webcam-feed-to-WOWZA-Server-over-RTMP-with-H264-encoding
http://www.factsandpeople.com/facts-mainmenu-5/23-other-software-technologies/258-preventing-real-time-buffer-error-causing-ffmpeg-to-drop-frames-in-screencast
http://www.wowza.com/forums/content.php?233-How-to-secure-publishing-from-an-RTMP-encoder-that-does-not-support-authentication-(ModuleSecureURLParams)
Thank you.

Resources