Lazarus

Programming => Graphics and Multimedia => Audio and Video => Topic started by: CM630 on September 16, 2013, 10:40:09 am

Title: Component for retrieving data from video files?
Post by: CM630 on September 16, 2013, 10:40:09 am
Does anyone know a free component for retrieving data from video files (codec info, FPS, bit rated, etc)?
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on September 16, 2013, 01:18:54 pm
Component wise you can extract some of the info you're looking from using the DSPack on Windows.

For cross-platform work, I keep hoping someone will translate the ffmpeg headers for me ;-)  Until then, you can call ffmpeg from the command line using TProcess.  It's got a superbly comprehensive list of attributes it returns...

UPDATE:  Did I say ffmpeg?  I meant ffprobe (same library)
http://ffmpeg.org/ffprobe.html

Function to call ffprobe (shows the parameters I use)
Code: [Select]
Function ProbeFile(sFilename: String): String;
Var
  sCommand: String;
Begin
  sCommand := Format('%s\ffprobe.exe -v quiet -show_format -show_streams "%s"',
    [ffmpegPath, sFilename]);
  Result := RunEx(sCommand, True);
End;

And here's my RunEx code (shamelessly lifted from the wiki, with an added option to redirect stderr (which causes problems if you don't redirect it))

Code: [Select]
Function RunEx(sCommandLine: String; bRedirectErr: Boolean = False): String;

Const
  READ_BYTES = 2048;

Var
  oStrings: TStringList;
  oStream: TMemoryStream;
  oProcess: TProcess;
  iNumBytes: Longint;
  iBytesRead: Longint;

Begin
  // A temp Memorystream is used to buffer the output
  oStream := TMemoryStream.Create;
  iBytesRead := 0;
  Try
    oProcess := TProcess.Create(nil);
    Try
      oProcess.CommandLine := sCommandLine;

      // We cannot use poWaitOnExit here since we don't
      // know the size of the output. On Linux the size of the
      // output pipe is 2 kB; if the output data is more, we
      // need to read the data. This isn't possible since we are
      // waiting. So we get a deadlock here if we use poWaitOnExit.
      If bRedirectErr Then
        oProcess.Options := [poNoConsole, poUsePipes, poStderrToOutPut]
      Else
        oProcess.Options := [poNoConsole, poUsePipes];

      oProcess.Execute;
      While oProcess.Running Do
      Begin
        // make sure we have room
        oStream.SetSize(iBytesRead + READ_BYTES);

        // try reading it
        iNumBytes := oProcess.Output.Read((oStream.Memory + iBytesRead)^, READ_BYTES);
        If iNumBytes > 0 Then
        Begin
          Inc(iBytesRead, iNumBytes);
        End
        Else
        Begin
          // no data, wait 100 ms
          Sleep(100);
        End;
      End;

      // read last part
      Repeat
        // make sure we have room
        oStream.SetSize(iBytesRead + READ_BYTES);

        // try reading it
        iNumBytes := oProcess.Output.Read((oStream.Memory + iBytesRead)^, READ_BYTES);

        If iNumBytes > 0 Then
        Begin
          Inc(iBytesRead, iNumBytes);
        End;
      Until iNumBytes <= 0;
      oStream.SetSize(iBytesRead);

      oStrings := TStringList.Create;
      Try
        oStrings.LoadFromStream(oStream);
        Result := oStrings.Text;
      Finally
        oStrings.Free;
      End;
    Finally
      oProcess.Free;
    End;
  Finally
    oStream.Free;
  End;
End;
Title: Re: Component for retrieving data from video files?
Post by: Fred vS on September 16, 2013, 11:46:45 pm
Quote
For cross-platform work, I keep hoping someone will translate the ffmpeg headers for me ;-)

Take a look here  ;) :

http://code.ohloh.net/file?fid=wbAk1NccIHoo6AiaRh5tm7fYZvs&cid=mAe06x6ROO4&s=&browser=Default&fp=226395&mpundefined&projSelected=true#L0 (http://code.ohloh.net/file?fid=wbAk1NccIHoo6AiaRh5tm7fYZvs&cid=mAe06x6ROO4&s=&browser=Default&fp=226395&mpundefined&projSelected=true#L0)
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on September 17, 2013, 04:54:55 am
@Fred vS
Nice one :-)  Many thanks for that link.  I had a play with this library when it was part of the UltraStar project, but couldn't get my head around it then.  I've had a quick play with the 3Dgrape version, seems easier now.  The rest of this post is more a reference for me as I intend to come back to this someday... 

If anyone is interested, the link Fred vS is posted is part of the 3Dgrape project (which looks rather interesting, no updates since 2011 though):  The 3Dgrape project includes ffmpeg headers that are released under LGPL.  I'm not sure if the ffmpeg header files here are a direct copy from the UltraStar project (I deleted my copy a year or two ago), or if they have been modified/improved in any way...

(3Dgrape was known originally known as scandraid)

http://svn.code.sf.net/p/scandraid/code/src/trunk/external/ffmpeg/

To use the above, you'll need to reference:
http://www.ffmpeg.org/documentation.html

Last time I checked there was already a pascal port as part of the ffpmeg library, but this was stale.  In fact, IIRC the UltraStar work was derived from the stale ffmpeg port.

The 3Dgrape guys have wrapped some useful functionality, creating a class that extract video data frame by frame.  It's then up the UI to render those frames.  Their work is in:
http://svn.code.sf.net/p/scandraid/code/src/trunk/gui/ffmpeg.pas  (which is the file @Fred vS referenced)

