On Sun, 19 Nov 2023 14:50:34 +0100, Bo Berglund via lazarus
<lazarus@lists.lazarus-ide.org> wrote:

>Lazarus contains LibVLC as a standard package available to be installed in the
>GUI using Package/Install-remove packages! No download needed from external
>sources!

>Anyway, I have been experimenting with the example inside the package code and
>also read Michael's document "Displaying video files using Free Pascal and
>Lazarus".
>
>I think I can switch out PasLibVLC and replace it with the LclVLC player 
>instead
>but I need some help in implementation.
>
>There are some functions I would like to get hints on how to implement:
>
>1) Progressbar update
>---------------------
THIS IS NOW SOLVED!
--------------------
I added a TThread.Create... statement as I found in the document, without really
understanding how it can help. Seems to me like creating a thread that
immediately exits. What can that do?
And I also added an FPlayer.UseEvents statement.
This is how it now looks and it does allow the events to fire...

procedure TfrmMainVlc.FormCreate(Sender: TObject);
begin
  With TThread.Create(False) do Terminate; //Initialize the treading system??
  FPlayer:=TLCLVLCPlayer.Create(Self);
  FPlayer.ParentWindow:=PVideo;
  FPlayer.OnPositionChanged:=@DoPositionChanged;
  FVideoFile := ReadIniString('Files', 'LastVideo', '');
  FEVideo.FileName := FVideoFile;
  FEVideo.InitialDir := ExtractFileDir(FVideoFile);
  tbVolume.Position := ReadIniInt('Settings', 'Volume', 10);
  FPlayer.UseEvents:=True;
end;

The next item is the handling of the progress bar:
It now looks like this and works:

procedure TfrmMainVlc.DoPositionChanged(Sender: TObject; const APos: Double);
var
  VPos: integer;
begin
  VPos := Round(APos * pgbVideopos.Max);
  pgbVideopos.Position := VPos;
end;

>
>2) Reposition video via progressbar
>-----------------------------------
This is also now working as follows:

//Mouse up on progressbar should reposition the video to the clicked pos
procedure TfrmMainVlc.pgbVideoposMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  VidPos: int64;
  Duration: int64;
begin
  Duration := FPlayer.VideoLength div 1000;
  VidPos := Round(X / pgbVideopos.Width * pgbVideopos.Max * Duration);
  FPlayer.VideoPosition := VidPos;
end;

However the progressbar does not immediately reposition to the clicked position,
instead it takes a second or so while it moves stepwise across.

How can I make that instantaneous?


>3) Increase/decrease playback speed?
>------------------------------------
>Is it possible to adjust the playback speed (I can do this with PasLibVLC)?
>Then how can it be done, say to enter a percentage between 50 and 200 in a box
>and then tell the player to use that setting.
>
In the original code using PasLibVLC it is done like this:

procedure TfrmMain.btnFFClick(Sender: TObject);
begin
  vlcPlayer.SetPlayRate(speSpeed.Value);
end;
And here the progressbar position is immediately changed to the target position
below the mous pointer.


>4) Lipsync adjust
>-----------------
>Is it possible to shift the audio forward/backward relative to the image in
>order to adjust lip sync? I can do this with PasLibVLC, but how can it be done
>here?

In the original code again it works and is done like shown below where the
spinedit speAudio contains a value in milliseconds but the command expects
microseconds, hence the multiplication by 1000:

//For testing purposes, delay audio by the value from speAudio
procedure TfrmMain.btnShiftAudioClick(Sender: TObject);
var
  SyncCmd: string;
begin
  vlcPlayer.SetAudioDelay(speAudio.Value *1000); //Convert to us
  SyncCmd := FormatAudioSyncCmd(-1 * speAudio.Value, FVideoFile);
  Clipboard.AsText := SyncCmd; //Ffmpeg command to modify file if needed
end;

Here I put the SyncCmd on the clipboard so it can be pasted into an SSH command
window for ffmpeg to modify the video file itself if needed.
This file modification is done after checking the effect inside the video player
first, in the player whatever shift is applied is immediately there to check...


Items 3 & 4 are still unsolved, how can it be done?

Still hoping for suggestions on how to get this to work!


-- 
Bo Berglund
Developer in Sweden

-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to