DGL
https://delphigl.com/forum/

TPasLibVlcPlayer not Render with openGl
https://delphigl.com/forum/viewtopic.php?f=19&t=11287
Seite 1 von 1

Autor:  carmeloconny [ Di Dez 02, 2014 08:21 ]
Betreff des Beitrags:  TPasLibVlcPlayer not Render with openGl

Hello everyone. sorry for my english.
I write in the English section, I do not know if I'm wrong.

Now my project, thanks to Wuppertaler, performs video TPasLibVlcList and TPasLibVlcPlayer visual component. My problem is that the video does not work render in 720x576 format. In Tfrmapri4.Render procedures; NewFrame is always False. why unlock function inactive newFrame True? Where am I wrong?

Code:
  1.  
  2. unit apri4;
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls, Buttons, PasLibVlcPlayerUnit, PasLibVlcUnit, dglOpenGL, glBitmap,
  10.   Windows;
  11.  
  12. type
  13.   tRGBA = record
  14.     r,g,b,a : byte;
  15.   end;
  16.   tVLCcontext = record
  17.     VLCpixels:array of tRGBA;
  18.   end;
  19.  
  20.   { Tfrmapri4 }
  21.  
  22.   Tfrmapri4 = class(TForm)
  23.     Button1: TButton;
  24.     Button2: TButton;
  25.     Button3: TButton;
  26.     Label1: TLabel;
  27.     Label2: TLabel;
  28.     Panel1: TPanel;
  29.     Panel2: TPanel;
  30.     Panel3: TPanel;
  31.     PasLibVlcMediaList1: TPasLibVlcMediaList;
  32.     Player1: TPasLibVlcPlayer;
  33.     SpeedButton1: TSpeedButton;
  34.     Timer2: TTimer;
  35.     procedure Button1Click(Sender: TObject);
  36.     procedure Button2Click(Sender: TObject);
  37.     procedure Button3Click(Sender: TObject);
  38.     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure FormHide(Sender: TObject);
  41.     procedure SpeedButton1Click(Sender: TObject);
  42.   private
  43.     { private declarations }
  44.     StartTime, TimeCount, FrameCount,fc  : Cardinal;
  45.     Frames, DrawTime,VLCRenderTime       : Cardinal;
  46.     DoPlay,NewFrame,fClose: Boolean;
  47.     fTexture1: TglBitmap2D;
  48.     procedure SetupGL;
  49.     procedure Render;
  50.     procedure RenderVLC;
  51.     procedure RenderGL;
  52.   public
  53.     { public declarations }
  54.     libvlc_instance        :libvlc_instance_t_ptr;
  55.     libvlc_media           :libvlc_media_t_ptr;
  56.     libvlc_media_player    :libvlc_media_player_t_ptr;
  57.     libvlc_media_track_info:libvlc_media_track_info_t_ptr;
  58.     VideoWidth,VideoHeight:Integer;
  59.     VLCctx:tVLCcontext;
  60.     DC                                : HDC;
  61.     RC                                : HGLRC;
  62.   end;
  63.  
  64.   function libvlc_video_lock(opaque : Pointer; var planes : Pointer) : Pointer; cdecl;
  65.   function libvlc_video_unlock(opaque : Pointer; picture : Pointer; planes : Pointer) : Pointer; cdecl;
  66.   function libvlc_video_display(opaque : Pointer; picture : Pointer) : Pointer; cdecl;
  67.  
  68.  
  69. var
  70.   frmapri4: Tfrmapri4;
  71.   mio_width:integer = 720;
  72.   mio_hength:integer = 576;
  73.  
  74.  
  75. implementation
  76.  
  77. {$R *.lfm}
  78.  
  79. { Tfrmapri4 }
  80.  
  81. procedure Tfrmapri4.FormCreate(Sender: TObject);
  82. begin          // PlayList
  83.   PasLibVlcMediaList1.Clear();
  84.   PasLibVlcMediaList1.Add('c:\film\01\01.mp4'); // 480 x 320
  85.   PasLibVlcMediaList1.Add('c:\film\02\02.mpg'); // 1920 x 1080
  86.  
  87.   //******************************************
  88.   libvlc_dynamic_dll_init_with_path('C:\Program Files (x86)\VideoLAN\VLC');
  89.   libvlc_instance := libvlc_new(0, nil);
  90.   //OpenGL:
  91.   DC:= GetDC(Player1.Handle);    //Handle TPasLibVlcPlayer compont visual
  92.   if not InitOpenGL then Application.Terminate;
  93.   RC:= CreateRenderingContext( DC,
  94.                                [opDoubleBuffered],
  95.                                32,
  96.                                24,
  97.                                0,0,0,
  98.                                0);
  99.   ActivateRenderingContext(DC, RC);
  100.   SetupGL;
  101.   TimeCount:=0;
  102.   FrameCount:=0;
  103.   fc:=0;
  104.   DoPlay:=false;
  105.   NewFrame:=false;
  106. end;
  107.  
  108. procedure Tfrmapri4.FormHide(Sender: TObject);
  109. begin
  110.   PasLibVlcMediaList1.Stop;
  111.   PasLibVlcMediaList1.Clear();
  112. end;
  113.  
  114. procedure Tfrmapri4.SpeedButton1Click(Sender: TObject);
  115. begin
  116.    PasLibVlcMediaList1.Next();
  117. end;
  118.  
  119. procedure Tfrmapri4.SetupGL;
  120. begin
  121.   glClearColor(0.3, 0.4, 0.7, 0.0);
  122.   glEnable(GL_DEPTH_TEST);
  123.   glEnable(GL_CULL_FACE);
  124.   glEnable(GL_ALPHA_TEST);
  125.   glAlphaFunc(GL_GREATER, 0.1);
  126.   glMatrixMode(GL_PROJECTION);
  127.   glLoadIdentity;
  128.   glOrtho(0,mio_width,0,mio_hength,0,128);
  129.   //glOrtho(0,1024,0,768,0,128);
  130.   glMatrixMode(GL_MODELVIEW);
  131. end;
  132.  
  133. procedure Tfrmapri4.Render;
  134. begin
  135.    if not DoPlay then begin sleep(20); exit; end;
  136.   if NewFrame then  // NewFrame in debug always False ????
  137.     begin
  138.       NewFrame:=false;
  139.       RenderVLC;
  140.       RenderGL;
  141.       TimeCount:= GetTickCount - StartTime;
  142.       Inc(FrameCount);
  143.       Frames:= FrameCount*1000 div TimeCount;
  144.       Drawtime:=TimeCount div FrameCount;
  145.     end
  146.   else
  147.     begin
  148.       sleep(1);
  149.     end;
  150. end;
  151.  
  152. procedure Tfrmapri4.RenderVLC;
  153. var pp: TglBitmapPixelPosition;
  154.     pf: TglBitmapPixelPositionFields;
  155. begin
  156.   pf:=[ffX];
  157.   pp.Fields:=pf;
  158.   pp.X:=VideoWidth;
  159.   pp.Y:=VideoHeight;
  160.   if fTexture1 = nil then
  161.     begin
  162.       fTexture1 := TglBitmap2D.Create(pp,ifRGBA8);
  163.       fTexture1.AddAlphaFromValue(255);
  164.       fTexture1.FreeDataAfterGenTexture := False;
  165.     end;
  166.   Move(VLCctx.vlcpixels[0],tRGBA(fTexture1.Scanline[0]^),VideoHeight*VideoWidth*4);
  167.   fTexture1.GenTexture;
  168.   glActiveTexture(GL_TEXTURE0);
  169.   fTexture1.Bind;
  170. end;
  171.  
  172. procedure Tfrmapri4.RenderGL;
  173. begin
  174.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  175.   glLoadIdentity;
  176.   glTranslatef(0, 0, -5);
  177.   glBegin(GL_QUADS);
  178.   glVertex3f(   0,   0, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,1); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,1);
  179.   glVertex3f(mio_width,   0, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,0);
  180.   glVertex3f(mio_width, mio_hength, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
  181.   glVertex3f(   0, mio_hength, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,1); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,1);
  182.   glEnd;
  183.   SwapBuffers(DC);
  184. end;
  185.  
  186. procedure Tfrmapri4.Button1Click(Sender: TObject);
  187. begin
  188.   VideoWidth :=mio_width;      //  VideoWidth :=720;
  189.   VideoHeight:=mio_hength;     //  VideoHeight:=576;
  190.  
  191.   Setlength(VLCctx.vlcpixels,VideoWidth*VideoHeight*4);
  192.  
  193.   libvlc_media :=  PasLibVlcMediaList1.GetItemAtIndex(0);
  194.   libvlc_media_parse(libvlc_media);
  195.  
  196.   libvlc_media_player := libvlc_media_player_new_from_media(libvlc_media);
  197.   libvlc_media_release(libvlc_media);
  198.  //******************************  Render video  720 x 576 ****************
  199.  
  200.    libvlc_video_set_format(libvlc_media_player,'RGBA',VideoWidth,VideoHeight,VideoWidth*4);
  201.    libvlc_video_set_callbacks(libvlc_media_player,@libvlc_video_lock,@libvlc_video_unlock,@libvlc_video_display,@VLCctx);
  202.  
  203.  // ******* Play to PasLibVlcmediaList  component visual ******************
  204.   PasLibVlcMediaList1.Play();
  205.  // ***************************************
  206.     Timer2.Enabled:=true;
  207.   DoPlay:=true;
  208.   StartTime:= GetTickCount;
  209.   while DoPlay do
  210.     begin
  211.       Render;
  212.       Application.ProcessMessages;
  213.     end;
  214.   if fClose then libvlc_media_player_stop(libvlc_media_player);
  215.   if fClose then PasLibVlcMediaList1.Stop;
  216. end;
  217.  
  218. procedure Tfrmapri4.Button2Click(Sender: TObject);
  219. begin
  220.   PasLibVlcMediaList1.Player.LogoSetFile('C:\film\logo\120x100.png');
  221.   PasLibVlcMediaList1.Player.LogoSetEnable(1);
  222.   label1.Caption:= inttostr(PasLibVlcMediaList1.Player.GetVideoWidth());
  223.   label2.Caption:= inttostr(PasLibVlcMediaList1.Player.GetVideoHeight());
  224. end;
  225.  
  226. procedure Tfrmapri4.Button3Click(Sender: TObject);
  227. begin
  228.   PasLibVlcMediaList1.Stop;
  229. end;
  230.  
  231. procedure Tfrmapri4.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  232. begin
  233.     fClose:=True;
  234.   DoPlay:=false;
  235. end;
  236.  
  237. function libvlc_video_lock(opaque : Pointer; var planes : Pointer) : Pointer; cdecl;
  238. begin
  239.   planes := @(frmapri4.VLCctx.vlcpixels[0]);
  240.   Result:=nil;
  241. end;
  242.  
  243. function libvlc_video_unlock(opaque : Pointer; picture : Pointer; planes : Pointer) : Pointer; cdecl;
  244. begin
  245.   Inc(frmapri4.fc);
  246.   frmapri4.NewFrame:=true;
  247.   frmapri4.VLCRenderTime:=GetTickCount;
  248.   Result:=nil;
  249. end;
  250.  
  251. function libvlc_video_display(opaque : Pointer; picture : Pointer) : Pointer; cdecl;
  252. begin
  253.     ////////////////
  254. end;
  255.  
  256. end.
  257.  

Autor:  carmeloconny [ Di Dez 02, 2014 09:34 ]
Betreff des Beitrags:  Re: TPasLibVlcPlayer not Render with openGl

I discovered that libvlc_media: PasLibVlcMediaList1.GetItemAtIndex = (0); does not assign the correct media. How can I point to the current media file of TPasLibVlcList1? To go right parameters to libvlc_video_set_callbacks (libvlc_media_player ... etc.

Code:
  1.  
  2. libvlc_media :=  PasLibVlcMediaList1.GetItemAtIndex(1); // not assign correct media
  3.   libvlc_media_parse(libvlc_media);
  4.  
  5.   libvlc_media_player := libvlc_media_player_new_from_media(libvlc_media);
  6.   libvlc_media_release(libvlc_media);
  7.    //*************************
  8.    libvlc_video_set_format(libvlc_media_player,'RGBA',VideoWidth,VideoHeight,VideoWidth*4);
  9.    libvlc_video_set_callbacks(libvlc_media_player,@libvlc_video_lock,@libvlc_video_unlock,@libvlc_video_display,@VLCctx);    
  10.  

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/