This file, however, is released under GPL (if I understand this correctly, this means you've got to release ALL your code if you use or modify this unit).  However, this unit has ties back to the rest of the 3Dgrape application.  I'm itching to use this file as a reference if I eventually produce a ffmpeg based player & probe, but due to the restrictive GPL I better stay clear...

@paskal

I'm going to have a quick play now, see if I can use the ffmpeg library here to extract the information you require...  I'll get back to you...

Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on September 17, 2013, 09:42:52 am
@Paskal

Ug.  The ffmpeg headers are still out of date, or at least incomplete.  No avcodec_open2 or avcodec_is_open for instance.

Nevertheless.  If you swipe the ffpmeg header units from the location I referred to last, and the dlls from the lib folder (http://svn.code.sf.net/p/scandraid/code/lib/win32/ffmpeg/)

Here's a quick (and very incomplete) wrapper unit...
Code: [Select]
Unit ffmpegWrapper;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils,
  avcodec, avformat, rational;

Type

  { TffmpegFile }

  { TffmpegFileInfo }

  TffmpegFileInfo = Class
  Private
    FFormatContext: PAVFormatContext;
    FFilename: String;
    function GetFormatContext: TAVFormatContext;
    Procedure SetFilename(AValue: String);
  Public
    Constructor Create;
    Destructor Destroy; Override;

    Procedure Clear;

    Function StreamCount: Integer;
    Function Stream(AStreamIndex: Integer) : TAVStream;

    Property Filename: String read FFilename write SetFilename;
    Property FormatContext: TAVFormatContext read GetFormatContext;
  End;

Function CodecContext(AStream : TAVStream) : TAVCodecContext;
Function CodecType(ACodecContext: TAVCodecContext): TCodecType;
Function CodecTypeAsString(ACodecContext: TAVCodecContext): String;
Function CodecTypeToString(ACodecType: TCodecType): String;
Function ToDouble(ARational: TAVRational) : Double;

Function OpenCodec(ACodecContext: TAVCodecContext) : TAVCodec;
Procedure CloseCodec(ACodecContext: TAVCodecContext);

Implementation

Function CodecContext(AStream: TAVStream): TAVCodecContext;
begin
  Result := AStream.codec^
end;

Function CodecType(ACodecContext: TAVCodecContext): TCodecType;
begin
  Result := ACodecContext.codec_type
end;

Function CodecTypeAsString(ACodecContext: TAVCodecContext): String;
begin
  Result := CodecTypeToString(ACodecContext.codec_type);
end;

Function CodecTypeToString(ACodecType: TCodecType): String;
Begin
  Case ACodecType Of
    CODEC_TYPE_UNKNOWN: Result := 'CODEC_TYPE_UNKNOWN';
    CODEC_TYPE_VIDEO: Result := 'CODEC_TYPE_VIDEO';
    CODEC_TYPE_AUDIO: Result := 'CODEC_TYPE_AUDIO';
    CODEC_TYPE_DATA: Result := 'CODEC_TYPE_DATA';
    CODEC_TYPE_SUBTITLE: Result := 'CODEC_TYPE_SUBTITLE';
    CODEC_TYPE_ATTACHMENT: Result := 'CODEC_TYPE_ATTACHMENT';
    CODEC_TYPE_NB: Result := 'CODEC_TYPE_NB';
  End;
End;

Function ToDouble(ARational: TAVRational): Double;
begin
  If ARational.num<>0 Then
    Result := av_q2d(ARational)
  Else
    Result := 0.0;
end;

Function OpenCodec(ACodecContext: TAVCodecContext): TAVCodec;
begin
  Result := avcodec_find_decoder(ACodecContext.codec_id)^;

  If (avcodec_open(@ACodecContext, @Result)<0) Then
    Raise Exception.Create('avcodec_open failed');
end;

Procedure CloseCodec(ACodecContext: TAVCodecContext);
begin
  // TODO:  Find out why this AV's.  It shouldn't...
  //avcodec_close(@ACodecContext);
end;

{ TffmpegFileInfo }

Procedure TffmpegFileInfo.SetFilename(AValue: String);
Var
  errCode: longint;

Begin
  If AValue = FFilename Then
    Exit;

  Clear;

  If FileExists(AValue) Then
  Begin
    errCode := av_open_input_file(FFormatContext, PChar(AValue), nil, 0, nil);
    If (errCode = 0) Then
      FFilename := AValue
    Else
      Raise Exception.CreateFmt('Error opening %s.  Error code %d', [AValue, errCode]);

    errCode := av_find_stream_info(FFormatContext);
  End;
End;

function TffmpegFileInfo.GetFormatContext: TAVFormatContext;
begin
  Result := FFormatContext^;
end;

Constructor TffmpegFileInfo.Create;
Begin
  FFormatContext := nil;
End;

Destructor TffmpegFileInfo.Destroy;
Begin
  Clear;

  Inherited Destroy;
End;

Procedure TffmpegFileInfo.Clear;
Begin
  FFilename := '';

  If FFormatContext <> nil Then
  Begin
    av_close_input_file(FFormatContext);
    FFormatContext := Nil;
  end;
End;

Function TffmpegFileInfo.StreamCount: Integer;
Begin
  Result := FFormatContext^.nb_streams;
End;

Function TffmpegFileInfo.Stream(AStreamIndex: Integer): TAVStream;
begin
  If FFormatContext <> nil Then
    Result := FFormatContext^.streams[AStreamIndex]^;
end;

Initialization
  // For now, this is easier than just registering the specific formats and
  // protocols that we need...
  av_register_all;

End.

And here's how to use it...
Code: [Select]
procedure TForm1.btnProbeClick(Sender: TObject);
Var
  oFile : TffmpegFileInfo;
  oStream: TAVStream;
  oCodecContext : TAVCodecContext;
  oCodec : TAVCodec;
  iStream: Integer;
  i: Integer;
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add('-TffmpegFileInfo-');
  oFile := TffmpegFileInfo.Create;
  Try
    oFile.Filename := FileNameEdit1.FileName;

    Memo1.Lines.Add(Format('Stream Count = %d', [oFile.StreamCount]));
    For i := 0 To oFile.StreamCount-1 Do
    Begin
      oStream := oFile.Stream(i);
      Memo1.Lines.Add(       '  -----------------');
      Memo1.Lines.Add(Format('  Stream ID: %d', [i]));
      Memo1.Lines.Add('');

      Memo1.Lines.Add(Format('  Frame Rate (fps): %f', [ToDouble(oStream.r_frame_rate)]));
      Memo1.Lines.Add(Format('  Duration: %d', [oStream.duration]));
      Memo1.Lines.Add(Format('  Time_Base: %f', [ToDouble(oStream.time_base)]));
      Memo1.Lines.Add(Format('  Duration (sec): %f', [oStream.duration * ToDouble(oStream.time_base)]));
      Memo1.Lines.Add('');

      oCodecContext := CodecContext(oStream);
      oCodec := OpenCodec(oCodecContext);
      Memo1.Lines.Add(Format('  Codec Type: %s', [CodecTypeAsString(oCodecContext)]));
      Memo1.Lines.Add(Format('  Codec Name: %s', [oCodec.Name]));
      Memo1.Lines.Add(Format('  bit rate (bps): %d', [oCodecContext.bit_rate]));
      Memo1.Lines.Add(Format('  bit rate (KBps): %f', [(oCodecContext.bit_rate/(8*1024))]));
      Memo1.Lines.Add(Format('  Frame Size: %d x %d', [oCodecContext.width, oCodecContext.height]));
      CloseCodec(oCodecContext);

      Memo1.Lines.Add(       '  -----------------');
      Memo1.Lines.Add('');
    end;
  finally
  end;
end;

I *hate* pointers.  Just thought I'd mention that :)

Also, this leaks.  I can't find why avcodec_close crashes on me, so for now, I've commented it out...

Title: Re: Component for retrieving data from video files?
Post by: CM630 on September 19, 2013, 08:18:55 am
I decided to use FFPROBE, until it occurred, that the EXE is 24 MB.
The avcodec and AVformat dlls are 5 MB, but...
I get Fatal: Can not find unit avcodec used by ffmpegWrapper.
How am to tell the app where to find the apps?
I tried regsvr32 but failed.

Code: [Select]
const
    {$ifdef win32}
    avcodec = 'avcodec-51.dll';
does not help, too.
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on September 19, 2013, 09:13:54 am
You sure ffprobe is that large? my version is only Kb in size...

No need to register the DLLs, just stick them in the same folder as your exe.

The file avcodec is in http://svn.code.sf.net/p/scandraid/code/src/trunk/external/ffmpeg/   You'll need to download them all, then add them to your project.  There was a problem with Mathematics.pas, so I just deleted it :-)

errr,

Code: [Select]
svn update http://svn.code.sf.net/p/scandraid/code/src/trunk/external/ffmpeg/ <your folder>  to download them.  I'm still new to SVN, TortoiseSVN hides the actual commands from me, so haven't learned them yet :-)
Title: Re: Component for retrieving data from video files?
Post by: metis on October 07, 2014, 03:34:28 pm
@mike.Cornflake:

Quote
For cross-platform work, I keep hoping someone will translate the ffmpeg headers for me

You mentioned Ultrastar, 3Dgrape, scandraid etc., but did You ever check FFVCL ?
www.DelphiFFmpeg.com (http://www.DelphiFFmpeg.com)

FFVCL is "only" a Delphi FFmpeg VCL Runtime-Package, but the Trial Edition
http://www.delphiffmpeg.com/downloads/ (http://www.delphiffmpeg.com/downloads/)
comes with all FFmpeg-DLLs, and here
http://www.delphiffmpeg.com/headers/ (http://www.delphiffmpeg.com/headers/)
you get all FFmpeg-Headers for Delphi/Pascal for free, with some Demos with SourceCode for Delphi.

I tried out some of them, simply using the Lazarus-ConversionTool, and up to now they all work fine
with Lazarus as well.

metis
Title: Re: Component for retrieving data from video files?
Post by: Fred vS on October 07, 2014, 03:46:36 pm
Hello.

You may use video vlc library.

fpGUI gives pascal header of vlc and a demo how to use it => /fpGUI/examples/gui/video_vlc
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on October 07, 2014, 04:11:03 pm
...did You ever check FFVCL ? www.DelphiFFmpeg.com (http://www.DelphiFFmpeg.com)

FFVCL is "only" a Delphi FFmpeg VCL Runtime-Package, but the Trial Edition
http://www.delphiffmpeg.com/downloads/ (http://www.delphiffmpeg.com/downloads/)
comes with all FFmpeg-DLLs, and here
http://www.delphiffmpeg.com/headers/ (http://www.delphiffmpeg.com/headers/)
you get all FFmpeg-Headers for Delphi/Pascal for free, with some Demos with SourceCode for Delphi.

I tried out some of them, simply using the Lazarus-ConversionTool, and up to now they all work fine
with Lazarus as well.

Whoo haa! :-)   That's fantastic news, many thanks for this.  I did check them out, but either I missed the free headers, or they weren't available when I checked.

I've sent them an email asking for permission to reference them on our wiki.

You may use video vlc library.

fpGUI gives pascal header of vlc and a demo how to use it => /fpGUI/examples/gui/video_vlc

And thanks for this as well.  I'm already using VLC for playback, via the Lazarus package, but it's the same fpc headers.  I've contributed to the Lazarus mplayer package, and I put together http://wiki.lazarus.freepascal.org/Video_Playback_Libraries (which is now recursive, thanks to a link in there pointing back here)...

I have a vision you see (one of many) :-)  One unified playback control where either the developer or enduser can decide the playback mechanism.  My potential clients are all in locked-down corporate environments, some have VLC, some are allowed the required codecs (for DirectShow), and others nothing at all - so I need flexibility.  I've already got a rough framework set up for switching between mplayer/vlc/directshow (but not that's ready for distribution).  What I didn't have is ffmpeg direct.  Oh, and I don't have the time :-)   I got exactly as far as I needed to get, then moved onto other problems.  Stay tuned, by 2020 I may just be there :-)
Title: Re: Component for retrieving data from video files?
Post by: Fred vS on October 09, 2014, 03:53:15 pm
Quote
One unified playback control where either the developer or enduser can decide the playback mechanism.

