Author Topic: Working on a Audio+Video file format to use.  (Read 4008 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Working on a Audio+Video file format to use.
« Reply #15 on: May 10, 2020, 06:56:26 pm »
Here's a trick you might use to keep sound synced -- Only play it one second at a time, using _SNDLIMIT and _SNDSETPOS to keep it on track.

For example, let's say you record 10 seconds of video at 30FPS...

At frame 0, set_SNDLIMIT 1.0 and then_SNDSETPOS to the 0 second mark, before using _SNDPLAY.
At frame 30, _SNDSETPOS to the 1 second mark, before calling _SNDPLAY.
At Frame (Counter MOD 30 = 0),  SNDSETPOS to (Counter \ 30 + 1), before using _SNDPLAY.

Sound would always be synced per second then, which should keep things from ever getting very distorted for the video.

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Working on a Audio+Video file format to use.
« Reply #16 on: May 10, 2020, 09:18:47 pm »
Really cool job, Dav.

One suggestion I have is to also store the width and height of the original frames. That way, should you want to turn this into a library, it'd be easier to have a set of methods that do not require the user to know the size beforehand. Anything close to this pseudocode:

Code: QB64: [Select]
  1. giant& = loadDAV("GIANT.DAV")
  2.  
  3. playDAV giant&
  4.  
  5.     putDAV giant&, _MOUSEX, _MOUSEY
  6.  

These remarks come from my experiment adapting Zom-B's GIF player, which is originally a standalone like your GIANTPLAY.BAS here, to play along with InForm. The methods I devised from his player are as you can see here: https://github.com/FellippeHeitor/InForm/blob/development/InForm/extensions/gifplay.bm and I ended up having it even load multiple GIFs at once, for simultaneous - and timed - playback.

PS: If you Ctrl+F and look for "Dav" in the GitHub page I'm linking, you'll find your BIN2BAS unpack code there ;-)
« Last Edit: May 10, 2020, 09:26:44 pm by FellippeHeitor »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #17 on: May 10, 2020, 11:29:31 pm »
Thanks, Fellippe.  Yes, that's a good suggestion.   Thanks for the animated .GIF link.  Looks like a well done piece of work.  Glad BIN2BAS is of use to somebody.

Curiosity gets me experimenting, so I was playing around with _DEFLATE, and found that double deflating often resulted smaller file sizes.  Not always, but a lot of times.  For instance, I did this in the GIANTMAKE program and it shaved of almost 200k in file size in the generated GIANT.DAV animation.:

 'Compress screen image data 
frame$ = _DEFLATE$(frame$)
frame$ = _DEFLATE$(frame$)  'Do it twice!

Of course you will have to double the _INFLATE call when playing the new file back, but I found it interesting that compression can be a even more by double deflating.

EDIT: Steve --- thanks for the good suggestions...

- Dav
« Last Edit: May 10, 2020, 11:31:47 pm by Dav »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #18 on: May 11, 2020, 05:53:02 pm »

Well, I decided to go back to a previous method and format, leaving _DEFLATE behind (but I can use what I learned in other projects).

This method, although it results in a TEMP file creation during playback, I think is better than the _DEFLATE one because you can actually make videos longer than 5 seconds without taking HUGE HD space.

This QBV format (QB64 VIDEO) packs a JPG image series to the OGG insead of _DEFLATE/_MEMIMAGE screen caps.  The result is longer videos with much smaller file size than _DEFLATE could ever do.

Please test the new attached demo.  It builds a 42 second audio/video clip of me playing amazing grace on piano and trumpet. The plus side to this method is video file size is small - only 2.2MB.  The downside is that a temp file of every frame has to be created in the current directory.

Download QB64 Video format Demo - >

- Dav


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #19 on: May 11, 2020, 10:20:23 pm »
Dang that's good! Trumpet and piano at same time, I've never seen that before.

