Recent

Author Topic: Looking for Tutorial how to record Video with Lazarus  (Read 9243 times)

metis

  • Sr. Member
  • ****
  • Posts: 300
Looking for Tutorial how to record Video with Lazarus
« on: October 01, 2018, 05:47:59 pm »
The Tutorial in the Attachment
'Displaying video files using Free Pascal and Lazarus.pdf' mentions at the Beginning, that
"In a recent contribution, it was shown how video can be recorded with Lazarus on windows."

I cannot find that "recent contribution" anywhere in the Net.
Does anyone know, where it can be downloaded, or could post it here ?

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

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Specialize a type, not a var.

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #2 on: October 05, 2018, 03:31:23 pm »
@Thaddy
Thanks for that Link. I went through the List - lots of interesting Codes, really impressive, but
nothing about, what I'm Looking for (or I'm blind) %), or did You mean the "Break-in detection using Lazarus" ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #3 on: October 07, 2018, 09:09:59 am »
VLC is actually capable of recording, but the Lazarus wrapper has only the player part. PasLibVLC might contain more complete API, but I can't ensure at the moment.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #4 on: October 07, 2018, 11:48:31 am »
hello,
with vlc installed and TPasLibVlcPlayer component you can easily make a project to record video stream.
here is the code to read a webcam stream from a public webcam and record the stream in a mp4 file under windows with Lazarus 1.8 :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ShowWebcamClick(Sender: TObject);
  2.   var
  3.     mrl : WideString;
  4.     MyOptions : Array[0..1] of WideString;
  5.  
  6.   begin
  7.     mrl := 'http://webcam-roggwil1.bioforce.ch/axis-cgi/mjpg/video.cgi';
  8.     MyOptions[0] := ':network-caching=1000';
  9.     MyOptions[1] := ':sout=#duplicate{dst=display,dst="transcode{vcodec="h264",vb="1500",acodec="mp4a",ab="96","channels=2",samplerate="44100",vfilter="transform"}:standard{access="file",mux="mp4",dst="m:\test\OutputFile.mp4"}"';
  10.     PasLibVlcPlayer1.Play(mrl,MyOptions);
  11.   end;
  12.  
  13. procedure TForm1.StopClick(Sender: TObject);
  14. begin
  15.     PasLibVlcPlayer1.Stop();
  16. end;

Result in attachments.
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #5 on: October 22, 2018, 01:26:21 pm »
Thank You Guys, but that's actually not what I'm Looking for.

'VLC' is based on 'FFmpeg', so the same can be done with 'FFmpeg' only, without VLC-Wrapper and -Installation.

If FFmpeg-CLIs suffices, the FFmpeg-WebPages explain, how to use the CommandLine-Arguments, and
Lazarus-Apps like 'WinFF' and 'dmMediaConverter' provide some concrete CommandLine-Examples for Encoding.
For advanced Needs, there are some C- and PascalCode-Samples in the Net illustrating the Use of FFmpeg-LIBs, and
finally the FFmpeg-SourceCodes got the entire C-Code for Encoding with 'FFmpeg'.

Now, rather than going through all FFmpeg- or VLC-SourceCode-Files, I'd like to have 
a Tutorial, that explains the Theorie of Recording/Encoding and the Strategy behind the Code,
either for 'FFmpeg/VLC' or for other Libraries, that can be used with Lazarus - obviously there isn't.

@Jurassic Pork
Quote
here is the code to read a webcam stream...
How does the Code look like, if You want to record directly from built-in Devices (Microphone/Camera,
optical Devices, Sound-/GraphicCard, etc.) or from external Devices, that are connected e.g. via USB ?
What's about Latency, if You do Recording with 'VLC' ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #6 on: October 24, 2018, 06:34:37 am »
It's been over a decade since I wrote a Video Recorder.  For that I used DirectShow.

https://docs.microsoft.com/en-us/windows/desktop/DirectShow/directshow

Although all samples are in C++, I found the Microsoft documentation extremely thorough and useful.  I realise you want to record using FFMPEG (sorry, no experience), but you may find a perusal of the MS Docs informative.

At least a certain portion of the samples are available in Lazarus - DS_Pack.  Let me know if you need a link.

Incidentally - I've been meaning to tell you I'm very impressed with what you've achieved with playback using ffmpeg dlls.  Nice work, and thanks for making the code available.