Excellent  ;) => I will be your fan.

Fred
Title: Re: Component for retrieving data from video files?
Post by: metis on October 10, 2014, 03:55:18 pm
@Mike.Cornflake

Quote
but either I missed the free headers, or they weren't available when I checked
Did You get them? I can't attach the ZIP-File for You, because it's a litte bigger than 250kb.
If You want, I split it for You.

Quote
What I didn't have is ffmpeg direct
That's the point. For this reason, I even didn't mention 'libvlc' resp. 'PasLibVlc'.

In the past I wrote some Test-Apps, e.g. for FMOD, MPlayer, VLC, just for checking out these Lib's.
They work fine, but I aim a Pascal-Solution, that is:
- OpenSource => NO FMOD (= closed)
- LicenseFree => NO FMOD (= free for personal use, but not for Redistribution)
- CrossPlatform => NO DirectShow, NO DirectSound (= Win only)
- direct => NO MPlayer (= Console, only communicating via Pipes)
- without Layers, I don't need => NO VCL
- depending on a minimum of other projects or DLLs - You never know, until they are "alive"
- Realtime, that afaik can not be really achieved with any Pascal-Code as long as
  it's running in a C-Code-Environment (Tell me, if I'm wrong).

For these reasons, I currently use for Audio mpg123, libsndfile and Portaudio, inspired by 'UOS' by Fred vS.