Yeah, OK that's amazing!
« Last Edit: May 11, 2020, 10:23:01 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #20 on: May 12, 2020, 01:33:00 pm »
Very nice, Dav!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #21 on: May 15, 2020, 07:40:56 pm »
I'm pleased to annouce a finished product, sort of, something worth releasing into programs I think.

QBMAKE v0.10.  Make/Play your own Audio/Video QBV files to use in your QB64 programs, with only a single small SUB to add to your code.  Can make videos with or without audio.  The Player SUB can set x/y position of video on screen, resize screen to fit the video size, zoom video size if wanted, and pause/resume playback with space bar.

The download has two BAS files: QBVMAKE.BAS and QBVPLAY.BAS, and files to make a small demo QBV file.  Run QBVMAKE first to make the BIRD.QBV video so you can see it work.  You can read in the source code how to make your own QBV videos easily.  I recommend the free VirtualDUB program to export AVI videos into a series of .JPG images so you can make your QBV files.

Btw, I tried using Steve's _SNDLIMIT/_SNDSETPOS trick to keep the FPS on track - which did work - but it results in a very small click between frames.  Not bad, but enough to not use it for now.  I'll work on eliminating the click for the next release.

Anyway, here's the finished project kit.  I'll post the BAS program here for reference, but you will need the .ZIP download to use them.

- Dav

DOWNLOAD QBVMAKE v0.10 -->   


