Author Topic: Videos  (Read 4141 times)

0 Members and 1 Guest are viewing this topic.

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Videos
« on: September 20, 2018, 04:32:04 am »
This might be a weird question. But is there anyway I can import videos in qb64? If it is not possible. Then I know how to do it with PNG sequence. But, I just wanted to ask if there is an easier way out of this...
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Videos
« Reply #1 on: September 20, 2018, 09:45:04 am »
Here a video player I made years ago using MCI commands, which means it's for Windows.  This is a VERY basic use of MCI, you can expand it by declaring types of files when opening the file, and add pause, resume, etc.  Lookup opening types of files with MCI for more info.  I'm not 100% sure I'm using MCI correctly here, but the video played for me at the time so I didn't mess with it anymore.

- Dav
 
Code: QB64: [Select]
  1. '=============
  2. 'QB64VIDEO.BAS
  3. '=============
  4. 'Plays a video file in QB64 via MCI commands (WINDOWS ONLY)
  5. 'Coded by Dav, forgot what year...
  6.  
  7. 'NOTE: This demo plays a sample video name davpiano.wmv.
  8.  
  9.     FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
  10.     ' mciSendStringA function plays media files and returns the following:
  11.     ' 0 = command sucessful
  12.     ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  13.     ' lpstrCommand is the MCI command string (and optional flags) to send.
  14.     ' lpstrReturnString is a string that holds any return information.
  15.     ' uReturnLength is the length of the lpstrReturnString string passed.
  16.     ' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
  17.     '       can be empty and uReturnLength can be set to 0.
  18.     ' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
  19.     '====================================================================
  20.     FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
  21.     ' mciGetErrorStringA returns error info if the mciSendStringA failed.
  22.     ' dwError is the return value from the mciSendString function.
  23.     ' lpstrBuffer string holds the error information returned by the function.
  24.     ' uLength is the length of the lpstrBuffer string buffer.
  25.     '====================================================================
  26.  
  27.     FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
  28.  
  29.  
  30. filename$ = "davpiano.wmv" '<========== My video file to play
  31.  
  32. IF NOT _FILEEXISTS(filename$) THEN
  33.     PRINT filename$ + " " + "not found."
  34.     END
  35.  
  36. handle& = _NEWIMAGE(320, 240, 32) '<===== The x/y size of my video
  37. SCREEN handle&
  38.  
  39. DO UNTIL _SCREENEXISTS: _LIMIT 30: LOOP 'be sure screen exists before using in this way
  40.  
  41. title$ = "QB64 Video Player - " + filename$
  42. _TITLE title$
  43.  
  44. hwnd& = FindWindow(0, title$ + CHR$(0))
  45.  
  46. ReturnString$ = SPACE$(255): ErrorString$ = SPACE$(255)
  47. a% = mciSendStringA%("open " + filename$ + " style popup", ReturnString$, LEN(ReturnString$), 0)
  48.  
  49. IF a% THEN
  50.     x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
  51.     PRINT ErrorString$
  52.     END
  53.     a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
  54.     b% = mciSendStringA%("play " + filename$, "", 0, 0)
  55.  
  56.     '=== Play video...
  57.     DO
  58.         _LIMIT 30
  59.  
  60.         'you can add pause/resume routine here if you want...
  61.  
  62.     LOOP UNTIL INKEY$ <> ""
  63.  
  64.     x% = mciSendStringA%("stop " + filename$, "", 0, 0)
  65.     x% = mciSendStringA%("close " + filename$, "", 0, 0)
  66.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Videos
« Reply #2 on: January 15, 2019, 11:06:21 pm »
Dav,

I tried it in Windows 10 and no luck. A .mov failed to initialize MCI and a .wmv gave me the specified device is not open or is not recognized my MCI. My hunch is ypu got this working in Windows 7?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Videos
« Reply #3 on: January 16, 2019, 09:04:51 am »
I could get only audio myself, with several variations of the same video, mpg, wmv, avi, ect.
I could get choppy broken video with an uncompressed AVI but that was it. and that was on Vista.
wanted to use this with my battleship game.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Videos
« Reply #4 on: January 16, 2019, 10:54:48 am »
I wonder what kind of setup Dav had? Well, this is what I thought might be the case. It would be nice to embed videos in QB64 apps.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Videos
« Reply #5 on: January 16, 2019, 11:03:22 am »
I could get only audio myself, with several variations of the same video, mpg, wmv, avi, ect.
I could get choppy broken video with an uncompressed AVI but that was it. and that was on Vista.
wanted to use this with my battleship game.

When I had those type issues with Vista, it was usually from hardware acceleration acting up.

Disable hardware acceleration. Open your computer's "Control Panel" and then click "Display." Select the "Settings" tab, click on "Advanced" and then click "Troubleshoot." Drag the hardware acceleration slider all the way to the left. This procedure can help reduce the strain on your processor, which can lead to choppy videos.

Give that a try and see if it helps.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!