Best video file format?

Windows specific questions.
grindstone
Posts: 755
Joined: May 05, 2015 5:35
Location: Germany

Re: Best video file format?

Postby grindstone » Jul 28, 2015 14:22

Hello!

This is a translation of a posting I made in the german FB forum some time ago.
https://forum.qbasic.at/viewtopic.php?p=105267&highlight=#105267
https://forum.qbasic.at/viewtopic.php?p=105270&highlight=#105270

It's about including two new statements by a dll for using the parallel port under WinXP:

Code: Select all

'include parallel port drivers for Windows XP
Dim parallelport As Any Ptr
Dim Shared OUT32 As Sub (Address As integer, Wert As Integer)
Dim Shared INP32 As Function (Address As Integer ) As Integer

parallelport = DylibLoad("inpout32.dll") 'load dll

If parallelport Then 'declare new statements
   Out32 = DylibSymbol(parallelport, "Out32") 'write byte
   Inp32 = DylibSymbol(parallelport, "Inp32") 'read byte
Else 'error
   Print "INPOUT32.dll not found."
  Sleep
EndIf

It is quite simple: A dll is a collection of procedures (functions and/or subs) which can be reloaded by a programm at its runtime.

To use such a procedure, it has to be declared like any other procedure. At this the compiler has to be informed, that the later call will not be done by a "normal" procedure name, but by a (yet to determine) pointer. This is done by using "Dim" instead of "Declare":

Code: Select all

Dim Shared Out As Sub (Address As integer, Value As Integer)
The mentioned procedure name ("Out") is the name the procedure will have INSIDE THE CALLING PROGRAMM.
Next up the dll - file will be loaded into the memory:

Code: Select all

parallelport = DylibLoad("inpout32.dll")
The return value (that means the value of the variable "parallelport") is a handle to the just loaded dll, a kind of identification number the dll can be approached with.

Now the declared procedure has to be assigned to its pointer:

Code: Select all

Out = DylibSymbol(parallelport, "Out32")
The first parameter is the handle of the dll, the second parameter ("Out32") is the name of the procedure INSIDE THE DLL.

Before calling a procedure by a pointer you should ALWAYS make sure that the pointer is <> 0, for a procedure call with a pointer to address 0 will inevitably cause a crash.

I hope this wil help you a little bit to understand how dlls are handled in FB.

Regards
grindstone
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: How to load ATL in order to embed window movie player?

Postby datwill310 » Jul 28, 2015 14:59

Tourist Trap wrote:By the way, you may edit your title in order to get more answers. You're too much general in my opinion. Maybe you should better try something like "How to load ATL in order to embed window movie player" ?

How do I change a topic's title?
EDIT: Is this correct?
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: How to load ATL in order to embed window movie player?

Postby Tourist Trap » Jul 28, 2015 17:56

datwill310 wrote:Is this correct?

You did it thanks. The more you ask precisely the best the chance to get the answer. There are other topics about activeX by there but none seems to make it the short way, and I haven't found anything about media player for now on the fourth first page. I can remember however that there is an affair of redirecting the output of a player, I just cant remember where I'd read about this. The idea is to play the video silently (background) but for the sound which plays loudly, and trap the video output. In this case it's like a streaming. If it was possible to ask a player to do that, so things would go such :
    launch player in background
    catch its video output
    show it as a stream in your window
    at any time communicate with player in background
Do you think this possible?
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Best video file format?

Postby datwill310 » Jul 28, 2015 18:28

I think so. So what you're saying is to get the video frame, and display it in a graphics window?
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Best video file format?

Postby datwill310 » Jul 28, 2015 18:31

I appreciate the work you have done for me, but now I'm wondering that there has to be a simpler way. I figure that you'd rather do other things then help me in this way?
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Best video file format?

Postby Tourist Trap » Jul 28, 2015 18:34

datwill310 wrote:I think so. So what you're saying is to get the video frame, and display it in a graphics window?

This below already works as a redirection example :

Code: Select all

''https://wiki.videolan.org/Video_output/#x11

