Recent

Author Topic: [Open source] LibFFPlay  (Read 18592 times)

mercury

  • Full Member
  • ***
  • Posts: 154
[Open source] LibFFPlay
« on: June 23, 2016, 02:54:01 pm »
LibFFPlay is a simple C lib for video/audio playback. Not only for Pascal, LibFFPlay can use by other program language as normal C lib. LibFFPlay is modified from FFPlay, a standalone video player by FFmpeg. LibFFPlay make FFPlay possible to embed in program as a component. With LibFFPlay you can use all the command line functions that FFPlay have.
This is my first component. I know the code is not very precise, if you find any problem please tell me. Welcome any comments and suggestions.
« Last Edit: June 24, 2016, 02:54:26 am by mercury »

mercury

  • Full Member
  • ***
  • Posts: 154
screenshot
« Reply #1 on: June 23, 2016, 02:54:14 pm »
screenshot:
« Last Edit: June 23, 2016, 03:16:35 pm by mercury »

mercury

  • Full Member
  • ***
  • Posts: 154
Download
« Reply #2 on: June 23, 2016, 02:54:25 pm »
v1.2 src.7z
Code: [Select]
SIZE   : 241339
CRC32  : 92c98686
MD5    : 58570cafa5092cea2ecac393e0d0dde8
SHA1   : f3802c14f94890e9d0ad05c5cd2a443419b7cb0e
SHA512 : e094e93162a738a7a94f68c0cb46f223a4a92ee9f9e81866b14297fc554b8f77af2d392bc317616e851f8d6ead559f0e6b0d6046693533dbb519ebce6fe7232a
download : below (If you can't see the attachment, maybe login is needed)

v1.2 bin-win32.7z
Code: [Select]
SIZE   : 6537210
CRC32  : 5c6a97ba
MD5    : 9ffb11b3188d3cc71104bd70f05507c3
SHA1   : b5a012f608d6e3183a1b3ca0bdf06cc76fbf0833
SHA512 : ef7bd74e422c8d30929e872a90d58863ff7a083a45450ab81dd42ca87a7de683d2957d2c68e3e673e1e7e073b9d39802d37944aaab9a94c095b8a5fa96728bdb
download : http://d-h.st/lkkm
« Last Edit: June 23, 2016, 03:52:58 pm by mercury »

mercury

  • Full Member
  • ***
  • Posts: 154
License
« Reply #3 on: June 23, 2016, 02:54:43 pm »
LibFFPlay is licensed under LGPL v2.1+ or GPL v2+. (Same as FFmpeg) Depend on how you configure FFmpeg.
« Last Edit: June 23, 2016, 03:09:06 pm by mercury »

mercury

  • Full Member
  • ***
  • Posts: 154
Guide
« Reply #4 on: June 23, 2016, 02:54:57 pm »
Compile LibFFPlay
If you don’t want do this, download the pre-compiled library. (Actually, this is really complex)
1. If you are using Windows, maybe you don’t have GCC. I recommend MinGW. (http://mingw.org/)
   If you are using Linux, normally you already have GCC installed. Check "gcc -v".
   To compile FFmpeg you also need Yasm (http://yasm.tortall.net/) or NASM (http://www.nasm.us/).
2. Download FFmpeg (https://ffmpeg.org/releases/). I tested with 2.8.6, later version should working.
3. For video/audio output you need SDL. (https://www.libsdl.org/)
   Download and install SDL 1.2.15. (2.X is not compatible)
4. If you want more functions for FFmpeg, install the external libraries you want.
   For me, I use libass, libfreetype and libfribidi.
5. Now you can compile FFmpeg. (Change the configure option to fit yours)
   configure --disable-debug --enable-libass --enable-libfreetype --enable-libfribidi
   make
   make install
6. Finally go to folder "LibFFPlay". Replace the "config.h" by yours.
   Compile the dll or so. And put them in your system path, or the same folder which your program in.

Run demo
Go to folder "Demo Pascal" compile and run.
Transfer the arguments like "ffplay(Length(argv), @argv[0]);".
Check https://ffmpeg.org/ffplay.html for useful options.
« Last Edit: June 24, 2016, 02:54:41 am by mercury »

mercury

  • Full Member
  • ***
  • Posts: 154
Reserve
« Reply #5 on: June 23, 2016, 02:55:14 pm »
Reserve

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [Open source] LibFFPlay
« Reply #6 on: June 23, 2016, 04:55:39 pm »
inside unit1
Code: [Select]
  if AFFplay.Finished then begin
    AFFplay.Free;
    AFFplay := TFFplay.Create(True);
  end;
Class AFFplay does not seem to contain a property or method named finished.

I replaced it with:
Code: [Select]
  if Assigned(AFFplay) then
  begin
    AFFplay.Free;
    AFFplay := TFFplay.Create(True);
  end;

mercury

  • Full Member
  • ***
  • Posts: 154
Re: [Open source] LibFFPlay
« Reply #7 on: June 23, 2016, 05:05:02 pm »
Class AFFplay does not seem to contain a property or method named finished.
Yes, but parent class TThread have.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [Open source] LibFFPlay
« Reply #8 on: June 23, 2016, 05:26:12 pm »
Let me re-phrase:
The compilation failed for me because the compiler states it is unable to find that property (i personally couldn't care less ;-) )

Ok, i need to update the lazarus installed on this machine :D

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [Open source] LibFFPlay
« Reply #9 on: June 29, 2016, 04:44:17 pm »
@mercury

Hi mercury !
I'm delighted, to find finally somebody else, who's interested in FFmpeg-Stuff.  :)

Quote
LibFFPlay is a simple C lib for video/audio playback...can use by any program language as normal C lib.
In other Words:
A C-DLL-File, that simply exports basic PlayerFunctions, and -Parameters from the original FFPlay-C-File.
In this pragmatic Way, of course, You don't have to bother too much with the FFPlay-SourceCode itself, and
You avoid messing around with PascalHeaders, that by Natur never can be really complete and up-to-Date, and
it's much easier to follow the latest FFmpeg-Updates.

So far, so good, but: (Sorry, but now some "buts" are coming.)  ;)

> What's the Advantage of Your 'LibFFPlay', compared with:

- Acinerella:
  https://github.com/astoeckel/acinerella

- FFDec:
  http://sourceforge.net/projects/ffdec


> ad 'FPS', shown in Your Screenshot:
In Your Screenshot, there is a Series of whole-numbered (integer) Values from 23 to 25, called 'FPS'.
This 'FPS' is simply calculated by Counting up the 'BGRABitmaps', and then showing the Sums per Sec., see:
Unit 'LibFFplay', Line 427: "FPS += 1;", and Unit 'Unit1', Line 72: "TForm1.Timer1Timer".
Some might confuse this 'FPS' with FFmpeg's FPS, which is the 'Number of Frames in a STREAM per Sec.', whereat
EACH Stream in the AV-Stream may have DIFFERENT TotalAmounts of Frames, and FrameRates.
It's then up to the PlayerCode, to put all this Mess in Order. That's why progging a MediaPlayer is
much more complex, than progging an AudioPlayer, that only has to deal with ONE Stream: Audio.
Your 'FPS' rather represents an approximate 'Number of DISPLAYED VideoPictures per Sec.', after
having passed all the Bunch of Decoding, Syncing, and eventually Skipping VideoFrames.


> ad AudioData-Callback-Function:
There isn't - As long as You don't add an AudioData-Callback, the Sound actually comes from
the FFPlay-C-File's SDL-Audio, and You (or eventual Users of 'LibFFPlay') can't implement any
own AudioCode (e.g. DSP), or add another Audio-Output (e.g. Portaudio).


> ad VideoData-Callback-Function 'Cb_display()':
Currently Your VideoData-Callback is placed at a Position in the FFPlay-Code, where the PictureQueue (now called 'FrameQueue') is completely left out from the VideoSync-Process, see:  ;D
(Your modified) 'ffplay.c', Line 1815.
(I saw, that this Part is marked as "TODO", so I suppose, You'll fix that.)

Here's a simplified WorkFlow of, how 'ffplay.c' generates a synced VideoImage:
AV-Stream -> Read VideoFrames -> Video-PacketQueue -> Decode VideoPackets -> Sync VideoFrameIn-PTS ->
 Scale to VideoFrameOut -> PictureQueue -> Fetch synced(!) VideoPicture -> Display (Puh!).

Your VideoData are fetched after 'Scale to VideoFrameOut' (= the VideoPicture), but to achieve a really
accurate VideoSync, 'ffplay.c' synchronizes the PTS of each completely decoded VideoFrame AND
calculates the Delay in Ms for each single VideoPicture, that shall be displayed.

=> The right Place to fetch VideoData would be at Line 971 of (Your modified) 'ffplay.c',
     exactly where You commented out "SDL_DisplayYUVOverlay(vp->bmp, &rect);".
-> Why don't You put Your VideoData-Callback there ?

To demonstrate the PictureQueue-Sync at Work, You'll find in the Attachment a ScreenShot of
a typical Series of real Values for 'Current VideoPictures per Sec.', generated by my 'FFPlay4Laz'.
(http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html)

BTW:
Please, mark the Changes, You've made inside the original FFPlay-C-Code, to make
it easier for Others to differ between the original Code and Your Modifications.


Quote
If you can't see the attachment, maybe login is needed
To see the Attachment, Login IS needed.

Tip for You:
You may use 'AV_TIME_BASE', instead of '/ 1000 / 1000'.

Tip for all the Others in this Forum:
'LibFFplay\libffplay.cbp' is a Code::Blocks-ProjectFile:
http://www.codeblocks.org.
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: [Open source] LibFFPlay
« Reply #10 on: June 29, 2016, 06:09:32 pm »
It would seem to me that http://winff.org (written with Free Pascal and Lazarus) is related to this discussion?
Regards,
Paul Breneman
www.ControlPascal.com

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [Open source] LibFFPlay
« Reply #11 on: June 29, 2016, 06:14:59 pm »
@Paul Breneman

'WinFF' is a MediaFile-Transcoder (= Encode/Decode), using FFmpeg.
Both, the Transcoder-, and the PlayerPart use CommandLine-FFmpeg-EXEs.
(I've already mentioned 'WinFF' in my 'FFPlay4Laz'-Thread.)
« Last Edit: June 29, 2016, 06:30:09 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

mercury

  • Full Member
  • ***
  • Posts: 154
Re: [Open source] LibFFPlay
« Reply #12 on: July 03, 2016, 05:00:49 am »
About Acinerella and FFDec
With both two libs, you must know about AVInfo, AVPacket. They are simplified FFmpeg, and lost many functions, like subtitle. LibFFPlay can play subtitle, use video/audio filter and many other functions, just add the arguments to “ffplay(argc: longint; argv: PPchar)” as what ffplay command line do. The most important thing is you are no need care about annoying things like AVInfo, AVPacket or do a main loop.

About demo FPS
That’s just a demo. It count how many frames showed in THIS second. So if the real FPS is not integer, it will jump between±1.
To get real FPS, you should count by frames/time and use a more advance timer like EpikTimer.

About audio callback
I had thought about this. But it’s not much important for me. If you want audio callback, hack it yourself.

About DTS & PTS
I know the display order is not right. As I said “I know the code is not very precise”. But I believe without reading the code, because of vision persistence most people can’t find anything wrong. Of course this should be fix. But at present I don’t know how to do it.
@metis You are more professional than me, maybe you can do this. Actually the reason I made LibFFPlay because I can’t find any exist lib fit for my purpose. I have looked your FFPlay4Laz, but you are reluctance to share your code or even a snippet. (http://forum.lazarus.freepascal.org/index.php/topic,26666.msg170107.html#msg170107 http://forum.lazarus.freepascal.org/index.php/topic,26666.msg194244.html#msg194244) So I made LibFFPlay and hope it can help others.

Mark the changes
No, it only make confuse. To find what different between the FFplay, you can use Meld or something similar.

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [Open source] LibFFPlay
« Reply #13 on: July 15, 2016, 07:47:56 pm »
@mercury

Quote
no need care about annoying things like...
Just, what I said: The pragmatic Way - Why not, but
the more Functionality You want to add to Your 'LibFFPlay', the more Changes You have to make on the original FFPlay-C-File (and its Updates!).

Quote
About DTS & PTS + I know the display order is not right.
This is not a Question of "DTS & PTS" or the "display order"; it's a Question of accurate Synchronism.
The current Version of my 'FFPlay4Laz' only does "FiFo" (= First in, First out), means:
The VideoImages are displayed in the same Order as they were decoded, and put into the Queues.
Afaik, FFmpeg already puts the VideoFrames into the right Order. (Tell me, if I'm wrong)

Quote
you are reluctance to share your code or even a snippet.
Well, here is a Summary of the "Snippets", I've already posted for FFmpeg:

- How to display FFmpeg-VideoFrames with SDL's YUV-Overlay, posted March 11, 2015
   (= 'filtering_video_plus_sdl_yuv.lpr.txt' + 'uff2sdlv_yuv.pas.txt'), see:
   http://forum.lazarus.freepascal.org/index.php/topic,26666.msg171317.html#msg171317

- The whole Structure for a basic FFmpeg-MediaPlayer, posted Dec. 21, 2015
   (= my FPC-Port of the Dranger-C-File 'tutorial08.c'), see:
   http://forum.lazarus.freepascal.org/index.php/topic,26666.msg196377.html#msg196377

- The entire SourceCode to read out StreamInfos via FFmpeg-DLLs, posted April 22, 2016
   ('= 'FFStreamInfo.lpr.txt'), see:
   http://forum.lazarus.freepascal.org/index.php/topic,22038.msg208700.html#msg208700

These "Snippets" contain all the basic Steps, to write a FFmpeg-MediaPlayer with FPC.
Furthermore, I always offered to answer to any specific Question, but in the last one and a half years, there wasn't any.  :'(
My FFPlay4Laz-Project is not meant to provide an InstantSolution, but to encourage others to deal with FFmpeg-DLLs.
Be honest, would You have started Your Project, otherwise ? Obviously not, see:
Quote
Actually the reason I made LibFFPlay because I can’t find any exist lib fit for my purpose.
Same happened to me. That's why I started 'FFPlay4Laz', but what's Your Purpose ?
Tell You, what is mine:
An AV-Player (don't need Subtitles), that opens/closes, pauses/resumes, and seeks really FAST, and all of this with high AV-Synchronism, and outstanding SoundQuality - I don't think, that You can achieve this with a Front-End-DLL.

Quote
I don’t know how to do it. + You are more professional than me, maybe you can do this.
Don't think, that I'm more professional - maybe I'm only more diligent.
I'd like to help You, but each Time I try to compile Your DLL, I get this Error (see the Attachment).
Your App then starts with the resulting DLL, but when I load a MediaFile, it immediately crashes.
-> Please, put a working DLL into the Attachment, so that I can run 'LibFFPlay' on my Win32-PC.

Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

mercury

  • Full Member
  • ***
  • Posts: 154
Re: [Open source] LibFFPlay
« Reply #14 on: July 18, 2016, 06:13:40 am »
the more Functionality You want to add to Your 'LibFFPlay', the more Changes You have to make on the original FFPlay-C-File (and its Updates!).
I only want ffplay embed in my program. Not a full ffmpeg. And it’s no need to change LibFFplay when update ffmpeg to a new version, it will compatible.

Afaik, FFmpeg already puts the VideoFrames into the right Order. (Tell me, if I'm wrong)
See http://dranger.com/ffmpeg/tutorial05.html
You must synchronize it yourself. BTW, not all video have different DTS & PTS.

Don't think, that I'm more professional - maybe I'm only more diligent.
I'd like to be diligent. But time not allowed. I must finish my project before the deadline.

I'd like to help You, but each Time I try to compile Your DLL, I get this Error (see the Attachment).
Your App then starts with the resulting DLL, but when I load a MediaFile, it immediately crashes.
-> Please, put a working DLL into the Attachment, so that I can run 'LibFFPlay' on my Win32-PC.
The pre-compiled library and demo are tested under Windows XP to 8.1 both x86 & x64.

If anyone get into trouble when compile the LibFFplay.
Please post your environment details, include OS, compilers, ffmpeg, dependence libs. Then, the error log.



 

TinyPortal © 2005-2018