Unfortunately mpg123 and libsndfile do not decode that much AudioFormats. Therefore, and of course for Video,
I want something, that works with any other present and future(!) Audio/Video-Codec.

Afaik up to now only FFmpeg fulfills these criterias, and finally FFmpeg is the mother of lots of
projects, like MPlayer/MEncoder, VLC, Acinerella, FFDec - see:
https://trac.ffmpeg.org/wiki/Projects (https://trac.ffmpeg.org/wiki/Projects)


Quote
while apparently random ... Oh, and I don't have the time
Got the same problem - Therefore:

Do You know any working Pascal-Code for a Player and En-/Decoder with FFmpeg ?
Otherwise I'd have to write most of the Code on my own, as I did for the Test-Apps mentioned above.
All the Links above do not open, for being outdated or missing permission.

Thanks.

Title: Re: Component for retrieving data from video files?
Post by: Fred vS on October 10, 2014, 04:11:20 pm
Quote
Unfortunately mpg123 and libsndfile do not decode that much AudioFormats

Hello.
 
Hum, what audio-format are you missing ?

Fred.
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on October 10, 2014, 04:20:36 pm
Quote
but either I missed the free headers, or they weren't available when I checked
Did You get them? I can't attach the ZIP-File for You, because it's a litte bigger than 250kb.
If You want, I split it for You.

Thanks for the offer, but I see they're still on the website.  I have since contacted FFVCL, obtained permission to link to the headers on our wiki, and updated the wiki accordingly :-)

Quote
What I didn't have is ffmpeg direct
That's the point. For this reason, I even didn't mention 'libvlc' resp. 'PasLibVlc'.
...

We're on the same page :-)  While I don't mind using mplayer and VLC, it's not my personal preference for a way forward...  I actually enjoyed the years I spent coding with DirectShow, and look forward to moving to cross-platform base.  But having said that, due to time constraints mplayer and VLC (either library) represent tanglible solutions that I can work with right now.  And that's important too :-)

- Realtime, that afaik can not be really achieved with any Pascal-Code as long as
  it's running in a C-Code-Environment (Tell me, if I'm wrong).

Don't see why not.  It's been done before (those outdated/dead links pointed to real projects, and FFVCL have written their own player & encoder from scratch in Delphi)

Afaik up to now only FFmpeg fulfills these criterias, and finally FFmpeg is the mother of lots of projects, like MPlayer/MEncoder, VLC, Acinerella, FFDec - see:
https://trac.ffmpeg.org/wiki/Projects (https://trac.ffmpeg.org/wiki/Projects)

Preaching to the converted :-)   We're definitely on the same page, and I've long been a fan of FFmpeg.

Do You know any working Pascal-Code for a Player and En-/Decoder with FFmpeg ?

Obviously you're talking about accessing the FFmpeg library directly, not through the binaries.  See below, but I have the code for those dead links and FFVCL report examples in the header downloads.  Other than that, I know of no other examples.  We'll be starting from scratch :-)

All the Links above do not open, for being outdated or missing permission.

Yeah, I'm in a bit of conundrum about that.  I actually downloaded various projects while they were available, but as the creator has deleted the code, does that remove my right to have the copy?  I'm unclear.  However, licensing on at least one of the projects made me uncomfortable, so personally I'd rather start over scratch and port the FFmpeg examples.  <shakes head> And why am I saying that?  Those FFVCL headers you pointed me to included examples.  While sure, they might be examples of the FFVCL encoder and player, I'm optimistic that they're actually examples ported from the original FFmpeg project...

