Recent

Author Topic: LazFFPlay4Windows - Demo-GUI and Sources  (Read 3886 times)

metis

  • Sr. Member
  • ****
  • Posts: 300
LazFFPlay4Windows - Demo-GUI and Sources
« on: May 18, 2023, 02:36:04 pm »
Hi to all, who are Looking for a (Windows only) FFmpeg-based MediaPlayer-Component for Lazarus !

This Post brought my Attention back to Somby's MediaPlayer after Years.

Since he started his Lazarus Mediaplayer with SDL2 and FFMPEG 5 Years ago, he really did a lot of Work (and Changes) on it.
First of all, he completely abandoned his simplified Synchronization, and replaced it with
the SyncMechanism of FFmpeg's TestPlayer FFplay, which works really precise and fast.
The current Version is v3.1.0.0 for FFmpeg v6.0 and SDL2 v2.26.4.

Now, the PlayerCore (= Unit 'uexplayer.pas') is a direct Port of FFmpeg's ffplay.c to FPC-OOP.
Alas, the PlayerComponent is derived from TWinControl, and big Parts of the PlayerCode are Windows only, whilst the original C-Code is cross-platform (why?  :'(  ).

I wrote a Demo-GUI, stripped down to the Essential, that shows the Usage of Somby's MediaPlayer-Component.
(see in the Attachment 'DemoGUI_LazProject.7z' = Complete Project with all Sources and the original C-File, renamed to 'ffplay-6.0.c'.)
IMHO by the Way a very good Opportunity to compare Delphi/FPC- and C++-Programming. 

The Dependencies (= the DLLs for FFmpeg v6.x and SDL2) are not included, but they can be easily downloaded.
If You take the WinXP32-compatible FFmpeg-Builds by Reino, the Player works from WinXP to Win10 and on Wine for Unix-like OSs,
just like the latest Release of my FFPlay4Laz2.
(-> Download 'ffmpeg-6.1-588-4006c71-win32-shared-xpmod-sse.7z' - Unlike FFPlay4Laz, all FFmpeg-DLLs are required.)

Tested on: - WinXP, Win7 and Win10
                 + Linux Mint v17.2 with Wine v1.6.2  :)
« Last Edit: June 16, 2023, 12:43:03 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

justinpang

  • Newbie
  • Posts: 3
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #1 on: May 21, 2023, 06:07:11 pm »
Hi,
Unfortunately, i cann't run the demo, cause it access error memory addr. Compile is okay. i wonder whether copy wrong SDL2 or ffmpeg dll. is there any special dll required?
 

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #2 on: May 21, 2023, 06:12:04 pm »
No special DLLs required. Only the ones shown in the Image above.

Which FFmpeg-DLLs do You use ?
Which SDL2-DLL do You use ?
Which OS do You use ?
« Last Edit: May 21, 2023, 06:16:21 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

TRon

  • Hero Member
  • *****
  • Posts: 2516
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #3 on: May 21, 2023, 08:57:11 pm »
I got the same result:
- floating point exception on startup
- access violation when loading a wma file (or dropping it)

used archives:
- ffmpeg-6.1-588-4006c71-win32-shared-xpmod-sse.7z
- SDL2-2.26.5-win32-x86.zip

btw The source-code is a mess imho. Wanted to try make it cross-platform but not even going to as it doesn't seem to work at all.

You asked why ? Answer is because it is not a direct copy of ff-play. ff-play uses an SDL window while the Pascal code  got that stripped and replaced it with a Delphi/Lazarus form/component. And as you found out doing it the Windows way  :'(
« Last Edit: May 21, 2023, 09:02:42 pm by TRon »

justinpang

  • Newbie
  • Posts: 3
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #4 on: May 22, 2023, 01:57:34 am »
No special DLLs required. Only the ones shown in the Image above.

Which FFmpeg-DLLs do You use ?
Which SDL2-DLL do You use ?
Which OS do You use ?

FFMpeg DLL by ffmpeg-6.1-588-4006c71-win32-shared-xpmod-sse
SDL2:2.26.5.0
OS: WIN11


justinpang

  • Newbie
  • Posts: 3
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #5 on: May 23, 2023, 02:13:55 am »
No special DLLs required. Only the ones shown in the Image above.

