Author Topic: Capture frames from video  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Capture frames from video
« on: June 03, 2021, 04:34:34 am »
Can MEM access video ram when a you tube video is playing?
maybe something like the DOS TSR?

« Last Edit: June 03, 2021, 04:40:52 am by NOVARSEG »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Capture frames from video
« Reply #1 on: June 03, 2021, 10:18:57 am »
Not sure, but that sounds absolutely dangerous and would most likely require a great deal of knowledge on codecs. You could use my WinAPI code for recording webcams through QB64 and then use a virtual webcam to pipe in the desktop video feed.
Shuwatch!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Capture frames from video
« Reply #2 on: June 03, 2021, 12:46:37 pm »
You could always use  _SCREENIMAGE with the  SAVEIMAGE code to "grab" frames from the video while it is playing.
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Capture frames from video
« Reply #3 on: June 03, 2021, 04:53:45 pm »
https://www.qb64.org/forum/index.php?topic=561.msg4127#msg4127
 try it, first run video on youtube, then run this program.

For start recording press spacebar. After then is program minimalized (but is recording frames from screen on selected area to Ram in background)
For end recording click to tray to program icon, this maxcimalize this program, then press enter for end recording frames from screen.
Press any key for playing recorded content.

For saving frames from RAM to HDD use SaveImage by Steve (not implanted in this program).
« Last Edit: June 03, 2021, 05:10:28 pm by Petr »

Offline OldsCool

  • Newbie
  • Posts: 19
  • 3D Spherical programming is as easy as pi
    • View Profile
Re: Capture frames from video
« Reply #4 on: June 04, 2021, 11:55:18 am »
just as Cobalt  suggested. I created a program using SCREENIMAGE that allows you to draw a box around the video area on your desktop you want to capture then saves each frame to an array to be played back or saved as a bitmap. at startup you specify the frame rate to capture so when you play it back it is rendered the original speed. I created it because I was looking for a way to save video clips that can be used for playback in my programs, works great!... Actually, I used it to create the 'Skull.png' image sheet that I'm currently using with my '3D skull from 2D images' program, I captured it from a GIF of the rotating skull, I will find and post it just for fun. of course, the skull was not for video playback but to analyze each frame for 3D. 

I ALSO created a version that will freak you out that is too hard to explain here, better to show you, I'll make a video demo in the next few days and post it as well

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Capture frames from video
« Reply #5 on: June 04, 2021, 12:04:49 pm »
I made. .DLL in purebasic once to allows a QB64 window to open/display a webpage. Like a browser window. Haven’t tried this, but maybe it would be possible to do a _COPYIMAGE(_DISPLAY) while watching a YouTube video with such a QB64 window.  If your interested I can dig up that .DLL (it was on my older laptop that died but I backed up the data somewhere). It was 32-bit though.

- Dav

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Capture frames from video
« Reply #6 on: June 04, 2021, 09:50:41 pm »
OldsCool

Quote
then saves each frame to an array to be played back or saved as a bitmap.

as the video is playing, how does the code know when to read video ram?

My experience with video stuff is limited.  I wrote an AVI file reader for Canon power shot camera. The (Canon) AVI format is fairly complex - it has variable compression. Every video frame can be a different length.  There is one sound frame per 30 video frames. The sound frame is always the same length.
« Last Edit: June 04, 2021, 09:58:32 pm by NOVARSEG »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Capture frames from video
« Reply #7 on: June 05, 2021, 09:44:43 am »
_SCREENIMAGE essentially returns the headless BMP format. So the frame size in RAM is determined as the selection width multiplied by the selection height multiplied by 4 bytes because you store 32-bit frames. Only pointers to individual frames that are created using the _COPYIMAGE or _NEWIMAGE command (depending on how the program is built) are stored in the field.

You can also determine the size of the block of memory that the image takes up as follows:

Frame = _SCREENIMAGE
Dim M as _Mem
M = _MemImage (Frame)
Print M.Size

For accurate playback synchronization, if you have 25 frames per second recorded, use _Limit 25 between each frame (Actually, you will use the same when recording images to RAM)

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Capture frames from video
« Reply #8 on: June 05, 2021, 09:31:59 pm »
I don't know enough about this subject to give any good reply.  If a video is playing on a certain window and QB64 on another window then how does the QB64 program  run at the same time as the video player. Does that involve multithreading?




Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Capture frames from video
« Reply #9 on: June 05, 2021, 11:46:17 pm »
I don't know enough about this subject to give any good reply.  If a video is playing on a certain window and QB64 on another window then how does the QB64 program  run at the same time as the video player. Does that involve multithreading?

What video player are you using by the way?

So you don't listen to music or anything while your working on code in qb64?

I could walk you through it, but it sounds like @OldsCool has a program that might be already created and work for you. might ask him for a link.
« Last Edit: June 05, 2021, 11:49:33 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Capture frames from video
« Reply #10 on: June 06, 2021, 04:05:51 am »
How does it work? QB64 simply captures the current screen, no matter what is running on it. Therefore (in the link I added last time above) I minimize the screen capture program so that its window does not overlap what is happening on the screen being recorded. Therefore, it records everything even when switching to another program, it captures exactly what is currently on the screen. If you only want to scan the output of a specific program, whether it is currently visible or not, you would probably have to use some Windows functions using dynamic libraries, I haven't tried this yet and I don't know if it's possible at all.

Keep in mind that the program I wrote a few years ago doesn't worry about synchronization, it's just the roughest resource for testing the principle of operation.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Capture frames from video
« Reply #11 on: June 07, 2021, 01:38:18 am »
What would happen if 2 QB64 programs were to access  video ram at the same time?

Say, a QB64  program writes a pixel and then the other QB64 program reads that same pixel.  Can this be kept in sync?

The test

the first program writes a green pixel and then a red pixel at the same location.  The second program reads the same pixel location after every write of the first program. The second program should read alternating red -green pixels. If it reads the same color twice (or other colors) in a row you know it went out of sync.




« Last Edit: June 07, 2021, 04:00:01 am by NOVARSEG »