Lightweight encoding method for RTSP stream? - ffmpeg

what i am trying to do is to save a RTSP-stream as a file with some text overlay (so copy is not an option) on a Raspberry Pi. I tried using FFMPEG, but even with ultrafast settings the CPU load is way too high. Is there a faster encoding method or a completely different approach that i am missing?
ffmpeg -rtsp_transport tcp -i rtsp://x:y#ip/stream1 -vcodec libx264 -preset ultrafast -crf 0 -segment_time 3600 -t 3600 -f segment -y -strftime 1 -vf drawtext="fontcolor=white:fontsize=30:text='%{localtime}'",drawtext="fontcolor=white:fontsize=30:textfile=text.txt:x=600" /home/pi/NAS1/Elements/Videos/%Y-%m-%d_%H-%M-%S_file.mp4

Use the hardware encoder
I.e.
ffmpeg -codec:v h264_omx -b:v 2048k

Related

FFmpeg - Streaming from a rtsp server to a rtmp server - loosing packages

I'm trying to stream a video from a rtsp server to a rtmp one using FFmpeg.
Tried multiple arguments for my command :
ffmpeg.exe -re -i "rtsp://10.65.28.251:11442/video/live" -pix_fmt yuv420p -codec:v libx264 -tune animation -preset fast -crf 23 -maxrate 4M -bufsize 8M -f flv "rtmp://10.65.58.21:1935/rec/XB"
ffmpeg.exe -re -i "rtsp://10.65.28.251:11442/video/live" -preset ultrafast -vcodec libx264 -tune zerolatency -b 900k -f flv "rtmp://10.65.52.131:1935/rec/XB
I'm loosing a lot of packages as seen in the picture. I'm pretty new to FFmpeg so I'm pretty sure I'm messing up the parameters somehow.
My goal is to get a video on rtmp with min 30fps and as least lost packages as possible. If needed a downsize of the video quality would be fine.
Any idea what I'm doing wrong?
Thanks!
As kesh pointed above removing -re made a big difference. I ended up with this command which holds pretty good quality at 30fps.
ffmpeg.exe -i "rtsp://serversource:11442" -filter:v fps=fps=30 -crf 40 -preset ultrafast -vcodec libx264 -f flv "rtmp://servertarget:1935"

ffmpeg live stream transcoding. A/V sync issues on fast camera movement

I create a webrtc peer connection with my server(only stun)
Using pion webrtc for the server
I write the received RTP packets as VP8 and opus streams, as described here, to two pipes (the writers; created with os.Pipe() in golang)
The read ends of these two pipes are received by ffmpeg as inputs (via exec.Command.ExtraFiles) for transcoding using libx264 and aac into a single stream. The command:
ffmpeg -re -i pipe:3 -re -r pipe:4 -c:a aac -af aresample=48000 -c:v libx264 -x264-params keyint=48:min-keyint=24 -profile:v main -preset ultrafast -tune zerolatency -crf 20 -fflags genpts -avoid_negative_ts make_zero -vsync vfr -map 0:0,0:0 -map 1:0,0:0 -f matroska -strict -2 pipe:5
The above command outputs to a pipe(:5) the read end of which is being taken as input by the following:
ffmpeg -hide_banner -y -re -i pipe:3 -sn -vf scale=-1:'min(ih,360)' -c:v libx264 -pix_fmt yuv420p -ca aac -b:a 128k -b:v 1400k -maxrate 1498k -bufsize 2100k -hls_time 1 -hls_playlist_type event -hls_base_url /workdir/streamID/360p -hls_segment_filename /workdir/streamID/360p/360_%%03d.ts -f hls /workdir/streamID/360p.m3u8
This works fine as long as there are no movements of my webcam. The moment that happens the video speed suddenly increases for a split second and audio delay gets introduced. This delay keeps increasing each time I shake my webcam.
The first command in point 4 above - if written to a file separately will be absolutely fine, in terms of a/v sync, even with vigorous camera shaking. The weird audio delay is only when transcoding for hls output irrespective of whether I'm actually viewing it live or playing it back later.
This is my first time working with ffmpeg/hls/webrtc - would be really helpful if I could be pointed in the correct direction at least to be able to debug this or even know why this happens. Any and all help is greatly appreciated

ffmpeg rtmp stream taking 100% CPU

I am creating a small script to stream a images on rtmp server but FFMPEG command taking 100% CPU. Please have a look on my code.
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -loop 1 -i "Digital-Wallet-.jpg" -t 00:30:00 -r 1 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -f flv "rtmp://rtmpserver"
Encoding is CPU intensive. Remove -r 1 and add -framerate 1, -re, and -shortest.
ffmpeg -f lavfi -i anullsrc -loop 1 -framerate 1 -re -i "Digital-Wallet-.jpg" -t 00:30:00 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -shortest -f flv "rtmp://rtmpserver"
The default image demuxer frame rate is 25, so your command was unnecessarily converting 25 frames per second to 1 frame per second which is inefficient. The above changes fixes that.
-re will slow down the reading of the input to the native frame rate of the input. It is useful for real-time output and live streaming. Otherwise ffmpeg will attempt to encode as fast as possible.
I added -shortest to end the output when the shortest stream ends (the image) because anullsrc was set to encode indefinitely.

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

Resources