Update: Found the following which uses the ffmpeg cli
https://trac.ffmpeg.org/wiki/DirectShow

Doesn't help with DLL's, but may help with testing functionality....
« Last Edit: October 24, 2018, 07:34:33 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #7 on: October 25, 2018, 05:48:46 pm »
@Mike.Cornflake

Pleased to have You back to the Discussion about Multimedia-Issues after a long Time.

Your Post showed me once again, that 'FFmpeg' is the cross-platform Swiss Knife for any Multimedia-Task.
Couldn't find anything faster and more universal up to now.

Quote
thanks for making the code available
And, it's gonna be even more available: In the Meantime I've added some more PlayerFeatures, and I've put all the Code into a Windows-DLL.
Currently, I'm writing a LCL-GUI, that demonstrates the Usage of the DLL's API. Both, the Console and the GUI, run w/o Problems and really fast from WinXP up to Win10.
There's only one really, really insistent Problem, that holds me back from Releasing it: >:(
To display the VideoImage inside of the GUI, the SDL-Window is captured by Setting its Parent to a Panel (or a WinControl),
that is anchored to the GUI's MainForm -> The VideoImage resizes with the MainForm, but:
- With WinXP, Anchoring of all or some Controls sometimes gets lost when Playing as shown in the attached Image:
  They are resized to the Panel, instead of being resized with the Form.
  This occurs even if they are anchored to the MainForm by Code (so not in the Object Inspector) 'OnFormResize' or 'OnPanelResize'
- With Win10, the MRL has to be paused when Resizing the MainForm, otherwise Resizing always hangs after some Resizes, and
  I have to restart the App. On the other Hand, the Console resizes properly.
I've tried around with Windows-Messages, but couldn't find any Solution yet.  %)
-> Any Idea, what's the Reason, and how to solve it ? 

Why do I mention this ?

Well, have a Look at "Running ffmpeg.exe without opening a console window" in Your second Link:
If you want to run your ffmpeg "from a gui" without having it popup a console window..."

Once me/You/we(?) get solved, how to put the SDL-Screen with a running(!) VideoStream into a Laz-GUI,
any FFmpeg-CLI could be integrated easily in any Laz-GUI, without rewriting lots of Code.
(I did it for 'ffplay.c', but for other Reasons, and I do not intend to do the same with other FFmpeg-Binaries.)

Quote
Doesn't help with DLL's, but may help with testing functionality...
Please, do so for 'FFPlay4Laz' and 'FFInfo4Laz' - any Kind of Contribution is welcome, here:
http://forum.lazarus.freepascal.org/index.php/topic,26666.msg286945.html#msg286945  :)
« Last Edit: October 29, 2018, 12:42:45 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #8 on: October 26, 2018, 08:35:50 am »
Yeah, sorry - changed jobs 3 years ago.  I'm now based out of an office and all my spare time to have vanished :-(

I'm only back while working on a few issues in utilities I have :-(   This topic still holds my interest though.