Exec ("C:\vlc\vlc.exe", "myvideo.avi -V caca")   ''change your path accordingly
                           ''put myvideo.avi in program path

? "END"
Sleep 
Last edited by Tourist Trap on Jul 28, 2015 18:35, edited 1 time in total.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

How to load ATL in order to embed window movie player?

Postby datwill310 » Jul 28, 2015 18:35

Sorry, I forgot to update my topic name on these posts. I'm using my iPod right now so it's a bit more difficult to use this forum I.e. it's laggy
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Best video file format?

Postby datwill310 » Jul 28, 2015 18:38

Is this just using an external player? It doesn't matter if it is; it's probably a better thing to do. Thank you for all of your help!
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: How to load ATL in order to embed window movie player?

Postby Tourist Trap » Jul 28, 2015 18:50

It uses an external player but VLC is powerful at least under linux, has a permissive licence, and once you have hidden its interface, you have the same result as if using the dll. The above example shows an output successful redirection. Ok under windows maybe the best would be to keep on the wmv wheels..

I've sligthly improved the code adapted from the lb tutorial. I would like to know more about the type of window liberty basic is creating when a program is launched. Is it console, or directly a windows window ?

Code: Select all

Dim As Any Ptr atllib  = DylibLoad ("ATL.dll")
Dim AtlAxWinInit As Function() As Any Ptr
     AtlAxWinInit = DyLibSymbol( atllib, "AtlAxWinInit" )
? "Calling for AtlAxWinInit..."
Dim As Any Ptr Ret = AtlAxWinInit()
? "Return = "; Ret

#Include "windows.bi"
#include "win/dshow.bi"

Dim As HWND _hWnd, _hWnd1, _hWnd2
Dim As HINSTANCE _hInst

_hWnd = GetConsoleWindow()
? "Calling for GetConsoleWindow..."
? "_hWnd = "; _hWnd

Dim As Integer nIndex = -6 '_GWL_HINSTANCE
? "Calling for GetWindowLongA..."
_hInst = GetWindowLongA( _hWnd, nIndex )
? "_hInst = "; _hInst
 
Dim As ULong dwExStyle = 131072  'WS_EX_STATICEDGE = 0x00020000L
Dim As  LPCTSTR     lpClassName
Dim As  LPCTSTR     lpWindowName
Dim As ULong dwStyle = 1073741824 'WS_CHILD = 0x40000000L
Dim As Integer x, y , nWidth , nHeight
Dim As HWND hWndParent = _hWnd
Dim As HMENU _hMenu  = 100
Dim As HINSTANCE _hInstance = _hInst
Dim As LPVOID lpParam
? "Calling for CreateWindowEx..."
_hWnd1 = CreateWindowEx( dwExStyle,"AtlAxWin","http://www.freebasic.net/", _
                         dwStyle, 100, 100, 100, 100, _
                         hWndParent, _hMenu, _hInstance, lpParam)
? "_hWnd1 = ";_hWnd1
? "lpParam = "; lpParam

Dim As Any Ptr hATL
? "Calling for CreateWindowExA..."
_hWnd2 = CreateWindowExA(131072, "AtlAxWin", "http://www.freebasic.net/", _
                         1073741824, 100, 100, 100, 100, _
                         _hWnd , _hMenu, _hInst, hATL )
? "hWnd2 = "; _hWnd2
? "hATL = "; hATL

Sleep


Take also a look to directshow : https://msdn.microsoft.com/en-us/librar ... 85%29.aspx. You will need to download windows SDK however if you want to access the examples, it's a huge download that I cant do for reason of space disk. But if you project using windows dll, you will often need the stuff provided there, also you'll need MSDN (the documentation) - also huge download but rather useful.

Code: Select all

'The Microsoft DirectShow application programming interface (API) is a media-streaming architecture for Microsoft 'Windows. Using DirectShow, your applications can perform high-quality video and audio playback or capture.
#include "win/dshow.bi"


At last wouldn't you be happy enough with animated gif? This is possible to find some tool to convert a video sequence into such image series. You could read them with BLOAD and some cache or stream buffer mechanism (say load 100 images in memory while 100 are played and destroyed ..etc..). Which means you make your own player - uncompressed images player. Up to you man to choose this rather peaceful highway.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: How to load ATL in order to embed window movie player?