To be investigated.  Sometime :-)
Title: Re: Component for retrieving data from video files?
Post by: serbod on October 10, 2014, 05:29:11 pm
I have a vision you see (one of many) :-)  One unified playback control where either the developer or enduser can decide the playback mechanism.

I try to implement something similar by improving http://wiki.lazarus.freepascal.org/ACS (http://wiki.lazarus.freepascal.org/ACS)   It use plugable 'drivers' for audio record or playback.

Some time ago I work on some commercial project, similar to GStreamer and have some experience with ffmpeg. And want to reproduce some useful things as ACS components. But with ffmpeg is not enough to just make bindings to library functions, there huge amount of necessary routines inside ffpmeg command-line tool, that not implemented (or documented) as library functions.
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on October 10, 2014, 06:02:44 pm
I have a vision you see (one of many) :-)  One unified playback control where either the developer or enduser can decide the playback mechanism.

I try to implement something similar by improving http://wiki.lazarus.freepascal.org/ACS (http://wiki.lazarus.freepascal.org/ACS)   It use plugable 'drivers' for audio record or playback.

Small clarification, while I know that FFmpeg (and mplayer/VLC/DirectShow/whatever) can all handle audio, my primary concern is video.  There is already in place a large collection of audio libraries for Lazarus or fpc - some of which already already handle switchable playback engines.  Whereas in the video playback world, what we've got is a collection of isolated libraries, what I want is mechanism to provide choice...

But with ffmpeg is not enough to just make bindings to library functions, there huge amount of necessary routines inside ffpmeg command-line tool, that not implemented (or documented) as library functions.

Understood :-)   This goes back to my conversation with @metis.  FFmpeg will be a huge job.  VLC/mplayer represent ready made mechanisms that work and can be used right now.   My priority would be to get the framework in place for switching VLC/VLC/mplayer/Directshow (not a typo on the double VLC) as video playback engine - then work on a direct FFMpeg implementation.  Doing in that order as I'm not kidding myself it'll be easy :-)
Title: Re: Component for retrieving data from video files?
Post by: metis on October 15, 2014, 04:28:24 pm
@All: Sorry for always answering so delayed, but I got no Internet at Home.


@Fred vS

Quote
what audio-format are you missing ?
When we had our Chat about Your 'UOS', it was specially WMA; meanwhile ACC and m4a have joined that List.
There are PascalSolutions for WMA only, but I'm looking for an UNIVERSAL AudioDecoder, to feed PortAudio
with ANY AudioFormat - Would be interesting for Your UOS as well, wouldn't it ?


@serbod
Quote
But with ffmpeg is not enough to just make bindings to library functions...
I know - Have a Look at UltraStar Deluxe - they did a lot of this work.
BTW, they also started with PortAudio, but as far as I understood the Code, they couldn't make it run - at least not in the FINAL Version from Oct.2010:
http://ultrastardx.sourceforge.net/usdx-downloads/usdx/ (http://ultrastardx.sourceforge.net/usdx-downloads/usdx/)
'UOS' does Portaudio !


@Mike.Cornflake

Quote
Obviously you're talking about accessing the FFmpeg library directly, not through the binaries
Of course, otherwise I would use them.

Quote
I have the code for those dead links
Gimme dat Ding - Please, please, please...

BTW, I'm also looking for the last Version of the "New Audio Components" (= NewAC 2.6.1).
All DownloadSites, I found, finally lead to the same WebSite in Russian:
http://www.vr-!/content/new-audio-components-1799 (http://www.vr-!/content/new-audio-components-1799)
Apart from not knowing any Russian, I can't find anything like "NewAC" on that Site.
-> Does anyone know, where to get 'NewAC 2.6.1' from ?

Quote
as the creator has deleted the code
Well, I'm not a lawyer, but until the moment it was published it was and is(!) public.
Means, afaik(!): Only changes, developments, improvements, etc., that were done AFTER
closing the Code may turn to proprietary.

Quote
I'm optimistic that they're actually examples ported from the original FFmpeg project.
Should be - Otherwise, they should have named them "FFVCL-Headers".

Quote
VLC/mplayer represent ready made mechanisms that work and can be used right now.
All true, as long as we talk about only Reproducing or Transcoding Audio/Video-Streams.
MPlayer/MEncoder are Console -> In-/Output is very, very delayed, and Output is only String => useless for me.

Quote
... - then work on a direct FFMpeg implementation
I'll (try to) come from the other side - Let's see, where we'll meet.

Last Weekend, I started investigating the VideoPart from UltraStar Deluxe.
Up to now I got working (and ported from Delphi-Mode to FPC-Mode):
Open a VideoStream -> Get the StreamInfos -> Decode the Stream -> Read the Frames, and...
...then I watch my LogWindow, how these Frames are being processed (obviously) without Errors, but:

How to make an Image out of this ? OpenGL ? SDL ?
Would be nice to make it with 'LazOpenGLContext', to keep it "Lazarus only".

Any ideas ?
Title: Re: Component for retrieving data from video files?
Post by: Fred vS on October 15, 2014, 04:39:44 pm
@ metis
Quote
Would be interesting for Your UOS as well, wouldn't it ?

OF COURSE  ;)

And you are highly welcome in uos-band, your commits will be extremely appreciated.  ;)

PS: I forgot to thank you about your tip => Athread.TTreaPriority := tpTimeCritical; => it allows uos to be multi-inputs  :-X

Fred.
Title: Re: Component for retrieving data from video files?
Post by: metis on October 15, 2014, 05:37:04 pm
@Fred vS

