Recent

Author Topic: Application producing a video of itself  (Read 762 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 7443
Application producing a video of itself
« on: August 08, 2024, 02:29:08 pm »
With a focus on Linux and an application program that knows exactly when it is doing things (driven by synchronous data collection), is there a painless way that whole-window grabs can be captured and combined into an "accepted format" video (possibly offline) for demo purposes?

I'd be inclined to keep the window to no larger than 1024x768 to ensure that the result is no larger than a plausible output device without forced scaling. Fast-moving diagnostic data can be suppressed, there's a visible 100 mSec timer but it would be entirely plausible to capture one frame a second provided that that was compatible with some form of standard output format.

Maximum video length would probably be of the order of 4 hours, naively and with no compression I'd expect that to be of the order of 32Gb. This is anticipated as being very much a "one of" for demo purposes, or at least something seldom used.

Any suggestions appreciated.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 7443
Re: Application producing a video of itself
« Reply #1 on: August 09, 2024, 09:31:56 am »
I think the "least painful" way of doing this would be

* Every second (or whatever), Bitblt the form canvas to a temporary and save that as a .png.

* Every minute, compress the .png files into an MPEG using ffmpeg, delete the originals.

* At the end of the program session, concatenate the MPEGs.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3128
Re: Application producing a video of itself
« Reply #2 on: August 09, 2024, 09:48:40 am »
Just a suggestion but I do not know if that is able to fit into your program flow.

If you are using ffmpeg then it should be possible to pipe the images to ffmpeg (or use its API) and feed pictures to the inputstream of ffmpeg to create a movie on the fly.

For a rudimentary (python) example see SO
« Last Edit: August 09, 2024, 09:50:20 am by TRon »
All software is open source (as long as you can read assembler)

MarkMLl

  • Hero Member
  • *****
  • Posts: 7443
Re: Application producing a video of itself
« Reply #3 on: August 09, 2024, 10:05:22 am »
Thanks, I'll check that but for the moment I'm inclined to try to keep as much out of the main flow as possible:

* BitBlt to temporary canvas, kick thread to save to file.

* Separate process (not capturing output) to create MPEG-2s.

* Merge MPEG-2s completely offline.

This is very much a contingency thing, but I've got frontend data capture (radio) issues that suggest that I'll miss the demo date I'd planned. So I need to focus on sorting out the frontend, and provided I can do that by the original demo date I can capture data (which will be prolific on that specific day) and then focus on processing it (and sending a video to stakeholders rather than demoing live) at my relative leisure.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 15494
  • Censorship about opinions does not belong here.
Re: Application producing a video of itself
« Reply #4 on: August 09, 2024, 10:09:43 am »
I found this snippet in C and that can easily be done in FPC too:
Code: C  [Select][+][-]
  1. #include <libavformat/avformat.h>
  2. #include <libavcodec/avcodec.h>
  3.  
  4. int main() {
  5.     av_register_all();
  6.  
  7.     AVFormatContext *pFormatCtx = avformat_alloc_context();
  8.     AVOutputFormat *pOutputFmt = av_guess_format(NULL, "output.mp4", NULL);
  9.     pFormatCtx->oformat = pOutputFmt;
  10.  
  11.     // Open the output file
  12.     if (avio_open(&pFormatCtx->pb, "output.mp4", AVIO_FLAG_WRITE) < 0) {
  13.         return -1;
  14.     }
  15.  
  16.     // Add video stream, set codec parameters, etc.
  17.     // ...
  18.  
  19.     // Write frames
  20.     // ...
  21.  
  22.     // Clean up
  23.     av_write_trailer(pFormatCtx);
  24.     avio_close(pFormatCtx->pb);
  25.     avformat_free_context(pFormatCtx);
  26.  
  27.     return 0;
  28. }
Of course it takes some more setup, but would work.
I *think* libffmpeg takes care of its own thread, but it has been some time ago since I used it.
I would try and capture the screen as the last part of an OnPaint event, not a timer, but you can combine it with a timer.
You can also simply pipe to ffmpeg, of course.
« Last Edit: August 09, 2024, 10:18:34 am by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Thaddy

  • Hero Member
  • *****
  • Posts: 15494
  • Censorship about opinions does not belong here.
Re: Application producing a video of itself
« Reply #5 on: August 09, 2024, 10:29:14 am »
Hmmm, Has been done. More or less. Can also be done in the app itself.
https://forum.lazarus.freepascal.org/index.php?topic=43411.0
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7443
Re: Application producing a video of itself
« Reply #6 on: August 09, 2024, 11:04:03 am »
Thanks for those Thaddy, I'll consider.

One thing that doesn't appear to be a viable option is concatenating PNG images into MNG (benefiting from their minimal complexity, since it appears that only a limited number of programs provide full MNG support and at least in some cases the level of support is the choice of the distro builder.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018