Postby datwill310 » Jul 29, 2015 10:35

Tourist Trap wrote:type of window liberty basic is creating when a program is launched. Is it console, or directly a windows window ?

You may block it before runtime, but LB produces a console-like window: it is used for input and output (and in my opinion could do with a few major improvements). One of LB's main positives is that it handles with GUI very easily. You could create one GUI window: fully functional with resizing borders, the three _, □, and X buttons, and title and icon (though there is not any option in this example of which icon to use), here:

[code=LB file=window.bas]nomainwin 'this blocks the console-like window from poping up - it's not necessary but advisory
'you may setup window size and position with special variables before opening the window:
UpperLeftX = 5
UpperLeftY = 10
WindowWidth = 500
WindowHeight = 400
open "Window Caption" for window as #windowhandle 'open the window - in LB you do not have to predefine variables
#windowhandle, "trapclose [quit]" 'send the trapclose command to the window just opened *see the comment on [quit]*
wait 'wait for user input

[quit] 'this is the branch setup for when a user clicks the X button
close #windowhandle 'actually close the window
end 'end the programme[/code]

It might be a bit rusty around the edges hence I haven't programmed in LB since May this year, but that's a basic window programme. This code generates a window with LB's main symbol as the icon, and a caption of Window Caption, with a pixel offset of 5, 10 from the desktop UL corner, and with a width of 500 pixels and a height of 400 pixels.

Tourist Trap wrote:At last wouldn't you be happy enough with animated gif?


I don't really want a .gif. I could compromise but only if desperate (I dunno; play music at the same time as the .gif and hope that it plays in sync?). So if I was to use VLC, I would require a Windows Media Video file? I perhaps need to find a suitable .WMV maker (frame by frame using files from my disc), stream that into VLC, and hope for the best!
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: How to load ATL in order to embed window movie player?

Postby Tourist Trap » Jul 29, 2015 15:04

datwill310 wrote:You may block it before runtime, but LB produces a console-like window: it is used for input and output (and in my opinion could do with a few major improvements). One of LB's main positives is that it handles with GUI very easily. You could create one GUI window: fully functional with resizing borders, the three _, □, and X buttons, and title and icon (though there is not any option in this example of which icon to use), here...

Thanks. So if the GUI option is activated a handle to a window is created. In the adaptation of the tutorial I'm in console mode, so a handle to console is provided, but maybe it wont be able to embed any graphical control. I don't really know how to launch a gui window, I always compile with -console option. This to say that the tutorial may work if a correct window is provided at the very start.
datwill310 wrote:I don't really want a .gif. I could compromise but only if desperate (I dunno; play music at the same time as the .gif and hope that it plays in sync?). So if I was to use VLC, I would require a Windows Media Video file? I perhaps need to find a suitable .WMV maker (frame by frame using files from my disc), stream that into VLC, and hope for the best!

You are right that "animated gif" would fit only if you have a little video incrusted in your game and provided you do the sound synchronizing.

Then for VLC, I'm disapointed since not all the dll are implemented for windows. So I was unable to test many things. Maybe the dll provided are sufficent, but I'm not able to translate the c++ include files (.h). To make it clear I meant using VLC at command line, asking it to something like "vlc -hide -redirectVideoTo mybuffer". If it is about include the libs it is far more difficult.

Media player, outside from the microsoft dot net framework, or C++ doesnt provide any easy access. But directshow seems fit your needs. The only issue is that to use it you'll need the windows sdk. This SDK contains everything to program under windows, not only the features currently in use in your system. But I cant download it those times. So if you don't have any restriction, I think this would be the best way here. Directshow is made to play video, as DirectX is made to draw 3D etc..

I've noticed that FB has a " #include "win/dshow.bi" " so some headers have been translated. Maybe you should open another thread to ask what exactly is possible to do, and how, to manage directshow via freebasic. I mean what functions are possible to use in freebasic to do directshow if you add this include to your code. For example " GetConsoleWindow() " is a function provided via "windows.bi" include file and it translate "windows.h" from the windows API. Is there a " DirectshowDrawAvi() " feature from "dshow.bi" ?
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: How to load ATL in order to embed window movie player?