The FFmpeg-AUDIOPart of UltraStar Deluxe comes next.
First I'd like to terminate something like a simple FFmpeg-VideoPlayer to have the basic FFmpeg-Routines.
As mentioned above, it seems to work, but the GraphicOutput is still totally missing.

Graphics I do not know so well, because up to now I was mainly interested in pure realtime AUDIO-Sound
-> Portaudio !!!  :)
Title: Re: Component for retrieving data from video files?
Post by: Mike.Cornflake on October 15, 2014, 06:59:46 pm
Quote
I have the code for those dead links
Gimme dat Ding - Please, please, please...

:-)

Sounds like you've already found Ultrastar code, but here it is again
https://dl.dropboxusercontent.com/u/59503182/Lazarus/ultrastardx-1.1-full.zip

Scandroid
https://dl.dropboxusercontent.com/u/59503182/Lazarus/scandraid-code.7z

You had no internet, I'm back in Australia - land of SLOW internet.  Wait until around 30 minutes after the date of this post before downloading.  Well, that's how long dropbox is currently telling me uploading 80Mb will take...

Quote
VLC/mplayer represent ready made mechanisms that work and can be used right now.
All true, as long as we talk about only Reproducing or Transcoding Audio/Video-Streams.
MPlayer/MEncoder are Console -> In-/Output is very, very delayed, and Output is only String => useless for me.

Umm.  You sure about the very delayed bit?  I found an initial delay, but once loaded, everything was responsive.

As for the string output.  Check out TMPlayerControl
http://wiki.freepascal.org/TMPlayerControl. 

All of the work I did on that package was decoding the string output and presenting the data in records or through events.  I was only focused on playback, not encoding...

Quote
... - then work on a direct FFMpeg implementation
I'll (try to) come from the other side - Let's see, where we'll meet.

Well, if you've started, you're going to get there a LOT faster than I :-)

Last Weekend, I started investigating the VideoPart from UltraStar Deluxe.
Up to now I got working (and ported from Delphi-Mode to FPC-Mode):
Open a VideoStream -> Get the StreamInfos -> Decode the Stream -> Read the Frames, and...
...then I watch my LogWindow, how these Frames are being processed (obviously) without Errors, but:

How to make an Image out of this ? OpenGL ? SDL ?
Would be nice to make it with 'LazOpenGLContext', to keep it "Lazarus only".

Nice work :-) 

I forgot all that code was tightly bound to SDL.  Same with the ffPlay code when I went through that..  No ideas or recommendations I'm afraid.

Have fun, glad you're working on the project :-)

Title: Re: Component for retrieving data from video files?
Post by: metis on October 18, 2014, 02:27:18 pm
@Fred vS
Quote
you are highly welcome in uos-band, your commits will be extremely appreciated.
Thank You - I was always interested in going on with 'UOS'.
See my Posts in "United OpenLib of Sound (UOS)"
http://forum.lazarus.freepascal.org/index.php/topic,17599.0.html (http://forum.lazarus.freepascal.org/index.php/topic,17599.0.html),
and my Thread "Some more UOS"
http://forum.lazarus.freepascal.org/index.php/topic,25020.0.html (http://forum.lazarus.freepascal.org/index.php/topic,25020.0.html)


@Mike.Cornflake

Quote
Sounds like you've already found Ultrastar code, but here it is again
That's exactly, what You get when downloading the "(Archive - zip)" from the UltraStar Deluxe Website, but this ZIP does NOT contain any SourceCode. ;D

For the SourceCode, download "Source Code (All Platforms)".
You'll find working(!) LazarusProjects (only in DelphiMode, but this is o.k.), in:
"ultrastardx-1.1-src\src\dists\lazarus\", and the "readme.txt" tells You, how to use them.
For FFmpeg-Stuff (and others, like Portaudio), see the Units in: "...\src\src\media".


Quote
Scandroid
That's definitivly SourceCode - Thanks, a lot !
You made me busy (and happy) all over the Winter. :D


Quote
Australia - land of SLOW internet
Come to Canary Islands, and You'll be happy with Your Internet-Connection. :P
BTW: "I got no Internet at Home", meant: I DO not have any Internet at Home.
-> My Answers may last some Days (MPlayer is indeed responding quicker).


Quote
Umm. You sure about the very delayed bit? I found an initial delay...
That's the Point, but this Delay is not only "initial", it's intrinsic (Pipes, not DLL).

To check Stuff like that, I write Test-Apps, before starting "something big".
(Hi Fred, I did the same with Your 'UOS'.) ;)

My Test-App for the MPlayer doesn't use any Packages or Components.
At that Time I derived it from the Delphi-VCL 'TMPlayer', porting it to FPC-Mode.

Apart from the Player itself with Load/Play/Pause-UnPause, Seek/SeekOnClick/SeekOnDrag, and some other
MPlayer-Stuff, like Setting A/V-Delay, Speed, etc. (here I stop, before You get bored),
it has a Form, I called 'MPlayer-Input/Output-Analyzer'.
There You can play around with the MPlayer, like:
- Send any Command with or without the Pausing/PausingKeep/PausingToggle-Prefixes
- Get-Set/Step any Property
(It's all easy, because it's all String-Input)
This Form then shows the Result of the entered String/StringCombination (-> works or ErrorString), and
the TIME, that has passed between PropertyRequest and PropertyResponse: Awful! - Yawn.

And I have another basic Problem with the MPlayer:
How to KEEP a paused Video really PAUSED, means:
Any 'SendCommand' lets a PAUSED Video PLAY again, even if using a Pausing/PausingKeep/PausingToggle-Prefix.
See my Thread: "How to keep the MPlayer really paused ?"
http://forum.lazarus.freepascal.org/index.php/topic,17327.msg95335.html#msg95335 (http://forum.lazarus.freepascal.org/index.php/topic,17327.msg95335.html#msg95335)
-> Obviously up to today there is no Solution for this.