Which FFmpeg-DLLs do You use ?
Which SDL2-DLL do You use ?
Which OS do You use ?

FFMpeg DLL by ffmpeg-6.1-588-4006c71-win32-shared-xpmod-sse
SDL2:2.26.5.0
OS: WIN11

I added the addtional DLLs, as the attached pic shows.
And the Demo shows no error.
I can't tell which is cause the error right now.


TRon

  • Hero Member
  • *****
  • Posts: 2516
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #6 on: May 23, 2023, 08:58:47 am »
Adding that my issue might be related to the VM setup. Some tracing revealed that sdl2.dll crashes
Quote
00:00:00.681: GetProcAddress(0x5ED00000 [c:\windows\system32\OPENGL32.DLL], "glBegin") called from "z:\simple\SDL2.DLL" at address 0x6C80060B and returned 0x5ED028F0.
00:00:00.691: GetProcAddress(0x5ED00000 [c:\windows\system32\OPENGL32.DLL], "glBindTexture") called from "z:\simple\SDL2.DLL" at address 0x6C80060B and returned 0x5ED02FA4.
00:00:00.691: GetProcAddress(0x5ED00000 [c:\windows\system32\OPENGL32.DLL], "glBlendEquation") called from "z:\simple\SDL2.DLL" at address 0x6C80060B and returned NULL. Error: The specified procedure could not be found (127).
00:00:00.691: First chance exception 0xC0000005 (Access Violation) occurred at address 0x00000000.

The resulting excerpt as posted was taken from a very simple SDL2 example from the Free Pascal meets SDL website. So, not related to the LazFFPlay4Windows project (it just happens the issue showed its colors there first for me).

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #7 on: May 23, 2023, 02:19:47 pm »
Sorry for my late Reply, but sometimes I have to work.

@TRon
Still don't know, which OS You're using - VM, o.k., but which one. On Linux Mint it works for me with Wine.
(see below "@TRon + justinpang", why this may be important.)

Quote
access violation when loading a wma file
I just tried it out on my WinXP: Works - see attached '01_PlayingWMA_WinXP.jpg'.
But there is a Bug with Audio-only: When Seeking paused, there is no OnProgress-Event, so that the Player's WaveForm, Position, etc. are not updated.
BTW: Playing (among others) WMA-Files was in 2014 the Reason for me to switch from Fmod/FmodEx (= Audio-only) to FFmpeg as Decoder.

Quote
The source-code is a mess
No Comment - I did not write that. I can only confirm, that it works by and large.
Writing an AudioVideo-Player is much more complicated than Writing an Audio-Only-Player.
It's not only the AV-SyncingStuff like most People think.
Everyone is called upon to write some better Code.  ;)

Quote
Wanted to try make it cross-plattform ... it doesn't seem to work at all
It definitively works.
I tried it on my WinXP SP3, Win7 Ultimate, Win10 and Linux Mint v17.2 + Wine v1.6.2 - all 32-bit.

If You want to make that Code cross-platform with FPC, see here:
"I've replaced all Windows-API-Calls with SDL2-Calls to make it cross-plattform".
This is the BasicStructure for a working cross-plattform FFmpeg-based MediaPlayer with SDL2, written in FPC (not OOP).

Quote
it is not a direct copy of ff-play + ff-play uses an SDL window + You asked why ?
I wrote, that it's "a direct Port ... to FPC-OOP" (this is not the same).
But, it's a direct Copy of FFplay's Strategy for Rendering Multimedia-Files and -Streams, where he...
• completely left out the SDL2-EventLoop
• replaced all SDL2-Threads, -Mutexes and -ConditionVariables with Windows-dependent Code (again, why?)
• creates the SDL2-Window within his PlayerComponent, which is easy:
   You just have to replace FFplay's 'SDL_CreateWindow()' with 'SDL_CreateWindowFrom()'.
I still ask "why?", because it makes no Sense at all to turn something cross-plattform into something plattform-dependent.  :'(


@justinpang
Didn't try it on Win11, but should work.
Didn't try it with SDL2 v2.26.5, but should work.

