FFmpeg latency is over 3 seconds (must be subsecond) - ffmpeg

I'm working on a robot (raspberry pi 4 based) that is accessible from anywhere. My robot is currently at a 3-second latency. I also use OvenMediaEngine (RTMP to WebRTC) to transmit my stream to the client (on a website).Here is my command:
raspivid -n -t 0 -w 1280 -h 720 -fps 25 -b 3500000 -g 50 -fl -o - | ffmpeg -thread_queue_size 1024 -i - -itsoffset 6 -f alsa -channels 1 -thread_queue_size 1024 -i hw:2 -preset ultrafast -tune zerolatency -vcodec libx264 -r 25 -b:v 512k -s 1280x720 -acodec aac -ac 2 -ab 32k -ar 44100 -f flv rtmp://xxxxxxxx:1935/app/stream
Does anyone know why it won't stream at subsecond latency?
Thanks in advance!

I am not exactly sure where you are incurring latency, but it usually happens either during transport or encoding.
If possible I would see if you avoid re-encoding to H264. You are going to pay a penalty of decoding (or just parsing?) and then encoding.
I would also see if you can ingest into OME with something other then RTMP. WebRTC and RTSP both will give you better latency.

Related

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.

Reducing FFMPEG h264 video stream latency

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

What command convert mjpeg IP camera streaming to mp4 file with lowest CPU usage?

like above question, I want find out what ffmpeg command can help me reduce cpu usage when running 50 IP camera (running same 50 command).
My ffmpeg command:
ffmpeg -f mjpeg -y -use_wallclock_as_timestamps 1 -i 'http://x.x.x.x:8090/test1?.mjpg' -r 3 -reconnect 1 -loglevel 16 -c:v mjpeg -an -qscale 10 -copyts '1.mp4'
50 command like that take my computer (4 core) 200% CPU
I want this computer can run for 150 camera, any advise?
=========================================================
using -c:v copy can make it faster but fize size is terrible
I try slow down frame rate by 3 with -r 3 or -framerate 3 to decrease file size but not succesful (because vcodec copy can't do that).
Have any option to force input frame rate by 3?
(sorry for my bad English)
by setting -c:v mjpeg you are decoding and re-encoding the stream. set -c:v copy to copy the data without re-encoding it.
ffmpeg -re -i 'rtsp://user:password#10.10.10.30/rtsp_tunnel' -pix_fmt yuv420p -c:v libx264 -preset ultrafast -profile baseline -crf 18 -f h264 udp://0.0.0.0:3001

ffmpeg - How to use all the CPU of the server?

I am using this command to run ffmpeg -
ffmpeg -i - -isync -threads 16 -vcodec libx264 -acodec aac -ar 22050 -r 25 -s 640x360 -strict experimental -b:a 32k -b:v 100k -f flv "rtmp://" -threads 16 -vcodec libx264 -acodec aac -ar 22050 -r 25 -s 640x360 -strict experimental -b:a 32k -b:v 400k -f flv "rtmp://"
I am running ffmpeg processes on my server. Currently ffmpeg don't use all my CPU, I want to use all my CPU usage.
My server has 24 CPU, 16 GB RAM, and 1 TB HDD. Please tell me the command to use all my CPU usage, and to make my ffmpeg smooth.
Thanks
0% idle and 0% wait. That is using 100% of your CPU. Your computer is just not powerful enough to process 20 videos simultaneously. You can try adding the 'ultrafast' option to use less CPU per encode (at the price of lower quality)

Resources