After that, I left the MPlayer, and wrote a Test-App for VLC, derived from 'PasLibVlc'.
-> I got two MainProblems with VLC:
- Can't use ASIO for AudioOutput (same Problem with MPlayer)
- Can't open a Stream at "00:00.000" PAUSED directly, means without working around with the TimeChanged-Event.


Quote
was decoding the string output and presenting the data in records or through events
O.k., but whatever you do, the Origin of the Output is still STRING.
E.g. to decode an AudioStream for Portaudio, this is too slow - I need the In-/Outputs as DIRECT as possible.

=> The only 2 Things I like on the MPlayer are: Easy to use and better Sound than VLC. :)
Title: Re: Component for retrieving data from video files?
Post by: metis on November 21, 2014, 04:11:23 pm
After having parsed grape3D/ScanDraiD- and Ultrastar-Code:

The Base of their FFmpeg-Input resp. SDL-Audio/Video-Output can be found here:

"An ffmpeg and SDL Tutorial or How to write a VideoPlayer in less than 1000 Lines"
http://dranger.com/ffmpeg/ (http://dranger.com/ffmpeg/)
BTW: The "slightly out of date" only refers to some Details.

To make an OpenGL-VideoOutput this may help in Addition:
"Display ffmpeg frames on opengl texture"
http://stackoverflow.com/questions/23567503/display-ffmpeg-frames-on-opgel-texture (http://stackoverflow.com/questions/23567503/display-ffmpeg-frames-on-opgel-texture)
"ffmpeg video to opengl texture"
http://stackoverflow.com/questions/6495523/ffmpeg-video-to-opengl-texture (http://stackoverflow.com/questions/6495523/ffmpeg-video-to-opengl-texture)

Whilst this is all C-Code, the Pascal-Counterparts can be found in grape3D and Ultrastar.


BTW:
Maybe we should start a new Topic, like "FFmpegPlay4Laz", because we're moving more and more away
from only talking about a "Component for retrieving data from video files".

Or is this already known or done in the Lazarus-Community ?
Title: Re: Component for retrieving data from video files?
Post by: metis on November 25, 2014, 01:46:54 pm
@Mike.Cornflake
@serbod
Video-Output via Lazarus-OpenGLControl done. :)
Next are Audio/Video-Output via SDL and the Audio/Video-Synchronization. ;)

@Fred vS
Finally I'll try to get the Audio-Output done by Portaudio. ::)
Title: Re: Component for retrieving data from video files?
Post by: Fred vS on November 25, 2014, 03:52:12 pm
Quote
Finally I'll try to get the Audio-Output done by Portaudio.
=>
http://www.portaudio.com/docs/portaudio_sync_acmc2003.pdf (http://www.portaudio.com/docs/portaudio_sync_acmc2003.pdf)

Fre;D
Title: Re: Component for retrieving data from video files?
Post by: metis on November 25, 2014, 04:24:29 pm
@Fred vS

