I am using FFmpeg-python bindings for using FFmpeg. I have to take input from x11grab, for which I already have an equivalent command in shell i.e,
ffmpeg -nostdin -hide_banner -nostats -loglevel panic -video_size 1920x1080 -r 60 -framerate 30 -f x11grab -i :1 -f alsa -ac 2 -i pulse -preset fast -pix_fmt yuv420p file.mkv &
I have gone through docs of FFmpeg-Python to create an equivalent command, however, I could not find any example of x11grab in the documentation.
I wanted to use a binding to make the code more readable, the command works with subprocess.call() / os.system()
CodePudding user response:
The syntax resembles the following code sample:
import ffmpeg
(
ffmpeg
.output(ffmpeg.input(':0', s='192x128', r=30, f='x11grab'),
ffmpeg.input('sine=frequency=500', f='lavfi'),
'file.mkv',
vcodec='libx264', acodec='aac', preset='fast', pix_fmt='yuv420p', t=5)
.global_args('-nostdin', '-hide_banner', '-nostats')
.overwrite_output()
.run()
)
Notes:
- My Ubuntu 18.04 Virtual machine, was not accepting 1920x1080 resolution, and not accepting the audio input device (I replaced it with synthetic audio).
- You can probably replace
ffmpeg.input('sine=frequency=500', f='lavfi')
with:
ffmpeg.input('pulse', f='alsa', ac=2)
, but I can't test it... - The example selects video and audio codecs:
vcodec='libx264', acodec='aac'
(selecting the codecs is a good practice). - The example uses
t=5
for recording only 5 seconds. .overwrite_output()
is used for overwriting the output without asking.
Grabbed sample: