FFmpeg录制Windows桌面&摄像头&麦克风

录制桌面

  1. 使用GDI screengrabber可以录制主屏幕的内容

    You can also use gdigrab as input device to grab video from the Windows screen.

    To capture all your displays as one big contiguous display:

    ffmpeg -f gdigrab -framerate 30 -i desktop output.mkv
    

    If you want to limit to a region, and show the area being grabbed:

    ffmpeg -f gdigrab -framerate 30 -offset_x 10 -offset_y 20 -video_size 640x480 -show_region 1 -i desktop output.mkv
    

    To grab the contents of the window named “Calculator”:

    ffmpeg -f gdigrab -framerate 30 -i title=Calculator output.mkv
    
  • 存在问题:缩放时耗费时间过长,导致帧率不高

2.使用screen capture recorder无法全屏录制桌面

录制音频

ffmpeg -f dshow -i audio="virtual-audio-capturer" -acodec libmp3lame window.mp3
avdevice_register_all();

	pInputFmt = av_find_input_format("dshow");
	if (avformat_open_input(&pFmtCtx, "audio=virtual-audio-capturer", pInputFmt, &pOptions) < 0) {
		av_log(nullptr, AV_LOG_ERROR, "cant not open input file.\n");
		return -1;
	}

	av_dump_format(pFmtCtx, 0, "audio=virtual-audio-capturer", 0);

录制摄像头

查看输入设备:

ffmpeg.exe -f dshow -list_devices true -i dummy

查看摄像头图像:

ffplay.exe -f dshow -video_size 640x480 -i video="HD WebCam"
avdevice_register_all();
pInputFmt = av_find_input_format("dshow");
int ret = avformat_open_input(&m_InputFmtCtx, "video=HD WebCam", pInputFmt, nullptr);
if (ret < 0)
{
	av_log(nullptr, AV_LOG_ERROR, "Could not open input file.\n");
	goto ERROR_PROC;
}

录制麦克风

播放麦克风声音:

ffplay.exe -f dshow -i audio="麦克风 (Realtek High Definition Audio)"

录制USB摄像头

ffmpeg.exe -f dshow -video_size 1280x720 -i video="HD USB Camera" -vcodec copy -rtsp_transport tcp -f rtsp rtsp://localhost/test

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章