Postby datwill310 » Jul 29, 2015 16:38

Tourist Trap wrote:Media player, outside from the microsoft dot net framework, or C++ doesnt provide any easy access. But directshow seems fit your needs. The only issue is that to use it you'll need the windows sdk. This SDK contains everything to program under windows, not only the features currently in use in your system. But I cant download it those times. So if you don't have any restriction, I think this would be the best way here. Directshow is made to play video, as DirectX is made to draw 3D etc..

I'm hopefully gonna release this game online. So if the player has to download extra data (and it seems a lot judging from what you said before) so they could view the clips, seems an inconvenient snag!
How do you know if you have got the SDK already? Will it be in the list of programmes in Uninstall or is it not really an application?
Looks like I'm going into have to revert to using an external player - it might seem somewhat, unconvincing, but it will do it properly. Windows Media Player will be on every modern Windows system, right?
Unless only I had to download the SDK - then that will be an option.
But right now, I'm starting to worry...
If ONLY I had kept that code!
Tourist Trap wrote:This to say that the tutorial may work if a correct window is provided at the very start.

I would have to hide it, then show it, then hide it again: that would be the general idea it seems. It would work.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: How to load ATL in order to embed window movie player?

Postby Tourist Trap » Jul 29, 2015 17:00

datwill310 wrote:I'm hopefully gonna release this game online. So if the player has to download extra data (and it seems a lot judging from what you said before) so they could view the clips, seems an inconvenient snag!

Will your game be run inside a web page?
There is not extra data, but if the video is in server side, loading time is to be expected.

datwill310 wrote:How do you know if you have got the SDK already? Will it be in the list of programmes in Uninstall or is it not really an application?

The SDK (software developpment kit) is only for the developper. The user doesn't need it. It contains tools that helps you access some feature that otherwise would be an horrible pain to figure out how to handle. If you want to use windows dll that we all have installed in our systems, then from a programer point of view the windows sdk would be useful. Generally it wont imply any extra download for the user.

datwill310 wrote:Looks like I'm going into have to revert to using an external player - it might seem somewhat, unconvincing, but it will do it properly. Windows Media Player will be on every modern Windows system, right?

WMP is always included in windows since XP, even maybe since windows 98. But a flashplayer is also a possibility. Hower at developper side flash is not a free application...

datwill310 wrote:If ONLY I had kept that code

You may be able to find it in the lb online documentation? Since I've not enough keywords related to this, I can't search the web efficently. But you could probably.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: How to load ATL in order to embed window movie player?

Postby datwill310 » Jul 29, 2015 17:52

Tourist Trap wrote:Will your game be run inside a web page?
There is not extra data, but if the video is in server side, loading time is to be expected.

It will be a download on sourceforge hopefully - Idk how to imbed apps in web pages, and I shouldn't ever need to.

Tourist Trap wrote:The SDK (software developpment kit) is only for the developper. The user doesn't need it. It contains tools that helps you access some feature that otherwise would be an horrible pain to figure out how to handle. If you want to use windows dll that we all have installed in our systems, then from a programer point of view the windows sdk would be useful. Generally it wont imply any extra download for the user..

That's great! That brings things into a whole new light!

Tourist Trap wrote:WMP is always included in windows since XP, even maybe since windows 98. But a flashplayer is also a possibility. Hower at developper side flash is not a free application...