Thanks, Fred - We seem to be the only ones, who are interested in NON-EXE FFmpeg-Solutions for Lazarus.  :(

Next Time I'll start a new Thread to continue with this Subject. ;)
 
-> see "NON(!)-EXE FFPlay4Laz"
http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html (http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html)
Title: Re: Component for retrieving data from video files?
Post by: serbod on May 12, 2015, 08:42:18 pm
@metis
Quote
BTW, I'm also looking for the last Version of the "New Audio Components" (= NewAC 2.6.1).

https://code.google.com/p/newac/
Title: Re: Component for retrieving data from video files?
Post by: metis on April 22, 2016, 02:45:23 pm
@CM630
@Mike.Cornflake

Referring back to the initial Subject, and in Addition to Mike's Post from 09/17/2013,
You'll find in the Attachment (= 'FFStreamInfo.lpr.txt' )
some more Code to read out Data from MediaFiles via FFmpeg-DLLs.

Differences to Mike's Code:
- updated FFmpeg-Functions for Use with more up to Date FFmpeg-Wrappers and -DLLs
- more Data fetched, like Metadata (= Tags), Aspect, diverse AudioParams, and so on
- stand-alone, procedural ConsoleApp

This Code is Part of my FFPlay4Laz-Project, see "NON(!)-EXE FFPlay4Laz":
http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html (http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html)
(It's an Extract of what is printed to the ConsoleWindow, when <i> was pressed.)

The FFmpeg-Wrappers and -DLLs You need to try it out, are here:
http://www.delphiffmpeg.com/headers/ (http://www.delphiffmpeg.com/headers/)
http://www.delphiffmpeg.com/downloads/ (http://www.delphiffmpeg.com/downloads/)
(The present Code runs with those from 'FFVCL v5.6', but it should work with 'FFVCL v6.1' as well.)

Following FFmpeg-DLLs are required:
avcodec-55.dll, avformat-55.dll, avutil-52.dll and swresample-0.dll.

Notes:
- Reading out Chapters is done analogue.
- This Code does not only work with VideoFiles -> Try it with AudioFiles, VOB-Files (= DVD), etc.
- written with Lazarus v1.6.0 + FPC v3.0.0; tested on WinXP 32bit.

Of course, lots of more Data can be read out via FFmpeg.
For those, who are interested, see FFmpeg's 'ffprobe.c':
https://github.com/FFmpeg/FFmpeg/blob/master/ffprobe.c (https://github.com/FFmpeg/FFmpeg/blob/master/ffprobe.c);
for those, who are very interested, have a Look at the 'libavformat'-SourceFile:
https://ffmpeg.org/doxygen/3.0/dump_8c_source.html#l00480 (https://ffmpeg.org/doxygen/3.0/dump_8c_source.html#l00480).
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on September 10, 2017, 10:48:38 am
It seems that scandraid project is no more hosted on SourceForge.

Can someone please share latest sources?

Thank you in advance.
Title: Re: Component for retrieving data from video files?
Post by: molly on September 10, 2017, 05:22:52 pm
@DJMaster:
Are you referring to this (https://launchpad.net/scandraid) project ?
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on September 10, 2017, 06:13:34 pm
No, I'm talking about the one referenced here:

http://forum.lazarus.freepascal.org/index.php/topic,22038.msg129568.html#msg129568

What I'm looking for is the following file and all the other files related to ffmpeg in pascal:

http://svn.code.sf.net/p/scandraid/code/src/trunk/gui/ffmpeg.pas

Title: Re: Component for retrieving data from video files?
Post by: molly on September 10, 2017, 07:04:47 pm
Ok, in that case you are probably talking about this (https://www.openhub.net/p/grape3D) project. which btw seems to be the same (renamed/rewritten) project with same author -> dariusb.

I had no luck in locating the original files you mentioned though (wayback got me running in circles).

In case your aim is to have updated ffmpeg headers then do a search on these forums for ultrastar deluxe. But as far as i was able to see that does not have a ffmpeg.pas that you mentioned.
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on September 10, 2017, 07:22:46 pm
Ok, in that case you are probably talking about this (https://www.openhub.net/p/grape3D) project. which btw seems to be the same (renamed/rewritten) project with same author -> dariusb.

I had no luck in locating the original files you mentioned though (wayback got me running in circles).

In case your aim is to have updated ffmpeg headers then do a search on these forums for ultrastar deluxe. But as far as i was able to see that does not have a ffmpeg.pas that you mentioned.

Thank you for your efforts molly. Maybe someone else has a local copy of this repository into his harddrive.

I'm working on a fresh new ffmpeg binding for FPC (working in progress).
Title: Re: Component for retrieving data from video files?
Post by: metis on September 22, 2017, 02:45:03 pm
@DJMaster

Quote
What I'm looking for is the following file and all the other files related to ffmpeg in pascal
Those Files had been posted here in this Thread:
http://forum.lazarus.freepascal.org/index.php/topic,22038.msg160145.html#msg160145 (http://forum.lazarus.freepascal.org/index.php/topic,22038.msg160145.html#msg160145)
-> See the Link under "Scandroid".

I've extracted the Files related to FFmpeg for You - see the Attachment: 'FFmpegInScandraid.7z'.

Note:
- '..\src\trunk\external\ffmpeg' are the FFmpeg-PascalWrapper, but they are totally obsolete.
- '..\src\trunk\gui\ffmpeg.pas' renders a VideoFile, but it has no Code for Sound, SubTitles, etc., and
   the fps is left fix. Thus, this Code is totally useless, e.g. for a MediaPlayer.

Quote
I'm working on a fresh new ffmpeg binding for FPC (working in progress).
The most complete and up to date FFmpeg-PascalWrapper I know, are those from FFVCL:
http://forum.lazarus.freepascal.org/index.php/topic,22038.msg159415.html#msg159415 (http://forum.lazarus.freepascal.org/index.php/topic,22038.msg159415.html#msg159415)

Those Wrapper are written in Delphi - unfortunately only for Windows and Mac.
Though they work fine with FPC/Lazarus in Delphi-Mode, of course it would be nice to have them ported to FPC. And, of course it would be even nicer, if somebody adds the Codelines for Linux.

BTW:
What's Your Intention ? What do You need FFmpeg for ?
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on September 22, 2017, 05:07:39 pm
Thank you metis for your help, really appreciated!

My intention is to create and mantain the FFmpeg headers binding for FPC.
Conversion is still in progress and it is based upon latest version 3.3.4 currently available.
Title: Re: Component for retrieving data from video files?
Post by: metis on September 22, 2017, 06:17:04 pm
@DJMaster

Quote
My intention is to create and mantain the FFmpeg headers binding for FPC
Sounds nice, interesting (and strenuous).

Where can I download Your FFmpeg-Wrapper? I'd like to try them out with my FFmpeg-MediaPlayer:
http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html (http://forum.lazarus.freepascal.org/index.php/topic,26666.0.html)
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on September 22, 2017, 07:01:14 pm
Git repository is available here:

https://github.com/DJMaster/ffmpeg-fpc

As told before, the conversion is not complete and you cannot still use it.
Title: Re: Component for retrieving data from video files?
Post by: metis on October 02, 2017, 02:27:53 pm
@DJMaster

O.k., so I'll wait for it.  :)

Here's another, maybe not so well known, Application of FFmpeg, that may be helpful for You: OvoPlayer:
https://github.com/varianus/ovoplayer (https://github.com/varianus/ovoplayer)

In the SourceCode, the FFmpeg-Wrapper is here:
https://github.com/varianus/ovoplayer/blob/master/src/import-engines/ffmpeg.pas (https://github.com/varianus/ovoplayer/blob/master/src/import-engines/ffmpeg.pas)

Good Luck with Your Project  ;)
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on October 29, 2017, 08:10:42 am
@metis

Bindings passed compilation. Conversion is not yet completed, but You can start testing it.
Title: Re: Component for retrieving data from video files?
Post by: DJMaster on November 07, 2017, 09:40:04 pm
First test program to display FFmpeg libs versions is attached to this post.

Compiled and tested under i386-win32 and x86_64-win64.
TinyPortal © 2005-2018