Author Topic: Screen recorder (test phase), save video to RAM  (Read 5426 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Screen recorder (test phase), save video to RAM
« on: September 10, 2018, 03:39:18 pm »
Hi. I wrote a very primitive screen scanner. To try out the program, first place it somewhere to the corner in the screen, then leave the video from Youtube on the rest of the monitor. Compile and run the program. A still image is taken. Use the mouse to select the crop to be recorded (left button, press hold, drag and drop) and confirm with the space bar. The program is minimized and begins recording the selected area into memory. To hang up and play, click the icon in the task bar to get a black window where it says how many frames are already being uploaded (to RAM). Press enter to stop recording. Press any key to play.

This is a function. The question is this: How do I capture the current screen so it does not overlap with the program window? What is the opposite function to _SCREENICON? Can the surface be scanned otherwise? This program attacked me today ... thanks for the suggestions.

Code: QB64: [Select]
  1. start& = _SCREENIMAGE
  2. PCOPY start&, 1
  3. _PUTIMAGE (0, 0), start&
  4. LOCATE 1, 1: PRINT "Select on screen area with mose for recording, then press SPACEBAR for start and ENTER for end recording."
  5.     IF _MOUSEBUTTON(1) = -1 THEN
  6.         IF mx <> 0 THEN mx = 0: ox = 0
  7.         IF ox = 0 THEN ox = _MOUSEX: oy = _MOUSEY
  8.         PCOPY 1, _DISPLAY
  9.         LINE (ox, oy)-(_MOUSEX, _MOUSEY), _RGB32(255, 255, 255), B , &H00FF00FF
  10.         _DISPLAY
  11.     END IF
  12.     IF ox AND _MOUSEBUTTON(1) = 0 AND mx = 0 THEN
  13.         mx = _MOUSEX: my = _MOUSEY
  14.         PRINT ox, oy, mx, my
  15.     END IF
  16.  
  17.     IF switch(32) AND start = 0 THEN
  18.         ' old = _DEST
  19.         _SCREENICON
  20.         start = 1
  21.         REDIM video(0) AS LONG
  22.         T# = TIMER
  23.         i$ = ""
  24.         DO WHILE i$ <> CHR$(13)
  25.             i$ = INKEY$
  26.             IF TIMER > T# + .1 THEN 'FPS limit
  27.                 video(i) = _NEWIMAGE(ABS(ox - mx), ABS(oy - my), 32)
  28.                 v& = _SCREENIMAGE
  29.                 _DELAY .01
  30.                 _PUTIMAGE (0, 0)-(_WIDTH(video(i)), _HEIGHT(video(i))), v&, video(i), (ox, oy)-(mx, my)
  31.                 i = i + 1
  32.                 REDIM _PRESERVE video(i) AS LONG
  33.                 T# = TIMER
  34.                 _FREEIMAGE v&
  35.                 _DEST InProcess&
  36.                 LOCATE 1, 1: PRINT "recording..."; i; "frames                                                                 " 'HOW do it visible, if is program minimalized?
  37.                 _DISPLAY
  38.                 _LIMIT 25
  39.             END IF
  40.         LOOP
  41.         start = 0
  42.         created = 1
  43.         _AUTODISPLAY
  44.     END IF
  45.  
  46.     _DEST 0
  47.     IF created THEN
  48.         _KEYCLEAR
  49.         BEEP
  50.         CLS
  51.         PRINT "Press key for play content:"
  52.         SLEEP
  53.         _KEYCLEAR
  54.         aaa = _DEST
  55.         playit = _NEWIMAGE(_DESKTOPWIDTH, _DESKTOPHEIGHT, 32)
  56.         SCREEN playit
  57.  
  58.         DO UNTIL _KEYDOWN(27)
  59.             FOR a = 0 TO UBOUND(video) - 1
  60.                 _PUTIMAGE (100, 100), video&(a)
  61.                 _LIMIT 10
  62.             NEXT a
  63.         LOOP
  64.         SCREEN aaa
  65.         _FREEIMAGE playit
  66.         created = 0
  67.         FOR a = 0 TO UBOUND(video) - 1
  68.             _FREEIMAGE video(a)
  69.         NEXT a
  70.         SCREEN start&
  71.     END IF
  72.  
  73.  
  74. FUNCTION switch (code)
  75.     i$ = INKEY$
  76.     IF i$ = CHR$(code) THEN
  77.         IF switch = 1 THEN switch = 0: _DELAY .1 ELSE switch = 1: _DELAY .1
  78.     END IF
  79.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Screen recorder (test phase), save video to RAM
« Reply #1 on: September 10, 2018, 03:46:35 pm »
http://qb64.org/wiki/SCREENSHOW -- _SCREENSHOW is opposite of _SCREENHIDE
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Screen recorder (test phase), save video to RAM
« Reply #2 on: September 10, 2018, 04:01:27 pm »
Thanks Steve, but this is not opposite for SCREENICON (i tryed it and program wont not maximalized)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Screen recorder (test phase), save video to RAM
« Reply #3 on: September 10, 2018, 04:06:27 pm »
Thanks Steve, but this is not opposite for SCREENICON (i tryed it and program wont not maximalized)

Maybe  $SCREENSHOW?   If not, I'm stumped
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Screen recorder (test phase), save video to RAM
« Reply #4 on: September 10, 2018, 04:21:31 pm »
No, after _SCREENICON it is minimalized for ever...

FellippeHeitor

  • Guest
Re: Screen recorder (test phase), save video to RAM
« Reply #5 on: September 10, 2018, 04:33:01 pm »
Use _SCREENHIDE instead of _SCREENICON then, so you'll be able to _SCREENSHOW it again.

If you want to do it programmatically, that's your alternative for now. If you minimize the Window, you'll have to wait for your user to want to click it again in the taskbar.

Or likely use a call to a Windows API to restore the window. Technically, a minimized window is one that's relocated to position (-32000, -32000).

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Screen recorder (test phase), save video to RAM
« Reply #6 on: September 10, 2018, 04:49:12 pm »
I'm working on it. Thanks for the help.

FellippeHeitor

  • Guest
Re: Screen recorder (test phase), save video to RAM
« Reply #7 on: September 10, 2018, 04:53:38 pm »
Also: Every time you call _SCREENIMAGE, you'll be creating a new handle and consequently allocating new memory for the new screenshot. Don't forget to _FREEIMAGE it after using it, or your program will quickly crash with an 'out of memory' error.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Screen recorder (test phase), save video to RAM
« Reply #8 on: September 10, 2018, 05:05:32 pm »
Yeah, I think to it. I need to know how to stop scanning because after the SCREENHIDE command I have to click on the monitor to restore the image of the web player and thus lose control over the program - it does not respond to the keyboard and runs in the background. That's what I found BUT I put a certain amount of time to stop him. Without it... how drive it after call SCREENHIDE?

FellippeHeitor

  • Guest
Re: Screen recorder (test phase), save video to RAM
« Reply #9 on: September 10, 2018, 05:13:43 pm »
In my experience the window remained focused and responsive even after using _SCREENHIDE:

Code: QB64: [Select]
  1. PRINT "hit a key..."
  2. a$ = INPUT$(1)
  3.  

If you run the code above and hit a key, the window will hide. Do nothing for 3 seconds and it will show again.

BUT!

If you hit a key to hide it, then hit any key while it's SLEEPing, the sleep timer will be interrupted and the window will show up again immediatelly.

Please confirm that also works on your machine.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Screen recorder (test phase), save video to RAM
« Reply #10 on: September 10, 2018, 05:30:28 pm »
Yes, it works. But i have this case. Use this code, run it, after first pressing click with mouse to other program. Then you never end it, you lose control.

Code: QB64: [Select]

FellippeHeitor

  • Guest
Re: Screen recorder (test phase), save video to RAM
« Reply #11 on: September 10, 2018, 05:49:24 pm »
Clicking another program will surely take focus from your program and it's hidden, of course you'll lose control of it.

If you must hide a program, make sure it'll come back programmatically later. Set a timer or something.

FellippeHeitor

  • Guest
Re: Screen recorder (test phase), save video to RAM
« Reply #12 on: September 10, 2018, 06:16:14 pm »
How about you just move it away then move it back on (all timer based too)?

Code: QB64: [Select]
  1. oldX = _SCREENX: oldY = _SCREENY
  2. _SCREENMOVE -32000, -32000 'hide
  3. 'do your thing
  4. 'sleep some
  5. _SCREENMOVE oldX, oldY 'show again