User:Trickygnome/Video recording
FFmpeg orders of parameters
ffmpeg [global_options] [input_options1] -i input1 [input_options2] -i input2 ... [output_options] output
check input
check and tune microphone
arecord -D mic -f cd -d 10 test.wav && mpv test.wav
ffmpeg -f alsa -i mic -t 10 -ac 2 -ar 44100 test.mp4 && mpv test.mp4
ffmpeg -fflags +genpts -f alsa -ac 2 -ar 44100 -thread_queue_size 1024 -i mic -c:a aac -af "volume=20,anlmdn,highpass=f=1200,lowpass=f=2600,aresample=async=1" output.mp4 ; mpv output.mp4
ffmpeg -fflags +genpts -use_wallclock_as_timestamps 1 \ -f alsa -ac 2 -ar 44100 -thread_queue_size 2048 -i mic \ -c:a aac -b:a 192k -af "volume=5,anlmdn,highpass=f=1000,lowpass=f=3000,aresample=async=1000" -movflags +faststart output.mp4 ; mpv output.mp4
check camera
root #
USE=sdl emerge --ask ffmpeg
sdl flag required for ffplay command
ffplay -report -f v4l2 -video_size 1280x720 -framerate 15 -i /dev/video0
ffmpeg -f v4l2 -video_size 1280x720 -framerate 15 -i /dev/video0 -c:v libx264 -preset ultrafast -y output.mp4
check screen recorder
Here for Wayland wlroots we use wf-recorder tool to record screen.
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuv420p -r 15 --geometry 1920x1080 -f aa.mp4
ffplay -f rawvideo -pixel_format yuvj420p -video_size 1920x1080 -framerate 30 test.yuv
Recording of mixes
1) Record only microphone and camera with ffmpeg.
This gives us acceleration capabilities available:
user $
ffmpeg -hwaccels
ffmpeg -f v4l2 -thread_queue_size 30 -i /dev/video0 -f alsa -thread_queue_size 30 -i mic -c:v h264_nvenc -preset p4 -rc vbr_hq -qmin 19 -qmax 21 -b:v 5M -maxrate 8M -c:a aac -ar 16000 -b:a 192k -async 1 -af "volume=20,anlmdn,highpass=f=1000,lowpass=f=3000,aresample=async=10" output.mp4
2) Record only screen video to file. Read file in mixer and save to other file. Play result file. Use ffmpeg debugging -loglevel debug
user $
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuv420p -r 15 --geometry 1920x1080 -f out.yuv
user $
ffmpeg -i out.yuv -c:v libx264 -preset ultrafast -y output.mp4 -loglevel debug
user $
mpv output.mp4
3) Pipe screen recorder to mixer
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuvj422p -r 15 --geometry 1920x1080 -f /dev/stdout | ffmpeg -i - -vf "format=yuvj422p" -c:v libopenh264 -y output.mp4
user $
mpv output.mp4
4) Add microphone recording to screen recording with mixer
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuv420p -r 15 --geometry 1920x1080 -f /dev/stdout | ffmpeg -f alsa -i mic -i - -map 1:v -map 0:a -c:v libx264 -b:v 5000k -preset fast -c:a aac -b:a 128k -ar 44100 -ac 2 -shortest -y output.mp4
Finally
all at once
Almost, but NOT WORKING, FAIL.
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuvj420p -r 15 -f /dev/stdout | ffmpeg -hwaccel cuda -fflags +genpts -use_wallclock_as_timestamps 1 -i - -f v4l2 -video_size 420x240 -framerate 15 -i /dev/video0 -f alsa -ac 2 -ar 11025 -thread_queue_size 48 -i mic -filter_complex "[0:v][1:v] overlay=W-w:H-h:format=yuv420" -map 2:a -c:v libx264 -preset fast -c:a aac -b:a 192k -af "volume=20,anlmdn,highpass=f=1000,lowpass=f=3000,aresample=async=10" -avoid_negative_ts make_zero -movflags +faststart -y output.mkv
record in parallel and then combine
myrec.sh
For Firefox#!/bin/bash
trap "kill 0" SIGINT
rm -f screen.mp4
rm -f camera+mic.mp4
setsid ffmpeg -f v4l2 -thread_queue_size 30 -i /dev/video0 -f alsa -thread_queue_size 30 -i mic -c:v h264_nvenc -preset p4 -rc vbr_hq -qmin 19 -qmax 21 -b:v 5M -maxrate 8M -c:a aac -ar 16000 -b:a 192k -async 1 -af "volume=20,anlmdn,highpass=f=1000,lowpass=f=3000,aresample=async=10" -y camera+mic.mp4 &
wf-recorder -D -b0 -B0 -m rawvideo --pixel-format yuv420p -r 15 --geometry 1920x1080 -f screen.mp4 &
wait
killall ffmpeg
Combine to "screen.mp4" + "camera+mic.mp4" = output.mp4:
ffmpeg -i screen.mp4 -i camera+mic.mp4 \
-filter_complex "[0:v]setpts=PTS-STARTPTS[bg]; \
[1:v]setpts=PTS-STARTPTS,scale=320:-1[cam]; \
[bg][cam]overlay=main_w-overlay_w:main_h-overlay_h:shortest=1,format=yuv420p[outv]" \
-map "[outv]" -map 1:a -c:v libx264 -preset fast -crf 23 -c:a aac output.mp4