//开始录制
void frmMain::on_start_clicked()
{
m_Process.setProcessChannelMode(QProcess::MergedChannels);
QString cmd = "ffmpeg.exe -f dshow -i video=\"screen-capture-recorder\" e:/123.mp4";
// .\ffmpeg -f dshow -i video="screen-capture-recorder" -r 20 -t 4 screen-capture.mp4
// .\ffmpeg -f dshow -i video="screen-capture-recorder" 123.mp4
m_Process.start(cmd);
}
//停止录制
void frmMain::on_stop_clicked()
{
if (m_Process.isOpen()){
m_Process.write("q");
}
}
参考雷神代码:
一句话介绍:注册录屏dshow滤镜(例如screen-capture-recorder),然后通过dshow获取录屏图像然后编码处理。
因此,在使用FFmpeg屏幕录像之前,需要先安装dshow滤镜。在这里推荐一个软件:screen capture recorder。安装这个软件之后,就可以通过FFmpeg屏幕录像了。
-f fmt (input/output)
Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.
-i url (input)
input file url
-r rate帧率
-t duration (input/output) 录屏时间
添加文字水印:
ffmpeg -f dshow -i video="screen-capture-recorder" -vf drawtext="fontsize=100:fontcolor=white:text='test':x=(w-text_w-10):y=(h-text_h-10)" 1.mp4
添加图片水印:
ffmpeg -f dshow -i video="screen-capture-recorder" -vf "movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" 2.mp4
位置:
左上角
x=10:y=10
右上角
x=w-text_w-10:y=10
左下角
x=10:y=h-text_h-10
右下角
x=w-text_w-10 : y=h-text_h-10
中间:
x=(w-text_w)/2:y=(h-text_h)/2