Topic: [Script] Webcam integration using ffmpeg.exe utility

Webcam integration using ffmpeg.exe utility

CONST

// setting of webcam
WEBCAM_NAME = 'USBWebCam'; // YOU NEED TO KNOW YOUR WEB CAM NAME!
WEBCAM_RESOLUTION = '1280x720';



procedure Form1_OnShow (Sender: string; Action: string);
begin
    ClearShotFolder;
end;

procedure frmEmployee_Button3_OnClick (Sender: string; var Cancel: boolean);
var
    pathShot: string;
    sShotFile: string;
begin
    frmEmployee.Button3.Enabled := False;
    pathShot := ExtractFilePath(Application.Exename)+'shot\';
    sShotFile := 'shot_'+FormatDateTime('ddmmyyyy_hhmmss', now)+'.jpg';

    OpenFile('-f dshow -s '+WEBCAM_RESOLUTION+' -i video="'+WEBCAM_NAME+'" -f image2 "'+pathShot+sShotFile+'"', 'ffmpeg.exe');


    Sleep(3000);
    if FileExists(pathShot+sShotFile) then
    begin
        frmEmployee.imgPhoto.LoadPicture(pathShot+sShotFile);
        frmEmployee.imgPhoto.dbFileName := pathShot+sShotFile;
        frmEmployee.imgPhoto.dbImageIsChanged := True;
    end;

    frmEmployee.Button3.Enabled := True;
end;





procedure Form1_bWebRes_OnClick (Sender: string; var Cancel: boolean);
begin
    OpenFile('/K ffmpeg.exe -f dshow -list_options true -i video="'+WEBCAM_NAME+'"', 'cmd.exe'); // list of resolutions
end;

procedure Form1_bListCams_OnClick (Sender: string; var Cancel: boolean);
begin
    OpenFile('/K ffmpeg.exe -list_devices true -f dshow -i dummy', 'cmd.exe'); // list of devices
end;



procedure ClearShotFolder;
var
    sl: TStringList;
    i,c: integer;
    pathShot: string;
begin
    pathShot := ExtractFilePath(Application.Exename)+'shot\';

    sl := TStringList.Create;
    sl.Text := GetFilesList(pathShot);

    // delete all files
    c := sl.Count-1;
    for i := 0 to c do
        if not DeleteFile(sl[i]) then ShowMessage('Can''t remove file '+sl[i]);

    sl.Free;
end;


Example:
http://myvisualdatabase.com/download/WebCam2.zip

Dmitry.