'example how record program screen to Dav's videoformat directly
'and greetings to Dav!
'$include:'saveimage.bi'
explo = WAVtoRAW("explosion.wav")
path$
= ENVIRON$("SYSTEMROOT") + "\Fonts\arialn.ttf"s$ = "Nice work, Dav!"
ScreenScanner = 1 / 15 '15 FPS
TimePos = 0
RAWCOPY explo, VideoSoundTrack(), TimePos
RAWPLAY explo
TimePos = TimePos + RAWLEN(explo) 'rawlen return sound lenght in seconds
PRINT "Total time:";
TIMER - Control;
"15 FPS>>>>";
INT(15 * (TIMER - Control
));
" frames" PRINT "Saving video sound track..."
SAVESOUND16S VideoSoundTrack(), "ForDav.wav" 'sound track for video is done (now just convert it to OGG)
PRINT "Converting BMPs to JPGs" FOR c
= 0 TO FrameCount
- 1 PRINT "[";
INT(c
/ (FrameCount
- 1) * 100);
"%]"
DOQBV:
'here continue Dav's source:
'===========
'QBVMAKE.BAS v0.10
'===========
'Makes .QBV Audio/Video files for QB64.
'Uses .jpg image sequences and .ogg sound files.
'Coded by Dav, MAY/2020
'QBVMAKE makes a .QBV audio/video file using a sequence
'of .jpg images and uses an .OGG sound file to add audio.
'This way you can make and use video files in you projects.
'This demo builds a video called BIRD.QBV in the current
'directory. It will then play the video. This is only an
'example so you can see how to make your own .QBV video.
'NOTE: YOU WILL HAVE TO ADAPT THIS CODE FOR YOUR FILES
'===========================================================
' SET YOUR OWN QBV INFORMATION IN THIS AREA.....
' The following are my demo file settings.
' You will need to replace them with your own.
QBV$ = "ForDav.qbv" '<<<--- NAME OF YOUR QBV TO MAKE
'Point to your image sequence location below and prefix
'My images are saved like, bird000.jpg.....
source$
= _CWD$ '<<<---- YOUR IMAGE DIRECTORY
OGG$ = "ForDav.ogg" '<<<--- Name of you .OGG file
'------
'NOW SET YOUR VIDEO INFO BELOW...
Audio = 1 '<<<--- SET TO 1 IF ADDING AUDIO, 0 IF NO AUDIO
fps = 15 'My demo video has 15 frames per second
frames = FrameCount - 1
vidwidth = 801 'The width of my video image files
vidheight = 601 'The height of my video image files
'==============================================================
'Now here we start making the QBV file....
'If adding audio, copy it first...
SL
= LOF(3) ''Length of OGG sound file... 'save it to QBV file
SL = 0 'No audio size at all
'Now we same the jpg images to the .QBV file.
'We start at frame 0, because image sequences start at 0 usually.
'This is set to use 0000 series numbers (ie: bird0000.jpg)
'If yours are different, you will have to adjust the code.
'Go through images...
'load a .jpg image file (a frame)
' f$ = source$ + tag$ + ".jpg"
'Grab it, CLOSE it
'Get size of frame
'Save it's length to file
'Now save the frame data to file
IF Auido$
= "0" THEN OGG$
= "(no audio)" PRINT "Using audio file: "; OGG$
PRINT "Adding frame"; t
+ 1;
"of"; frames;
"..."
'Now we add a Footer to the end of the .QBV file.
'This will save all the .QBV settings information.
'Set what version of .QBV file this is.
'Set if QBV has audio of not.
'Save the width of video
'Save the height of video
'Now, save the OGG file size to the end in MKL format
'Now save number of frames in MKI format
'Now save FPS to file in MKI format
PRINT "Press any key to playback...."
'============================================================
'Now lets play back the video we just made....
'Open the demo file bird.qbv below.....
'set x/y pos, Zoom x2, resize screen to fit vid, loop option
PlayQBV "ForDav.qbv", 0, 0, 2, 1, 1
'=============================================================
SaveScreen:
SaveFullBMP
(STR$(FrameCount
) + ".bmp") 'JPG save is slow, therefore i use fastest saving method to BMPFrameCount = FrameCount + 1
SUB PlayQBV
(file$
, x
, y
, zoom
, fit
, loopit
) 'Dav's original SUB 'file$ = QBV file to play
'x = x position on screen
'y = y position on screen
'zoom factor of video, 1 is regular size,
' 2 is double size, etc...
'fit = fit video to match your current screen resolution
'loopit = Loop video or not. 1 is loop, 0 is play once.
'Get info saved at end of file
Ver$
= INPUT$(7, FF
) 'Version of QBV video format Audio$
= INPUT$(1, FF
) 'Audio setting vidwidth
= CVI(INPUT$(2, FF
)) 'Width of video vidheight
= CVI(INPUT$(2, FF
)) 'Height of video VidData
= CVL(INPUT$(4, FF
)) 'Place in file Video data starts frames
= CVI(INPUT$(2, FF
)) 'How many frames in file
'Set screen based on vid setting...
'make a temp jpg on disk
'load it
'erase it
KILL "_tmp_qbv_frame_.jpg"
_PUTIMAGE (x
, y
)-(x
+ (vidwidth
* zoom
), x
+ (vidheight
* zoom
)), frm&
'A little keyboad control if you want.
'If you don't want, comment this out....
RAWLEN = OTP(handle).Offset_End - OTP(handle).Offset_Start / 44100
size
AS LONG ' 4 bytes (file size) subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS INTEGER ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples lenght
AS LONG ' 4 bytes Data block size
H16.chunk = "RIFF"
H16.size
= 44 + UBOUND(arr
) * 4 'two channels, it create 16 bit, stereo wav file, one sample use 2 bytes to one channel
H16.fomat = "WAVE"
H16.sub1 = "fmt "
H16.subchunksize = 16
H16.format = 1
H16.channels = 2
H16.rate = 44100
H16.ByteRate = 44100 * 2 * 16 / 8
H16.Block = 4
H16.Bits = 16
H16.subchunk2 = "data"
LeftChannel = arr(audiodata).Left * 32768
RightChannel = arr(audiodata).Right * 32768
SoundLenghtInBytes = OTP(handle).Offset_End - OTP(handle).Offset_Start
' IF UBOUND(arr) < UBOUND(arr) + SoundLenghtInBytes + position THEN REDIM _PRESERVE arr(UBOUND(arr) + SoundLenghtInBytes + position) AS Snd
OTPS = OTP(handle).Offset_Start
FOR rc
= position
TO position
+ SoundLenghtInBytes
IF arr
(rc
).Left
THEN OutLeft
= (arr
(rc
).Left
+ OutputSound
(OTPS
).Left
) ELSE OutLeft
= OutputSound
(OTPS
).Left
IF arr
(rc
).Right
THEN OutRight
= (arr
(rc
).Right
+ OutputSound
(OTPS
).Right
) ELSE OutRight
= OutputSound
(OTPS
).Right
IF OutLeft
> .9 THEN OutLeft
= .9 IF OutLeft
< -.9 THEN OutLeft
= -.9
IF OutRight
> .9 THEN OutRight
= .9 IF OutRight
< -.9 THEN OutRight
= -.9
arr(rc).Left = OutLeft
arr(rc).Right = OutRight
' arr(rc).Left = OutputSound(OTPS).Left
' arr(rc).Right = OutputSound(OTPS).Right
OTPS = OTPS + 1
FUNCTION WAVtoRAW
(file$
) ' Function load WAV file (this just 16bit, stereo format) and load it to array as RAW. subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS STRING * 2 ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples
block = H.Block
RATE = H.rate
chan = H.channels
bits = H.Bits
SEEK #ch
, Find_data_area
(file$
)
OTP
(OTP_Size
).Offset_Start
= UBOUND(outputsound
) + 1
lef = lefi / 65536
righ = righi / 65536
IF RATE
> 44100 THEN frekvence
= RATE
ELSE frekvence
= 44100
FOR plll
= 1 TO frekvence
/ RATE
OutputSound(oss + plll).Left = lef
OutputSound(oss + plll).Right = righ
OTP
(OTP_Size
).Offset_End
= UBOUND(outputsound
) WAVtoRAW = OTP_Size
SUB RAWPLAY
(handle
) ' Play file content from RAW array (array OutputSounds) FOR Playi
= OTP
(handle
).Offset_Start
TO OTP
(handle
).Offset_End
_SNDRAW OutputSound
(Playi
).Left
, OutputSound
(Playi
).Right
Find_data_area
= INSTR(1, D$
, "data") + 8 D$ = ""
'$include:'saveimage.bm'