Meanwhile, I've just stumbled across the following sample.  Doesn't look like it holds the full story of writing a ffmpeg recorder (can't find where devices/codecs are enumerated), but it may be useful...
https://www.ffmpeg.org/doxygen/trunk/muxing_8c-example.html

Hmmm, here's a more complete example.  Ignore the bit about screenrecorder, if you look in ScreenRecorder.cpp you'll see a comment offering advice for recording from a camera.
https://github.com/abdullahfarwees/screen-recorder-ffmpeg-cpp
https://github.com/abdullahfarwees/screen-recorder-ffmpeg-cpp/blob/master/src/ScreenRecorder.cpp

Converting from C++ to Pascal ALWAYS breaks my head, and I always have to shout for help trying to understand some nuance of pointer to pointer based operations :-)  (So, yes - my entire DirectShow development was really just me annoying colleagues who understood C++ (Thanks Gavin if you're listening here :-) )  Hopefully there's little of that pointer madness happening in this code, but if you do encounter issues, yell out on here.

Oooh - this might be a solution to the missing documentation (well, the documentation that I've been unable to find): http://dranger.com/ffmpeg/
« Last Edit: October 26, 2018, 08:49:56 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #9 on: October 31, 2018, 02:55:44 pm »
@Mike.Cornflake

Quote
http://dranger.com/ffmpeg/
I already know that: Together with Ultrastar-SourceCode, it's with what I started my FFPlay4Laz-Project.
The Dranger-Tutorial explains, how to write a minimal FFmpeg-Player; nothing at all about Grabbing/Encoding, only Decoding.
My FPC-Port of the C-Files, that came with the first Dranger-Release is attached, here:
http://forum.lazarus.freepascal.org/index.php/topic,26666.msg196377.html#msg196377
This Port is kept as near as possible to the original C-Code to make it easier to compare the FCC-Code with the
corresponding C-Code in Order to alleviate "Converting from C++ to Pascal ALWAYS breaks my head".
-> Actually, I'm Looking for something similar to that Dranger-Tutorial for Recording/Encoding.

Quote
https://www.ffmpeg.org/doxygen/trunk/muxing_8c-example.html
I already know that: It's one of the Sample-C-Files, provided by 'FFmpeg'.
You can find a DelphiPascal-Port of it, and all the other FFmpeg-Sample-C-Files, here:
http://www.delphiffmpeg.com/headers/
The CodeSamples are in the "examples"-Directory, and can easily be converted, with the Lazarus-ConversionTool:
Laz-IDE: [Tools] -> [Delphi-Conversion] -> [Convert Delphi Project to Lazarus Project...].
Note: This does not convert to FPC; it's all left in Delphi-Mode.

Quote
here's a more complete example
Now, Things are getting new for me - I had a quick Look at it:
It only grabs VideoFrames (Camera/Desktop); no Audio implemented, but this should go the same Way.
The Parameters for the OutputFile are set in "/* set property of the video file */", quite similar to the CommandLine-Arguments for 'ffmpeg.exe'.
Obviously, this Guy wanted a simple Solution to create "animated ScreenShots", that can be uploaded to a Net.
Unfortunately, he does not mention, which FFmpeg-Version is used.

Still not convinced, why to start something similar to 'FFPlay4Laz' for Recording, because:
1. my Sparetime is limited, as well
2. I'm sufficiently occupied with the FFPlay4Laz-Player
3. it makes no Sense for me, because for Recording I use the 'PowerDirector' (Shareware, closed): https://www.cyberlink.com/.
    Apart from that the available Containers and Codecs are very limited (surely for Copyright-Reasons), it's a very powerful and
    fast Tool for Audio/Video-Recording and(!) -Editing. If needed, the Result can be transcoded easily.
4. it makes no Sense in General, because...

- A Player only decodes and renders, whereas a Recorder gets disproportionately complex, if You incorporate all the
  Variety of possible Options, like In-/Output(s), Container, Codecs, all/some Streams (Audio(s), Video(s), Subtitle(s)),
  Resolution, Aspect, Bitrate, Samplerate, and, and, and... (endless).
  'ffmpeg.exe' already does Recording/Encoding/Transcoding whatever You want correctly(!), very fast, and very elaborated(!).

- A Player should be responsive at several Points (Open, Seek, Pause/Resume, Close, etc.), whereas
  a Recorder only has to respond fast, when Recording is started and stopped. All the Rest, so the Processing itself, can also be delegated to a CLI, using Pipes.

ergo: A Laz-GUI for Recording with 'ffmpeg.exe' only has to...
- hide the ConsoleWindow
- enumerate the available Inputs
- pass CommandLine-Arguments
- redirect StdErr and StdOut and communicate via Pipes
- display the currently processed VideoFrame (= the MainProblem)

'WinFF' (open) and 'dmMediaConverter' (closed) already do Transcoding. The only Thing, that is missing for Lazarus is Recording, and
the only Thing, that was missing was a Tool to check quickly(!) the In- and OutStreams = 'FFInfo4Laz' and 'FFPlay4Laz'. :D
« Last Edit: October 31, 2018, 03:00:31 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Looking for Tutorial how to record Video with Lazarus
« Reply #10 on: December 03, 2018, 02:04:52 pm »
@Mike.Cornflake

Obviously, there's no Tutorial for Recording with 'FFmpeg', so
I had a deeper Look at the 'ScreenRecorder', and...ported it to FPC, see 'FFGrab4Laz':
http://forum.lazarus.freepascal.org/index.php/topic,43411.0.html
-> GoTo "ScreenRecorder2FPC".
You'll see, there's no weird C-Pointer or spooky Code, at all.

 :)
« Last Edit: December 03, 2018, 02:40:30 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018