QBVMAKE.BAS
Code: QB64: [Select]
  1. '===========
  2. 'QBVMAKE.BAS v0.10
  3. '===========
  4. 'Makes .QBV Audio/Video files for QB64.
  5. 'Uses .jpg image sequences and .ogg sound files.
  6. 'Coded by Dav, MAY/2020
  7.  
  8. 'QBVMAKE makes a .QBV audio/video file using a sequence
  9. 'of .jpg images and uses an .OGG sound file to add audio.
  10. 'This way you can make and use video files in you projects.
  11.  
  12. 'This demo builds a video called BIRD.QBV in the current
  13. 'directory.  It will then play the video.  This is only an
  14. 'example so you can see how to make your own .QBV video.
  15.  
  16. 'NOTE: YOU WILL HAVE TO ADAPT THIS CODE FOR YOUR FILES
  17.  
  18. '===========================================================
  19.  
  20. ' SET YOUR OWN QBV INFORMATION IN THIS AREA.....
  21. ' The following are my demo file settings.
  22. ' You will need to replace them with your own.
  23.  
  24. QBV$ = "bird.qbv" '<<<--- NAME OF YOUR QBV TO MAKE
  25.  
  26. 'Point to your image sequence location below and prefix
  27. 'My images are saved like, bird000.jpg.....
  28. source$ = ".\qbvmake-demo\bird" '<<<---- YOUR IMAGE DIRECTORY
  29.  
  30. OGG$ = ".\qbvmake-demo\bird.ogg" '<<<--- Name of you .OGG file
  31.  
  32. '------
  33.  
  34. 'NOW SET YOUR VIDEO INFO BELOW...
  35.  
  36. Audio = 1 '<<<--- SET TO 1 IF ADDING AUDIO, 0 IF NO AUDIO
  37. fps = 15 'My demo video has 15 frames per second
  38. frames = 165 'My video has 165 images in the sequence
  39. vidwidth = 512 'The width of my video image files
  40. vidheight = 288 'The height of my video image files
  41.  
  42. '==============================================================
  43.  
  44. 'Now here we start making the QBV file....
  45.  
  46. OPEN QBV$ FOR OUTPUT AS #1
  47.  
  48. 'If adding audio, copy it first...
  49. IF Audio = 1 THEN
  50.     OPEN OGG$ FOR BINARY AS #3
  51.     SL = LOF(3) ''Length of OGG sound file...
  52.     'save it to QBV file
  53.     A$ = INPUT$(SL, 3): PRINT #1, A$;: CLOSE #3
  54.     SL = 0 'No audio size at all
  55.  
  56. 'Now we same the jpg images to the .QBV file.
  57. 'We start at frame 0, because image sequences start at 0 usually.
  58. 'This is set to use 0000 series numbers (ie: bird0000.jpg)
  59. 'If yours are different, you will have to adjust the code.
  60.  
  61. 'Go through images...
  62. FOR t = 0 TO frames - 1
  63.  
  64.     'load a .jpg image file (a frame)
  65.     tag$ = LTRIM$(STR$(t))
  66.     IF LEN(tag$) = 3 THEN tag$ = "0" + tag$
  67.     IF LEN(tag$) = 2 THEN tag$ = "00" + tag$
  68.     IF LEN(tag$) = 1 THEN tag$ = "000" + tag$
  69.     f$ = source$ + tag$ + ".jpg"
  70.  
  71.     OPEN f$ FOR BINARY AS 7
  72.     'Grab it, CLOSE it
  73.     frame$ = INPUT$(LOF(7), 7): CLOSE 7
  74.  
  75.     'Get size of frame
  76.     framelen$ = MKL$(LEN(frame$))
  77.  
  78.     'Save it's length to file
  79.     PRINT #1, framelen$;
  80.  
  81.     'Now save the frame data to file
  82.     PRINT #1, frame$;
  83.  
  84.     CLS
  85.     PRINT "============="
  86.     PRINT "QBVMAKE v0.10"
  87.     PRINT "============="
  88.     PRINT
  89.     PRINT "Making .QBV file: "; UCASE$(QBV$)
  90.     IF Auido$ = "0" THEN OGG$ = "(no audio)"
  91.     PRINT "Using audio file: "; OGG$
  92.     PRINT "Adding frame"; t + 1; "of"; frames; "..."
  93.  
  94.  
  95. 'Now we add a Footer to the end of the .QBV file.
  96. 'This will save all the .QBV settings information.
  97.  
  98. 'Set what version of .QBV file this is.
  99. PRINT #1, "QBV0.10";
  100.  
  101. 'Set if QBV has audio of not.
  102. IF Audio = 1 THEN
  103.     PRINT #1, "1";
  104.     PRINT #1, "0";
  105.  
  106. 'Save the width of video
  107. PRINT #1, MKI$(vidwidth);
  108.  
  109. 'Save the height of video
  110. PRINT #1, MKI$(vidheight);
  111.  
  112. 'Now, save the OGG file size to the end in MKL format
  113. PRINT #1, MKL$(SL);
  114.  
  115. 'Now save number of frames in MKI format
  116. PRINT #1, MKI$(frames);
  117.  
  118. 'Now save FPS to file in MKI format
  119. PRINT #1, MKI$(fps);
  120.  
  121.  
  122. PRINT "Done!"
  123. PRINT "Press any key to playback...."
  124. A$ = INPUT$(1)
  125.  
  126. '============================================================
  127.  
  128. 'Now lets play back the video we just made....
  129.  
  130. SCREEN _NEWIMAGE(512, 288, 32) 'Open a 32 bit screen first
  131.  
  132. 'Open the demo file bird.qbv below.....
  133. 'set x/y pos, Zoom x2, resize screen to fit vid, loop option
  134. PlayQBV "bird.qbv", 0, 0, 2, 1, 1
  135.  
  136.  
  137. '=============================================================
  138.  
  139. SUB PlayQBV (file$, x, y, zoom, fit, loopit)
  140.     'file$ = QBV file to play
  141.     'x = x position on screen
  142.     'y = y position on screen
  143.     'zoom factor of video, 1 is regular size,
  144.     '     2 is double size, etc...
  145.     'fit = fit video to match your current screen resolution
  146.     'loopit = Loop video or not. 1 is loop, 0 is play once.
  147.  
  148.     FF = FREEFILE
  149.  
  150.     OPEN file$ FOR BINARY AS FF
  151.  
  152.     'Get info saved at end of file
  153.     SEEK FF, LOF(FF) - 19
  154.  
  155.     Ver$ = INPUT$(7, FF) 'Version of QBV video format
  156.     Audio$ = INPUT$(1, FF) 'Audio setting
  157.     vidwidth = CVI(INPUT$(2, FF)) 'Width of video
  158.     vidheight = CVI(INPUT$(2, FF)) 'Height of video
  159.     VidData = CVL(INPUT$(4, FF)) 'Place in file Video data starts
  160.     frames = CVI(INPUT$(2, FF)) 'How many frames in file
  161.     fps = CVI(INPUT$(2, FF)) 'How many fps
  162.  
  163.     IF Audio$ = "1" THEN
  164.         b& = _SNDOPEN(file$) 'Open sound file
  165.     END IF
  166.  
  167.     'Set screen based on vid setting...
  168.     IF fit = 1 THEN
  169.         SCREEN _NEWIMAGE(vidwidth * zoom, vidheight * zoom, 32)
  170.     END IF
  171.  
  172.     DO
  173.         SEEK FF, VidData + 1
  174.  
  175.         IF Audio$ = "1" THEN _SNDPLAY b&
  176.  
  177.         FOR vid = 1 TO frames
  178.             framelen$ = INPUT$(4, FF)
  179.  
  180.             frame$ = INPUT$(CVL(framelen$), FF)
  181.  
  182.             'make a temp jpg on disk
  183.             FFF = FREEFILE
  184.             OPEN "_tmp_qbv_frame_.jpg" FOR OUTPUT AS FFF
  185.             PRINT #FFF, frame$;
  186.             CLOSE FFF
  187.  
  188.             'load it
  189.             frm& = _LOADIMAGE("_tmp_qbv_frame_.jpg")
  190.             'erase it
  191.             KILL "_tmp_qbv_frame_.jpg"
  192.  
  193.             _PUTIMAGE (x, y)-(x + (vidwidth * zoom), x + (vidheight * zoom)), frm&
  194.             _FREEIMAGE frm&
  195.  
  196.             _LIMIT fps
  197.  
  198.             'A little keyboad control if you want.
  199.             'If you don't want, comment this out....
  200.             SELECT CASE UCASE$(INKEY$)
  201.                 CASE IS = " "
  202.                     IF Audio$ = "1" THEN _SNDPAUSE b&
  203.                     pa$ = INPUT$(1)
  204.                     IF Audio$ = "1" THEN _SNDPLAY b&
  205.                 CASE IS = CHR$(27): EXIT DO 'ESC key exits
  206.             END SELECT
  207.  
  208.         NEXT
  209.  
  210.         IF loopit <> 1 THEN EXIT DO
  211.  
  212.     LOOP
  213.  
  214.     CLOSE FF
  215.  
  216.     IF Audio$ = "1" THEN _SNDSTOP b&
  217.  
  218.  