On Win10 and Linux Mint + Wine, I use ffmpeg-6.1-588-4006c71-win32-shared-xpmod-sse + SDL2 v2.26.4.0.
On Win11, You may try Somby's FFmpeg- and SDL2-Builds:
-> GoTo: "FFMPEG/SDL2".
(Somby's WebSite obviously only exists in German, couldn't find an English Version.)
I downloaded and tested it yesterday on Win10: Works - see attached '02_FFmpeg+SDL2-BuildsBySomby_Win10.jpg'.

Quote
I added the addtional DLLs ... And the Demo shows no error.
It depends on the Configuration of the FFmpeg-Build, whether those external DLLs are included in the corresponding FFmpeg-DLLs, or not.
Perhaps Reino's latest FFmpeg-Build includes DLLs that are still compatible with Win10, but no longer compatible with Win11 - don't know.
His Aim is to still generate FFmpeg-Builds, which are compatible with WinXP 32-bit. You can see the current BuildConfiguration in the first Post.


@TRon + justinpang
On WinXP, I had the same Error with several SDL2-Versions. The only SDL2-Version, that works on my WinXP is v2.0.14.0.
(Don't ask me why - I simply tried it out.)

If it still does not work after having tried out several SDL2-Versions, try this:
-> GoTo Line #5877 in 'uexplayer.pas', and disable...
Code: [Select]
if (m and SDL_INIT_VIDEO)=0 then begin
    if SDL_InitSubSystem(SDL_INIT_VIDEO)<0 then begin
       raise Exception.CreateFMT(rsClassFunctionError,[classname,'SDL_InitSubSystem(SDL_INIT_VIDEO)',SDL_GetError]);
    end;
    FSDLSubSystems:=FSDLSubSystems or SDL_INIT_VIDEO;
end;
This is not from the original C-File; Somby added it - FFplay uses 'SDL_Init() + Flags'.

Last but not least, don't forget that Somby wrote his own minimal FPC-Wrappers for FFmpeg and SDL2.
So maybe the Problem is there.

I use in my FFPlay4Laz-Project FFmpeg-Wrapper from FFVCL and SDL2-Wrapper by Tim Blume - Works.  :)
« Last Edit: June 13, 2023, 12:24:06 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

TRon

  • Hero Member
  • *****
  • Posts: 2516
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #8 on: May 24, 2023, 06:23:33 am »
Still don't know, which OS You're using - VM, o.k., but which one.
Ah yes sorry metis, my bad.

VB 7.08 with XP Pro SP3 32-bit (pretty much pristine except for an update of/in mvc-redis in order to be able to trace).

ffplay and ffmpeg exe's work as intended for me.


Quote
No Comment - I did not write that. I can only confirm, that it works by and large.
Ha, yes ofc. but working and being able to read the code between all the bits that are commented is a bit of a pita. Seems like everything (in unit uexplayer) was just stuffed in there in a hurry.

That the code of lazffplay4windows works for you is no guarantee it will work cross-platform once it is altered to be cross-platform  :)

Quote
If You want to make that Code cross-platform with FPC, see here:
I'll have a look thanks. The basic setup of the ff/sdl units is pretty neatly done so is a good base to start with.


