Adding text to video recording

RVMedia support and discussion (components for displaying and controlling IP cameras, webcams, video conferencing, video chats, recording audio and video files)
Post Reply
wernerh
Posts: 16
Joined: Fri Mar 27, 2020 1:52 am

Adding text to video recording

Post by wernerh »

Hi,

I am using the TRVCamRecorder to record videos and just wondering if it's possible to add text to a video, like a caption or timestamp?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Adding text to video recording

Post by Sergey Tkachenko »

Use TRVCamera.OnGetImage event.

The code below adds a timestamp to the bottom right corner:

Code: Select all

procedure TForm1.RVCamera1GetImage(Sender: TObject; img: TRVMBitmap);
var
  bmp: TBitmap;
  S: String;
  Sz: TSize;
begin
  bmp := img.GetBitmap;
  with bmp.Canvas do
  begin
    Lock;
    try
      Brush.Style := bsClear;
      Font.PixelsPerInch := 96;
      Font.Name := 'Tahoma';
      Font.Color := clWhite;
      Font.Size := 8;
      S := TimeToStr(Now);
      Sz := TextExtent(S);
      TextOut(bmp.Width - Sz.cx - 2, bmp.Height - Sz.cy - 2, S);
    finally
      Unlock;
    end;
  end;
  img.UpdateData;
end;
Note that this event may be called in a thread context.
If you need to add a static image, like a logo, the recommended way is to prepare it in TRVMBitmap object, and use OnGetImage to draw as img.Draw(X, Y, MyLogoBitmap); You do not need to call img.UpdateData after using this method (if MyLogoBitmap is TRVMBitmap)
Post Reply