QBVPLAY.BAS
Code: QB64: [Select]
  1. '===========
  2. 'QBVPLAY.BAS v0.10
  3. '===========
  4. 'Plays .QBV Audio/Video files.
  5. 'Coded by Dav, MAY/2020
  6.  
  7. SCREEN _NEWIMAGE(512, 288, 32)
  8.  
  9. 'Open file piano.qbv below.....
  10. 'set x/y pos, Zoom x2, resize screen to fit vid, loop it
  11. PlayQBV "bird.qbv", 0, 0, 2, 1, 1
  12.  
  13. SUB PlayQBV (file$, x, y, zoom, fit, loopit)
  14.     'file$ = QBV file to play
  15.     'x = x position on screen
  16.     'y = y position on screen
  17.     'zoom factor of video, 1 is regular size,
  18.     '     2 is double size, etc...
  19.     'fit = fit video to match your current screen resolution
  20.     'loopit = Loop video or not. 1 is loop, 0 is play once.
  21.  
  22.     FF = FREEFILE
  23.  
  24.     OPEN file$ FOR BINARY AS FF
  25.  
  26.     'Get info saved at end of file
  27.     SEEK FF, LOF(FF) - 19
  28.  
  29.     Ver$ = INPUT$(7, FF) 'Version of QBV video format
  30.     Audio$ = INPUT$(1, FF) 'Audio setting
  31.     vidwidth = CVI(INPUT$(2, FF)) 'Width of video
  32.     vidheight = CVI(INPUT$(2, FF)) 'Height of video
  33.     VidData = CVL(INPUT$(4, FF)) 'Place in file Video data starts
  34.     frames = CVI(INPUT$(2, FF)) 'How many frames in file
  35.     fps = CVI(INPUT$(2, FF)) 'How many fps
  36.  
  37.     IF Audio$ = "1" THEN
  38.         b& = _SNDOPEN(file$) 'Open sound file
  39.     END IF
  40.  
  41.     'Set screen based on vid setting...
  42.     IF fit = 1 THEN
  43.         SCREEN _NEWIMAGE(vidwidth * zoom, vidheight * zoom, 32)
  44.     END IF
  45.  
  46.     DO
  47.         SEEK FF, VidData + 1
  48.  
  49.         IF Audio$ = "1" THEN _SNDPLAY b&
  50.  
  51.         FOR vid = 1 TO frames
  52.             framelen$ = INPUT$(4, FF)
  53.  
  54.             frame$ = INPUT$(CVL(framelen$), FF)
  55.  
  56.             'make a temp jpg on disk
  57.             FFF = FREEFILE
  58.             OPEN "_tmp_qbv_frame_.jpg" FOR OUTPUT AS FFF
  59.             PRINT #FFF, frame$;
  60.             CLOSE FFF
  61.  
  62.             'load it
  63.             frm& = _LOADIMAGE("_tmp_qbv_frame_.jpg")
  64.             'erase it
  65.             KILL "_tmp_qbv_frame_.jpg"
  66.  
  67.             _PUTIMAGE (x, y)-(x + (vidwidth * zoom), x + (vidheight * zoom)), frm&
  68.             _FREEIMAGE frm&
  69.  
  70.             _LIMIT fps
  71.  
  72.             'A little keyboad control if you want.
  73.             'If you don't want, comment this out....
  74.             SELECT CASE UCASE$(INKEY$)
  75.                 CASE IS = " "
  76.                     IF Audio$ = "1" THEN _SNDPAUSE b&
  77.                     pa$ = INPUT$(1)
  78.                     IF Audio$ = "1" THEN _SNDPLAY b&
  79.                 CASE IS = CHR$(27): EXIT DO 'ESC key exits
  80.             END SELECT
  81.  
  82.         NEXT
  83.  
  84.         IF loopit <> 1 THEN EXIT DO
  85.  
  86.     LOOP
  87.  
  88.     CLOSE FF
  89.  
  90.     IF Audio$ = "1" THEN _SNDSTOP b&
  91.  
  92.  