Quote
@TRon + justinpang
On WinXP, I had the same Error with several SDL2-Versions. The only SDL2-Version, that works on my WinXP is v2.0.14.0.
(Don't ask me why - I simply tried it out.)
Sofar I have tried with SDL versions 2.08, 2.26.3 and 2.26.5 and unfortunately they all crashed for me in the same way. I'll have a try with 2.0.14.

I'll keep your suggestions of modifying the code in mind, thank you for that.

Quote
Last but not least, don't forget that Somby wrote his own minimal FPC-Wrappers for FFmpeg and SDL2.
So maybe the Problem is there.
And as said above: neatly done but indeed it could be there is something amiss there. It would be tedious to check every little tidbit though.
« Last Edit: May 24, 2023, 06:25:53 am by TRon »

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #9 on: May 24, 2023, 01:29:46 pm »
@TRon

Quote
VB 7.08 with XP Pro SP3 32-bit
I got the same WinXP-Version - All my FFmpeg4Lazarus-Projects, that I compile on that WinXP work perfectly
on my Linux Mint v17.2 + Wine v1.6.2 (totally pristine), together with Reino's XP-compatible FFmpeg-Builds.
SDL2, however I need to check for each Platform. Sometimes everything works, but Audio is too fast (why?), etc.
Try again with Wine, instead of VirtualBox.

Quote
ffplay and ffmpeg exe's work as intended for me.
Of course, because ffplay.exe does not have the Code, where the Error occurs when Loading the Component.
(see above: "If it still does not work after having tried out several SDL2-Versions, try this:" )
And, ffmpeg.exe does not require SDL/SDL2.

Quote
Seems like everything ... was just stuffed in there in a hurry.
Bingo! That's exactly my Impression. :D

Quote
all the bits that are commented
Most of those Comments are the corresponding C-CodeLines in FFplay.
Just copy, then search them in the 'ffplay-6.0.c' included in the 7z-File above, and You are at the right Position in the original C-Code.

Quote
it could be there ... It would be tedious to check every little tidbit though
That's why I prefer proven FPC-Headers.
« Last Edit: May 24, 2023, 02:58:28 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

TRon

  • Hero Member
  • *****
  • Posts: 2516
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #10 on: May 25, 2023, 06:46:52 am »
If You want to make that Code cross-platform with FPC, see here:
"I've replaced all Windows-API-Calls with SDL2-Calls to make it cross-plattform".
This is the BasicStructure for a working cross-plattform FFmpeg-based MediaPlayer with SDL2, written in FPC (not OOP).
I finally managed to get that going on my Linux machine.

It was not really cross-platform, now was it ?  :P (that was rhetorical because it did not compile out of the box as Linux target).

I needed to convince FPC to link against the old(er) av-libraries. I still got 1 issue left and that is with libswresample that keeps dragging in libavutil.so.58 instead of libavutil.so.57 ... but *fingers crossed* it seems to work as there is sound and video.

I need to do some more testing because some video's (MP4's) seem to run out of sync by slowing down to later try and catch up (double/triple frame rate for graphical output while audio seems to stay in sync). I take it that is related to the av libraries and not your example code.

Thank you for the example metis !

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: LazFFPlay4Windows - Demo-GUI and Sources
« Reply #11 on: May 25, 2023, 05:38:54 pm »
Quote
It was not really cross-platform, now was it ?
I write all my Programs and Ports on WinXP, never Eliminating cross-platform Code, like Somby did.
In this Sense cross-platform C-Originals should stay cross-platform in FPC.
In the Case of FFExample by Lovesan, I've replaced Windows-dependent C-Code with cross-platform SDL2-Code for FPC, but...

Quote
it did not compile out of the box as Linux target
...I actually never compile on other Targets than that WinXP, simply because there is no Need for me to do so.
All 32-bit Binaries, that I generate this Way work fine on all Systems, that I use.
That's the banal Reason, why I always write "Tested on WinXP, Win7, Win10 and Linux Mint+Wine".
Now, everybody may take those Sources, and compile them on his own Platform (well, maybe after some smaller Modifications).
And, if perhaps somebody adds conditional Compilation for plattform-dependent Codes and publishes them in this Forum, so much the better. :D

Quote
I needed to convince FPC to link against the old(er) av-libraries.
Where are those shared FFmpeg-LIBs for Linux from, that You're trying to link against ?
Which FPC-Headers are You using on Linux ?  Where are they from ?
What "did not compile out of the box as Linux target" ?
Do not forget: FFmpeg is under heavy Development with quite a lot of Changes with each Version, so that
You always have to use the corresponding Versions of Headers and Binaries, otherwise it won't work.
SDL2 doesn't change that much.

Quote
some video's (MP4's) seem to run out of sync + is related to the av libraries and not your example code.
It's the ExampleCode ( :-X): There, Video is synced to Audio in a very basic Way, means:
Audio runs as it's decoded and put out via SDL2-Audio, and Video is synced to it.
If Your System is too slow to decode the VideoFrames in Time, will happen what You've described.
That SyncMechanism origins from very early FFplay-Versions. Beside of that, there is no
FrameDrop-Mechanism implemented yet, so that highly compressed Videos might hang behind on slow Systems.
If You need (much) better AV-Syncing with VideoFrame-Dropping, see the C-Codes of newer FFplay-Versions (= ffplay.c in [fftools] ).
Somby's FPC-PlayerCore has the latest and best Syncing from FFmpeg v6.0, but crippled to Windows only.  :(

Quote
Thank you for the example metis !
:)
« Last Edit: May 28, 2023, 01:39:10 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018