That's also good - I'm aiming to be compatible with modern Windows (i.e. from XP. Idk about Windows 10 since it's very new and hardly anybody would have it - and even then they won't have it as their favourite OS yet) - and if a lot of people like the look of it and do not own Windows, then I may create Linux and DOS versions - but I do not have appropriate devices to test on :( I may even have to get my hands dirty all over again and create a Mac version; FB doesn't do Apple products yet does it?

Tourist Trap wrote:You may be able to find it in the lb online documentation? Since I've not enough keywords related to this, I can't search the web efficently. But you could probably.

You see; I was given the code by a fellow coder. But (for reasons I do not wish to share), I cannot ask him for it again. I may try and find it on the web, but there's alternatives which seem suitable enough (if not more suitable!).
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: How to load ATL in order to embed window movie player?

Postby Tourist Trap » Jul 29, 2015 18:11

datwill310 wrote: FB doesn't do Apple products yet does it?

Apple simply use something close to linux. However nobody would bother develop games for Apple, since there is always a doubt about if those guys would'nt some day make you pay some fee for it ;-)

Tourist Trap wrote: I may try and find it on the web, but there's alternatives which seem suitable enough (if not more suitable!).

Forget about it so. Go for windows SDK, bring back MSDN in the same time, assumed you've got very large hard disks. Then take also visual studio express edition, grab code block complete IDE. Those are a good basis for starting being at ease if you are to do some widerange programing. Visual studio would allow you to play easily some examples that are related to dot net, and Code Block would grant you access to C/C++ world in a friendly yet powerful fashion. By the way dot net frameworks are also huge downloads... You may need them from version 2 to 4 and further if you decide to use visual basic.

Unless, you come back to animated gif.... Here a buggy very early version for doing some kind of player :

Code: Select all

'
'....premise of a player
'
#include "fbgfx.bi"
dim as integer rs = MkDir ("frames")
               rs = ChDir("frames\")

dim as single x
dim as single y
dim as string filename
dim as integer scW, scH

Screen 13
ScreenInfo scW, scH
? "       CREATE IMAGES FOR VIDEO"
?
? "       PRESS A KEY TO CONTINUE"
sleep
cls
screenlock
dim as integer maxImage = 50
For index as integer = 0 to maxImage
    For x = 1 to 350
        y = (0.01*x)*50*sin(sqr(x)*x/sqr(index)*sin(1/x)+sqr(index))+scH\2
        circle (x,y), 5, 14
        circle (x,-y+scH), 5, 10
        y = 50*sin(sqr(x)*x/sqr(index)*sin(1/x)+sqr(index))+scH\2
        circle (x,y), 5, 4
        circle (x,-y+scH), 5, 2
        y = 50*sin(sqr(abs(50-x))*x/(index)^2+(index))+scH\2
        circle (x,y), 5, 6
    next x
    filename = "videoFrame"& index &".bmp"
    BSAVE filename, 0
    cls
next index
screenunlock

? "          PLAY VIDEO IN CONTEXT"
?
? "         PRESS A KEY TO CONTINUE"
sleep
Screen 18
Line (10,50)-(330,260), 8, bf
Line (9,49)-(331,261), 15, b
? "          LAUNCH VIDEO PLAYER"
?
? "        PRESS A KEY TO CONTINUE"
sleep

dim as string framename
dim as integer bufferSize = 10
dim as Any Ptr framebuffer(1 to 10)
dim as integer cyclecount = maxImage \ bufferSize
dim as integer currentcycle = 1
dim as integer generalindex = 1
dim as integer w, h

While currentcycle<=cyclecount
    If currentcycle = 1 then 'Buffer a whole row
        For index as integer = (currentcycle mod 2)to 9+(currentcycle mod 2) step 2
            framebuffer(index) = ImageCreate(320, 200)
            framename = "videoFrame"& generalindex &".bmp"
            draw string (100, 420), "Loading...videoFrame"& generalindex &".bmp"
            BLOAD (framename, framebuffer(index))
        next index
    End if
    If currentcycle >1 then  ''Flush and clean then buffer new row alternately
        For index as integer = (currentcycle mod 2)to 7+(currentcycle mod 2) step 2
            framebuffer(index+2) = ImageCreate(320, 200)
            framename = "videoFrame"& generalindex &".bmp"
            BLOAD (framename, framebuffer(index+2))
            imageinfo framebuffer(index+2), w, h
            Put (10,60), framebuffer(index+1), PSET
            ImageDestroy framebuffer(index+1)
            sleep 50
        next index
    Elseif currentcycle =1  Then ''Feed only

    End If
    currentcycle += 1
    generalindex += 1
wend

sleep

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 5 guests