« Last Edit: May 15, 2020, 07:52:37 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #22 on: May 15, 2020, 09:44:33 pm »
That's REALLY awesome Dav!! Great job! If you want, check out what I added to the player. People can add text within the video itself if they wish. Probably even graphics but I haven't tried that yet. It's using also the _DISPLAY command so things don't flash.  Here is my little mod. I put --------- lines between the 2 areas I added lines at (one line of code in both areas.) Tell me what you think. 

Code: QB64: [Select]
  1. '===========
  2. 'QBVPLAY.BAS v0.10
  3. '===========
  4. 'Plays .QBV Audio/Video files.
  5. 'Coded by Dav, MAY/2020
  6.  
  7. SCREEN _NEWIMAGE(512, 288, 32)
  8.  
  9. 'Open file piano.qbv below.....
  10. 'set x/y pos, Zoom x2, resize screen to fit vid, loop it
  11. PlayQBV "bird.qbv", 0, 0, 2, 1, 1
  12.  
  13. SUB PlayQBV (file$, x, y, zoom, fit, loopit)
  14.     'file$ = QBV file to play
  15.     'x = x position on screen
  16.     'y = y position on screen
  17.     'zoom factor of video, 1 is regular size,
  18.     '     2 is double size, etc...
  19.     'fit = fit video to match your current screen resolution
  20.     'loopit = Loop video or not. 1 is loop, 0 is play once.
  21.  
  22.     FF = FREEFILE
  23.  
  24.     OPEN file$ FOR BINARY AS FF
  25.  
  26.     'Get info saved at end of file
  27.     SEEK FF, LOF(FF) - 19
  28.  
  29.     Ver$ = INPUT$(7, FF) 'Version of QBV video format
  30.     Audio$ = INPUT$(1, FF) 'Audio setting
  31.     vidwidth = CVI(INPUT$(2, FF)) 'Width of video
  32.     vidheight = CVI(INPUT$(2, FF)) 'Height of video
  33.     VidData = CVL(INPUT$(4, FF)) 'Place in file Video data starts
  34.     frames = CVI(INPUT$(2, FF)) 'How many frames in file
  35.     fps = CVI(INPUT$(2, FF)) 'How many fps
  36.  
  37.     IF Audio$ = "1" THEN
  38.         b& = _SNDOPEN(file$) 'Open sound file
  39.     END IF
  40.  
  41.     'Set screen based on vid setting...
  42.     IF fit = 1 THEN
  43.         SCREEN _NEWIMAGE(vidwidth * zoom, vidheight * zoom, 32)
  44.     END IF
  45.  
  46.     DO
  47.         SEEK FF, VidData + 1
  48.  
  49.         IF Audio$ = "1" THEN _SNDPLAY b&
  50.  
  51.         FOR vid = 1 TO frames
  52.             framelen$ = INPUT$(4, FF)
  53.  
  54.             frame$ = INPUT$(CVL(framelen$), FF)
  55.  
  56.             'make a temp jpg on disk
  57.             FFF = FREEFILE
  58.             OPEN "_tmp_qbv_frame_.jpg" FOR OUTPUT AS FFF
  59.             PRINT #FFF, frame$;
  60.             CLOSE FFF
  61.  
  62.             'load it
  63.             frm& = _LOADIMAGE("_tmp_qbv_frame_.jpg")
  64.             'erase it
  65.             KILL "_tmp_qbv_frame_.jpg"
  66.             '---------------------------------------
  67.             _DISPLAY
  68.             '---------------------------------------
  69.             _PUTIMAGE (x, y)-(x + (vidwidth * zoom), x + (vidheight * zoom)), frm&
  70.             _FREEIMAGE frm&
  71.  
  72.             _LIMIT fps
  73.  
  74.             'A little keyboad control if you want.
  75.             'If you don't want, comment this out....
  76.             SELECT CASE UCASE$(INKEY$)
  77.                 CASE IS = " "
  78.                     IF Audio$ = "1" THEN _SNDPAUSE b&
  79.                     pa$ = INPUT$(1)
  80.                     IF Audio$ = "1" THEN _SNDPLAY b&
  81.                 CASE IS = CHR$(27): EXIT DO 'ESC key exits
  82.             END SELECT
  83.             '---------------------------------
  84.             LOCATE 10, 10: PRINT "Welcome"
  85.             '---------------------------------
  86.         NEXT
  87.  
  88.         IF loopit <> 1 THEN EXIT DO
  89.  
  90.     LOOP
  91.  
  92.     CLOSE FF
  93.  
  94.     IF Audio$ = "1" THEN _SNDSTOP b&
  95.  
  96.  
  97.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #23 on: May 15, 2020, 09:55:21 pm »
