Secure UDP broadcast with username and password using FFmpeg - 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

Related

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

How to livestream a webcam to YouTube with FFmpeg?

I want to send the livestream of my webcam to YouTube. I can follow YouTube's guide up to step 8. "Stream Connection" tells me there is "No data" and the button "Go Live" remains unclickable. A screenshot of this situation can be seen at
As encoding software, I was planning on using FFmpeg because it can run from the target platform, a Raspberry Pi with Raspbian. A USB webcam supported by video4linux2 is used.
FFmpeg's wiki shows that streaming a file can be done with the following:
ffmpeg -re -i input.mkv \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 \
-ar 44100 -f flv rtmp://live.twitch.tv/app/<stream key>
I modified this command in the following ways:
1. It takes the video stream from the webcam with -f v4l2 -i /dev/video0.
2. It does not broadcast any audio with -an.
3. It broadcasts to YouTube's RTMP server, rtmp://a.rtmp.youtube.com/live2/<stream key>
The final version of the command is now:
RTMP_URL="rtmp://a.rtmp.youtube.com/live2"
STREAM_KEY="secr-etse-cret-secr"
OUTPUT=$RTMP_URL/$STREAM_KEY
ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv $OUTPUT
When I run this command, I would expect that "Stream connection" would change to something else than "No data" after a few seconds, but that does not happen.
I have tried recording the stream to a local file with:
ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv test.flv
This worked fine. That demonstrates to me that the issue is with getting the video stream accepted by YouTube.
The code below works very well using Windows, you may adjust to fit for your need
ffmpeg -loglevel debug -threads:v 2 -threads:a 8 -filter_threads 2 -thread_queue_size 512 -f dshow -i video="HP Wide Vision HD" -f dshow -i audio="Microphone Array (Realtek Audio)" -pix_fmt yuv420p -c:v libx264 -qp:v 19 -profile:v high -rc:v cbr_ld_hq -level:v 4.2 -r:v 60 -g:v 120 -bf:v 3 -refs:v 16 -f flv rtmp://youtube_stream_url/stream_key

FFmpeg - frame delays double after the audio was added

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?

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