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
Related
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
I want to record and stream desktop to Youtube live by FFmpeg. But the output resolution is very low, maximum 360.
What options I need to change?
ffmpeg -framerate 30 -f x11grab -i :1 -f pulse -i default -c:v libx264 -s 1920x1080 -r 60 -b:v 5000k -crf 10 -vf format=yuv420p -c:a aac -b:a 128k -f flv rtmp://a.rtmp.youtube.com/live2/stream_key
Problem
Default size for x11grab is the full desktop or window (640x480 for old ffmpeg versions). Your ffmpeg is old, so it is capturing at 640x480. You are then upscaling 640x480 to 1920x1080 which is bad and looks ugly.
Solution 1: Upgrade ffmpeg
Fix by using a modern ffmpeg version and it will grab the full desktop or window size by default. See FFmpeg Download page for links or the FFmpeg compile and install guides.
Solution 2: Use -video_size input option
ffmpeg -framerate 30 -video_size 1920x1080 -f x11grab -i :0.0 -f pulse -i default -c:v libx264 -b:v 5000k -maxrate 5000k -bufsize 10000k -g 60 -vf format=yuv420p -c:a aac -b:a 128k -f flv rtmp://a.rtmp.youtube.com/live2/stream_key
See the FFmpeg x11grab documentation for more info and options.
For streaming it is recommended to add -g, -bufsize, and -maxrate to enable VBV.
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.
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" ?
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