Yep graphics works too. :) Just put graphics commands next to where I put the PRINT command. I was thinking too that I bet it also could be used with other apps or games combining action inside the video. You could do an IF/THEN statement of a wide range of RGB colors to compare it with the bird using the POINT command in order to do things like feeding the bird with the mouse. There's limitless potential using videos inside games and apps if you think about it. :)
« Last Edit: May 16, 2020, 10:09:31 am by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #24 on: May 16, 2020, 12:37:58 am »
Thanks, Ken! I can use all the help and suggestions! I completely forgot about _DISPLAY. Thanks for trying it all out and posting your additions.

I think this kind of utility can be useful for games - for creating intros/credits, cut scenes. I've been thinking of making a little story book app, was trying to figure out how to show a nice page turn effect. Now I can render the effect in an external video program and convert it to a QBV file to use.

- Dav

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #25 on: May 16, 2020, 12:07:33 pm »
Welcome Dav. Another type of game people could make with this is something like the old 80's arcade game Dragon's Lair where the whole game is a bunch of videos. You control your guy with a sword and if you move at the wrong time, he dies. If you move at the right time, he passes the level. So let's say you want 20 levels. It would take around 3 videos per level. One video as the opening sequence, one video if he wins, the other video if he loses. So it would take 60 small videos for a 20 level game. Of course for a better game, you would have more game play in each level and more videos. The arcade game had some kind of laser disc inside it that played the videos as you played the game. It was in cartoon format but still really fun. If anyone is interested, here is the full game-play of the game:
https://www.youtube.com/watch?v=bRU0TaJq2eA
« Last Edit: May 16, 2020, 12:16:36 pm by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #26 on: May 16, 2020, 12:36:09 pm »
Wow Ken---we are still on the same wave length! Having the same dragons lair thought last night I started watching a video walk through on YouTube and then re-downloaded the game to my iPad.  I can't tell you how many quarters I spent playing that game long ago. And space ace too. Yes, a game like that is very possible in qb64 with this utility. 

