Recent

Author Topic: How to use Lazarus to record video from other windows?  (Read 10071 times)

BosseB

  • Sr. Member
  • ****
  • Posts: 468
How to use Lazarus to record video from other windows?
« on: November 02, 2020, 07:27:54 pm »
I need to make an application which can be used to record a video from a browser window where a video is playing. I need it to contain the audio too.
I posted such a request on the wrong subforum by mistake after searching for similar threads (and I don't know how to move it).
So now I am duplicating it here in a place where more people may find it:

I have previously used Paslibvlc to create a video editing utility but now I need to also make it possible to actually record from the screen of another window (Chrome/Firefox). I cannot directly connect to the stream showing on the screen due to complicated logins needed.
And the video itself does not have an associated URL pointing to a video file or the like either...

I don't need to use Paslibvlc if there are some other solutions.
I can even record the complete window of the browser containing the video inside since I can later edit out the surrounding stuff using my existing edit application. But I need the audio to go with it.

Are there some good solution examples using fpc/lazarus you can suggest?
I have found some old threads here but they do not show the solution to the problem at least not one I can follow.
I do not need it to be cross-platform, it is enough to stay on Windows with this.
I am using the latest Lazarus 2.0.10 and Fpc 3.2.0
--
Bo Berglund
Sweden

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to use Lazarus to record video from other windows?
« Reply #1 on: November 02, 2020, 08:31:08 pm »
Ehh. I guess, it's something easy, like recording video from YouTube. First of all, VLC can record from screen via device called "screen://". Plus, as I know, LibVLC supports custom recorders, i.e. something like OnFrame events, that can be used to capture video frames via your custom method. Second thing: not sure about Chrome, but Firefox has network monitor, that can be found at Development tools -> Network. Have you tried it? There aren't many video transfer technologies around the world. HLS and DASH are the most popular. HLS video usually looks like something like "chunklist.m3u8". DASH video is something like "video.mpd". Just copy URL and try to record it via VLC. WebM also becomes more and more popular. Not 100% sure, how to record it. Internet suggests, that it's the same DASH, but YouTube for example hides mpd manifest somehow, so it isn't accessible directly. But at the end there is no magic there. Segment list should exist somewhere. As both HLS and DASH aren't "standard" technologies. They're JS-based. I.e. segment list can be hidden, mangled or even encrypted, but at some point it should exist in open state. Otherwise browser won't know, what to download.
« Last Edit: November 02, 2020, 09:08:58 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: How to use Lazarus to record video from other windows?
« Reply #2 on: November 02, 2020, 10:50:10 pm »
Ehh. I guess, it's something easy, like recording video from YouTube.
First of all, VLC can record from screen via device called "screen://".
All right,
first of all, when working with YouTube I have tools that can do the download (all YT videos are files so that is a simpler task).
But this source is different and the YT download tools do not work due to login requirements. I have yet to make VLC play the videos natively.

So I looked at VLC now and it seems to be able to record, but only the whole desktop, which means that all the windows including VLC will be part of the recording...
I also viewed a number of Youtube videos to see how it is done and they all use the same method, which only records the video and NOT the audio...

I can handle the fact that there will be too much video recorded by using my video editor to clip away the stuff outside the video rectangle.
But the audio needs also to be part of the mp4, and this is not shown in the tutorials I have seen.  >:(
Quote

Plus, as I know, LibVLC supports custom recorders, i.e. something like OnFrame events, that can be used to capture video frames via your custom method.
Second thing: not sure about Chrome, but Firefox has network monitor, that can be found at Development tools -> Network.
Have you tried it? There aren't many video transfer technologies around the world. HLS and DASH are the most popular. HLS video usually looks like something like "chunklist.m3u8". DASH video is something like "video.mpd".
Just copy URL and try to record it via VLC. WebM also becomes more and more popular. Not 100% sure, how to record it.
Internet suggests, that it's the same DASH, but YouTube for example hides mpd manifest somehow, so it isn't accessible directly.
The idea to use the dev tools of the browser (both FireFox and Chrome has it) is a no-go since the video must be played in the original window, which is logged in to the source. No way I have tested makes it possible to find the actual video "file" URL. There seems to be none.

So in summary:
I can use VLC to record the video as a full desktop, and then use my video editor to re-encode by cropping everything outside of the video borders. It uses FFMpeg of course...

But I cannot find any way to include the audio track, which also plays during the recording phase.
All of the "with Audio" suggestions I have seen use a microphone to record your voice at the same time as the video plays, but to a separate file. But I want the original sound from the playing video to be recorded.

Therefore I was thinking about somehow making some kind of Lazarus app that could combine the video and audio channels of the playing video into a final mp4...

The hunt continues.
--
Bo Berglund
Sweden

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to use Lazarus to record video from other windows?
« Reply #3 on: November 02, 2020, 10:58:35 pm »
Hi!

DownLoadHelper is an addon for FireFox and Chrome.
Works perfekt. Downloads any kind of video that runs in the browser.

They say it is OpenSource but I can't find the source.

Look at https://www.downloadhelper.net/

Winni

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: How to use Lazarus to record video from other windows?
« Reply #4 on: November 03, 2020, 12:38:21 am »
DownLoadHelper is an addon for FireFox and Chrome.
Works perfekt. Downloads any kind of video that runs in the browser.

They say it is OpenSource but I can't find the source.

Look at https://www.downloadhelper.net/

Winni
Well, I have "Video DownloadHelper" if that is what you mean but when I try to use that it just shows a mess of individual really small items it suggests to download. Nowhere to be seen is the full video.
I think that is because the provider has cut it into a lot of small parts that are streaming across and the download helper does not know how to handle these "atoms" of the full video.
Anyway, the add-on is incapable of getting this video type.
--
Bo Berglund
Sweden

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to use Lazarus to record video from other windows?
« Reply #5 on: November 03, 2020, 04:49:34 am »
So I looked at VLC now and it seems to be able to record, but only the whole desktop, which means that all the windows including VLC will be part of the recording...
First of all, look at this. As I know, there is no better way to capture screen, than "Canvas.Handle := 0;". I.e. in the past I thought, that it can be done via more advanced library, like DirectShow, but didn't find any solution. And you can copy any region you need from desktop canvas.
I also viewed a number of Youtube videos to see how it is done and they all use the same method, which only records the video and NOT the audio...
If you talk about >720p YouTube videos, then yeah, they don't contain audio. Only 720p video contain audio. I don't know, why such design is used. HLS works with TS video, that contains both video and audio. But in DASH video and audio tracks can be separated. I.e. all video qualities may have shared audio tracks, that is more optimal. But for 720p video audio is embedded. This is their design, so it's their logic behind this design. So, 720p video should be downloaded and then it's audio should be extracted and put together with >720p video.

P.S. Currently I work with video system, that needs to broadcast arbitrary picture from server to several computers, that show this picture on TVs. And I experiment with both HLS and DASH now. Because at the end I've chosen browser, nginx server and JS for this purpose. It's very sad, but browser supports very limited amount of video formats directly. MP4, OGG and WebM. That's it. So, for RTMP/RTSP videos there is not easy solution, like "<video src="rtmp://ip/live/stream">". Only HLS or DASH can do it. And they both are JS-based. I.e. some JS script loads fragments into memory, joins them toghether and then provides blob URL to browser to show them. Very complex tech. See hls.js and dash.js for reference. So, I'm not specialist in this area. All is done for learning purposes.
« Last Edit: November 03, 2020, 05:05:26 am by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: How to use Lazarus to record video from other windows?
« Reply #6 on: November 03, 2020, 06:42:53 am »
Why reinvent the wheel?

I use internet download manager https://www.internetdownloadmanager.com

Downloads videos from all sites. It has it's small problems but would highly recommend.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: How to use Lazarus to record video from other windows?
« Reply #7 on: November 03, 2020, 07:09:35 am »
I use SimpleScreenRecorder (Linux only) https://www.maartenbaert.be/simplescreenrecorder/
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to use Lazarus to record video from other windows?
« Reply #8 on: November 03, 2020, 08:22:06 am »
And of course I've forgotten about obvious thing: ffmpeg also can capture screen.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: How to use Lazarus to record video from other windows?
« Reply #9 on: November 03, 2020, 09:05:52 am »
To download videos, I use https://youtube-mp4.download/fr/the-online-converter, or Kazam (Linux only) if I need to record "live".

[brainstorming on]
But as the solution seems to be in \ around a browser, maybe https://wiki.freepascal.org/pas2js (never used, because I already know javascript, which is enough for what I do) could be seen as a possible homogeneous Lazarus "glue" which could drive and integrate already existing mixed client and server solutions (e.g. Python with the little SVN binutils C++ applications, in RabbitCVS).
[brainstorming off]
« Last Edit: November 03, 2020, 09:15:17 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: How to use Lazarus to record video from other windows?
« Reply #10 on: November 03, 2020, 09:31:59 am »

BosseB

  • Sr. Member
  • ****
  • Posts: 468
Re: How to use Lazarus to record video from other windows?
« Reply #11 on: November 03, 2020, 12:18:48 pm »
Thank you all for your suggestions!
For sure I don't want to do this myself just for the sake of it, I really want to have a working tool to do the capturing!
The reason I am asking here is that like when I started writing my video editor I could not find anything that did what I needed and I found that there was a Lazarus package (PasLibVlc), which let me plug into the VLC capabilities for the editor.
Now I need a screen capture utility and when I did not find anything online I thought I wold try my hand at it...

But using something that exists and works is much better of course, saves my time for other projects.

So:

And of course I've forgotten about obvious thing: ffmpeg also can capture screen.
Since I have done a fair deal of ffmpeg stuff when designing my video editor and the supporting tools this seems very interesting.
I will make it a priority to try to use ffmpeg for the screen recording project if I need to write it myself.
Notice that I have to do it on Windows since there is the only place I can play the videos inside the browser.
I don't have a full linux installation with deslktop and such, only an Ubuntu server with a command line interface...

I use SimpleScreenRecorder (Linux only) https://www.maartenbaert.be/simplescreenrecorder/

This also seems interesting, but it might not work for me because of the lack of a Linux box other than servers.
It is a Linux only solution, right?
And written in C++ I see on github, so getting it into FPC is not a trivial thing...

Hi on Windows i'm using https://icecreamapps.com/Screen-Recorder/
Another project named Screen-recorder...
Seems like a full-fledged solution too. It might be exactly what I need by the looks of the images on their website.  :D
Question:
Does it record the audio that comes with the video playing in the browser and exiting out of the loudspeakers?
This is what is not working with VLC and some other solutions where audio is supposed to come from the microphone...


PS:
I see a lot of replies here and still I have not received any alert message from the forum...
Is there a forum setting I am missing to enable immediate email on replies?
DS
--
Bo Berglund
Sweden

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: How to use Lazarus to record video from other windows?
« Reply #12 on: November 03, 2020, 03:03:44 pm »
You may use ffmpeg as it has many features from recording the screen to recording the audio of your computer. A Plus point is that there are a lot of samples and answered questions that can help you. You can use ffmpeg from Lazarus with the help of TProcess.
About forum notification
- Check if the "Notify" button in the bottom of this page is on
- Check your profile > Account Settings > Modify Profile > Notifications

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: How to use Lazarus to record video from other windows?
« Reply #13 on: November 03, 2020, 11:49:45 pm »
Quote
You can use ffmpeg from Lazarus with the help of TProcess.
As shown here: http://forum.lazarus.freepascal.org/index.php/topic,43411.0.html
-> GoTo: "ScreenRecorder2FPC" (= Video only via FFmpeg-LIBs) and "RunFFmpeg" (= anything via FFmpeg-CLIs and 'TProcess').

@BosseB
Quote
Does it record the audio that comes with the video ... This is what is not working with VLC
I know. Therefore, I already gave You this Solution with 'FFmpeg':
https://forum.lazarus.freepascal.org/index.php/topic,26666.msg382658.html#msg382658
-> GoTo: "Here is a FFmpeg-CommandLine for ScreenRecording with Audio" and "record Parts of the Screen".
You can change "Microphone (...)" in the FFmpeg-CommandLine to any other supported Audio-Output of Your PC.
If You know, how to use 'FFmpeg', You won't need anything else.  :)
« Last Edit: November 04, 2020, 01:02:20 am 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: How to use Lazarus to record video from other windows?
« Reply #14 on: November 04, 2020, 01:20:46 pm »
@Mr.Madguy

Quote
VLC can record from screen via device called "screen://"
But only without Audio - At least, I didn't succeed to record the Screen with Audio via 'VLC', neither.
Then I tried several ScreenRecorder from the Web, but couldn't find anything, that I really liked.
That's why I wrote 'RunFFmpeg', that does anything You want to do with 'FFmpeg', among others
ScreenRecording with Audio, the entire Desktop, an App's Window or Parts of the Screen, as You like it.
You only have to modify the FFmpeg-CommandLine, as decribed in my Links above - easy !

Hint: Currently, there are two Limitations with 'RunFFmpeg':
1. After some Hours(!) of Processing, the ProcessOutput freezes; probably an Overflow
    of the Lines in the ProcessOutput's 'TMemo'.
2. Recordings to AVI-Files can be finished, simply by Terminating the FFmpeg-Process (as it is done now), but
    mp4-Files, must be finished by Sending a <q> (= quit) to the FFmpeg-ProcessInput, otherwise
    You get a VideoFile, that cannot be played.
Shouldn't be a big Problem to implement this in the current Code.

Quote
If you talk about >720p YouTube videos, then yeah, they don't contain audio.
How do You know this? Try the '4k Video Downloader': https://www.4kdownload.com/.
It downloads - with very, very few Exceptions - any YT-Video with Audio and selectable VideoQuality.
Some of the YT-Videos come optionally with a VideoCodec, that even FFmpeg's Player 'ffplay.exe' can't decode (yet).
In this Case, You will hear only the AudioStream w/o Video, when Playing it.

Solution:
1. Select an other VideoCodec, when Downloading
2. Wait, until 'FFmpeg' (and thus my FFPlay4Laz-Player :) ) implements that Codec, too.
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018