Reducing FFMPEG h264 video stream latency - ffmpeg

I'm using FFMPEG(h264) and I want to reduce latency as much as possible. Now it's about 700 ms and I can't really make it lower. I tried almost all, so maybe anyone has idea how to help me?
ffmpeg -f dshow -i video="screen-capture-recorder" -pix_fmt yuv420p -probesize 32 -r 100 -an -vcodec libx264 -crf 40 -preset ultrafast -tune zerolatency -threads 8 -thread_type slice -f mpegts udp://192.168.88.228:1234
The weird thing is I got this latency even on 127.0.0.1....
(on the other side I use just ffplay udp:// .......)

I would try to set -threads to 1 to disable multi-threaded decoding. Multi-threaded decoding introduces delay by adding a lag of 1 frame for each thread.

Works with a GoPro Hero 8 Black and Linux
ffmpeg -threads 1 -i 'udp://#0.0.0.0:8554?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format=yuv420p -f v4l2 /dev/video0

Related

ffmpeg - slow x11 framerate when audio enabled

I've got a weird issue running ffmpeg and trying to capture my screen.
When I run it with:
ffmpeg -video_size 512x383 -framerate 60 -f x11grab -i :0.0+512,203 -c:v libx264 -crf 0 -preset ultrafast -t 20 /tmp/lossless.mkv
I can capture 60fps without any issue.
However, as soon as I try to capture audio. The framerate drops to less than 30fps:
ffmpeg -video_size 512x383 -framerate 60 -f x11grab -i :0.0+512,203 -f pulse -ac 2 -i default -c:v libx264 -crf 0 -preset ultrafast -b:a 64k -t 20 /tmp/lossless_with_audio.mkv
See here for command output: https://pastebin.com/BMq38raq
I'd try with:
ffmpeg -framerate 60 -f x11grab -thread_queue_size 1024 -i :0.0 -f pulse -ac 2 -i default -c:v libx264 -acodec libmp3lame -crf 0 -preset ultrafast -b:a 64k -t 20 /tmp/lossless_with_audio.mkv
Also, in terms of framerate, Are we talking about high motion here, such as game graphics? If not, I'd reduce the framerate to 25-30.
Note that the FPS may also drop due to lack of CPU resources so you should check the utilisation.
You may also want to review https://trac.ffmpeg.org/wiki/EncodingForStreamingSites
Cheers,
This is a very weird problem, I have the slight feeling that starting dbus helped prevent this problem.
https://stackoverflow.com/a/64080884/903004

How to switch from yuyv422 to yuv420p for better framerate in ffmpeg on Windows 10

I upgraded PC from Windows 7 to Windows 10, as it is discontinued. Problem is,
I had low latency monitoring and recording solution with FFmpeg.
After the upgrade, Logitech camera switched from yuv420p to yuyv422 and I lost 30 fps support at 1280x720. Now it is only limited to 10 FPS.
Tried different drivers, it still yuyv422
Here is a code i use.
ffmpeg -y -loglevel panic -hwaccel qsv -threads 1 -fflags nobuffer -flags low_delay -strict experimental -f dshow -video_size 1280x720 -framerate 10 -pixel_format yuyv422 -i video="C922 Pro Stream Webcam" -codec:v libx264 -preset ultrafast -crf 24 -tune zerolatency -map 0 -f segment -segment_time 600 -segment_wrap 2 -reset_timestamps 1 dvr_%%04d.avi -codec:v copy -f nut - | ffplay -fflags nobuffer -flags low_delay -vf scale=1920x1080:flags=lanczos -window_title "kamera" -noborder -left 1920 -top 150 -fast -framedrop -
I really need low CPU, no latency monitoring at minimum 24 FPS and recording capabilities. File size doesn't matter so much.
Using mjpeg eats CPU like crazy.
I force installed old Logitech driver and get back yuv420p/30FPS support.
I store some instructions and drivers here: https://github.com/mjasnikovs/logitechC920-vlc
Maybe somebody will find it useful.

How to reduce audio delay in FFmpeg using HTTP FLV stream?

I have problem with live http flv stream. I'm using the following command and it works great except for the audio. Audio has delay that increasing over time. I can fix the this by removing refresh rate option on the output (-r 30) but then stream latency goes higher for about half second.
ffmpeg -f v4l2 -threads 0 -video_size 672X420 -i /dev/video1 -f alsa -thread_queue_size 512 -i hw:1,0 -c:a aac -ar 44100 -b:a 128k -c:v libx264 -s 672x420 -r 30 -g 60 -preset superfast -tune zerolatency -strict -2 -f flv rtmp://localhost/live/primary
Can someone explain why this happening and what possible fixes are?
On the client I'm using Chrome with flv.js library.
On the server Node-Media-Server.

FFmpeg, capturing video is laggy, how to eliminate that?

Lets say I dont have a very good computer and my recordings are laggy. Two version I tried:
ffmpeg -f dshow -framerate 30 -i video="screen-capture-recorder":audio="virtual-audio-capturer" -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.mkv
ffmpeg -f gdigrab -framerate 30 -i desktop -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.mkv
I tried to avoid all compressing stuff, still lagging. Although Im recording 1920x1080 video... I dont care how big the result is. Isnt there an option like "store all frames, and encoding a bit later, I dont care the realtime capturing" ?

FFMPEG HLS video speed is too fast

I am trying to make a .m3u8 hls playlist locally on my computer. I am using Windows 7, 32 bit.
I am a begginner of FFMPEG, and finally I combined some commands into this:
ffmpeg -re -rtbufsize 999999k -y -f dshow -video_size 640x360 -r 15 -i video="ManyCam Virtual Webcam" -c:v libx264 -crf 18 -profile:v main -maxrate 999999k -bufsize 99999k -pix_fmt yuv420p -flags -global_header -hls_time 10 -g 3 -hls_list_size 2 -hls_wrap 0 -start_number 1 D:\\stream\stream.m3u8 -tune zerolatency
The problem is that while playing the m3u8 playlist with VLC or a HLS player, the video speed is faster than normal.
If you need more info, please comment.
EDIT
If I play one of the .ts files, the problem is the same.
Thank you so much!

Resources