- Dav

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #27 on: May 16, 2020, 02:37:49 pm »
LOL Dav, awesome. Yeah there's a Dragon's Lair for PC's too now that you can get from Steam. I haven't bought it though myself. I remember the name Space Ace, cool. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #28 on: May 16, 2020, 04:09:00 pm »
I just added something else for you. When playing the video and someone presses "T" or "t" it will show the seconds of the video on the bottom left corner of the screen. When people press "T" or "t" again, it will disappear. When the video loops back to the start, it goes back to 0. I put my code in your main LOOP in the Sub. Near DO I put 2 lines: TIMER ON and start = TIMER. Then in your SELECT CASE I put code for the user to press T or t. Then using a variable for off and on, right after the SELECT CASE, I put the TIMER code. This should be useful for people wanting to stay on track with the length of the video. At first I tried to add minutes and hours, but I couldn't figure it out with the TIMER always changing, so I just kept it with seconds. I also put the seconds in that specific corner because when the digits keep adding up, they move to the right and I didn't want people to lose sight of it on the right side, so I went with the left. Oh one more thing, I used _PRINTSTRING so it stays on the bottom with any size video people make using your (vidheight * zoom) variables. I subtracted 15 pixels from them to be seen clearly. Enjoy. :)

Code: QB64: [Select]
  1. '===========
  2. 'QBVPLAY.BAS v0.10
  3. '===========
  4. 'Plays .QBV Audio/Video files.
  5. 'Coded by Dav, MAY/2020
  6. 'Modification with video timer by pressing T added by Sierraken on May 16, 2020.
  7.  
  8. SCREEN _NEWIMAGE(512, 288, 32)
  9.  
  10. 'Open file piano.qbv below.....
  11. 'set x/y pos, Zoom x2, resize screen to fit vid, loop it
  12. PlayQBV "bird.qbv", 0, 0, 2, 1, 1
  13.  
  14. SUB PlayQBV (file$, x, y, zoom, fit, loopit)
  15.     'file$ = QBV file to play
  16.     'x = x position on screen
  17.     'y = y position on screen
  18.     'zoom factor of video, 1 is regular size,
  19.     '     2 is double size, etc...
  20.     'fit = fit video to match your current screen resolution
  21.     'loopit = Loop video or not. 1 is loop, 0 is play once.
  22.  
  23.     FF = FREEFILE
  24.  
  25.     OPEN file$ FOR BINARY AS FF
  26.  
  27.     'Get info saved at end of file
  28.     SEEK FF, LOF(FF) - 19
  29.  
  30.     Ver$ = INPUT$(7, FF) 'Version of QBV video format
  31.     Audio$ = INPUT$(1, FF) 'Audio setting
  32.     vidwidth = CVI(INPUT$(2, FF)) 'Width of video
  33.     vidheight = CVI(INPUT$(2, FF)) 'Height of video
  34.     VidData = CVL(INPUT$(4, FF)) 'Place in file Video data starts
  35.     frames = CVI(INPUT$(2, FF)) 'How many frames in file
  36.     fps = CVI(INPUT$(2, FF)) 'How many fps
  37.  
  38.     IF Audio$ = "1" THEN
  39.         b& = _SNDOPEN(file$) 'Open sound file
  40.     END IF
  41.  
  42.     'Set screen based on vid setting...
  43.     IF fit = 1 THEN
  44.         SCREEN _NEWIMAGE(vidwidth * zoom, vidheight * zoom, 32)
  45.     END IF
  46.  
  47.     DO
  48.         SEEK FF, VidData + 1
  49.  
  50.         IF Audio$ = "1" THEN _SNDPLAY b&
  51.         TIMER ON
  52.         start = TIMER
  53.  
  54.         FOR vid = 1 TO frames
  55.             framelen$ = INPUT$(4, FF)
  56.  
  57.             frame$ = INPUT$(CVL(framelen$), FF)
  58.  
  59.             'make a temp jpg on disk
  60.             FFF = FREEFILE
  61.             OPEN "_tmp_qbv_frame_.jpg" FOR OUTPUT AS FFF
  62.             PRINT #FFF, frame$;
  63.             CLOSE FFF
  64.  
  65.             'load it
  66.             frm& = _LOADIMAGE("_tmp_qbv_frame_.jpg")
  67.             'erase it
  68.             KILL "_tmp_qbv_frame_.jpg"
  69.             _DISPLAY
  70.             _PUTIMAGE (x, y)-(x + (vidwidth * zoom), x + (vidheight * zoom)), frm&
  71.             _FREEIMAGE frm&
  72.  
  73.             _LIMIT fps
  74.  
  75.             'A little keyboad control if you want.
  76.             'If you don't want, comment this out....
  77.             SELECT CASE UCASE$(INKEY$)
  78.                 CASE IS = " "
  79.                     IF Audio$ = "1" THEN _SNDPAUSE b&
  80.                     pa$ = INPUT$(1)
  81.                     IF Audio$ = "1" THEN _SNDPLAY b&
  82.                 CASE IS = CHR$(27): EXIT DO 'ESC key exits
  83.                 CASE IS = "T", "t"
  84.                     ti = ti + 1
  85.                     IF ti > 1 THEN ti = 0
  86.             END SELECT
  87.             IF ti = 1 THEN
  88.                 t = TIMER
  89.                 sec = INT(t - start)
  90.                 sec$ = STR$(sec)
  91.                 _PRINTSTRING (0, (vidheight * zoom) - 15), sec$
  92.             END IF
  93.         NEXT
  94.  
  95.         IF loopit <> 1 THEN EXIT DO
  96.  
  97.     LOOP
  98.  
  99.     CLOSE FF
  100.  
  101.     IF Audio$ = "1" THEN _SNDSTOP b&
  102.  
  103.  
  104.  
« Last Edit: May 16, 2020, 08:25:10 pm by SierraKen »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Working on a Audio+Video file format to use.
« Reply #29 on: May 16, 2020, 06:16:35 pm »
Dragon's Lair!!!!
It was one of the my preferite arcade game with its pseudo 3D graphic.
Some time ago I wrote a walktrough.

Wiki reference
https://en.wikipedia.org/wiki/Dragon%27s_Lair_(1983_video_game)

walktrough
https://www.youtube.com/watch?v=C-dg4J9_nes
« Last Edit: May 17, 2020, 01:26:35 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee