Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am playing a very large avi file in my C++ program on a Windows 32 bit system.

Small avi files play OK. This one avi file has large uncompressed bitmaps in it and it seems to be loading slowly while playing thus playing slowly. It plays, but it is slow. It plays in VLC media player much faster. It was encoded at 40 frames per second, but plays in my executable at 10 to 15 frames per second. I was thinking of loading it completely, then after it was fully loaded use Animate_Open to play it.

I am using

#define IDC_MYANIMATE   9

    HINSTANCE hInstanceAVI = GetModuleHandleW (NULL);

    HWND hwndAvi = Animate_Create (hParent, IDC_MYANIMATE, WS_BORDER | WS_CHILD, hInstanceAVI);

    int iAp = Animate_Open (hwndAvi, L"Very_Large.avi");

    ShowWindow (hwndAvi, SW_SHOW);

    iAp = Animate_Play (hwndAvi, 0, -1, -1);

but this seems to be slowed down by the continuously loading of the avi file as it is playing.

How can I load the avi file completely, then when loaded begin to play it?

What I have tried:

I tried searching for how to load a video file of any type in case I could adjust the logic for this. I have not found any help in this. They all seem to be doing close to what I am doing and not attempting to load the entire avi file first before playing it.

I do not mean to make the avi file a part of my executable, but for the executable to load the avi file then when the file is completely loaded play it. That way I can then delete the memory that the avi file is in and release that large amount of memory to do other things. So, start the exe, then while the exe is running click on a button to load the avi file, then click on a button to play the avi. Simple? It should be. I am having problems with the loading of the avi then holding it in memory until I click a button for it to play.

I am using a fast cpu, a solid state drive, lots of RAM, and a large page file, so I do not expect that to be much adjustable for this.

This should be easy since I can load multiple single bitmaps then later show then, but I seem to be missing something.

I am asking for help to solve this. Thank you.
Updated 21-Feb-23 3:19am
[no name] 12-Feb-23 12:24pm    
You play "chunks", while preloading other chunks. That presumes your "player" can handle memory streams and do background loading asynchronously. It's called: buffering.
Shao Voon Wong 12-Feb-23 23:42pm    
What is the file size of the AVI? 32-bit windows application only can access up to 2GB in the user mode memory space.
Member 15078716 13-Feb-23 6:46am    
874,825 KB
Duration 0:00:24
40 frames/second
972 frames in BMP format
24 bit

Thank you for drawing my attention to that.

I am now looking at my Page File Usage in case that might help to explain what is happening.

My Page File Usage remains steady within a variation of 1 up or down.
Member 15078716 13-Feb-23 8:48am    
In my resource.h

I can load a bitmap like this, then use it later.

#define IDB_Image1 2003
HBITMAP g_Image1 = LoadBitmap(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDB_Image1));

I do not know how to do this with avi or video.

I did not find any HAVI .
I did not find any LoadAVI .
So, how do I tell the program to make the resouce of an avi?

I can do this to define IDR_AVI1
#define IDR_AVI1 9123
Then what?

I tried
HANDLE LoadResource()
In case maybe I could load the avi as a generic file.
But, I did not find sufficient documentation explaining how to use LoadResource() with an avi file.

I think that I am getting close.
In my resource.rc I placed
IDR_AVI1 RCDATA "Very_Large.avi"

That seemed to be close, but it not only added 800+ MB to my exe, but it now does not play at all. Both are unwanted. I wanted to start the exe, without the avi, then load the avi, then play the avi.
Shao Voon Wong 15-Feb-23 23:42pm    
Reencode your large AVI with a good compression video codec.

// int iAp = Animate_Open(hwndAvi, L"Very_Large.avi");

// The second parameter Animate_Open() can contain a pointer to the path of the AVI file, or the name of an AVI resource.
// The parameter is created with the MAKEINTRESOURCE macro, which consists of the resource identifier in the LOWORD and null in the HIWORD.
// An application can use FindResource() and LoadResource() to find and load any type of resource.
// It is therefore also possible to read the AVI as a resource from a file.

int iAp = Animate_Open(hwndAvi, MAKEINTRESOURCE(IDR_AVI1));
Share this answer
As others have said in their comments, the secret to handling any large multimedia file is buffering. You do not actually need all of the file in memory at one time - only enough of the file to handle the current element plus a "jitter buffer" to allow for delays in reading more data (e.g. because the O/S is busy with other tasks).

Basically, you need two threads and a queue:

One thread reads blocks of data from the file, and places them in the queue. When the queue is full, this thread sleeps.
The other thread reads blocks of data from the queue, processing the data. If the queue is empty, it sleeps.

Implementing the queue is simple - you need two counting semaphores. The "write" semaphore starts out with a value of N, where N is the number of blocks in the queue. The "read" semaphore starts out with a value of 0.

Write to the queue:
1. Acquire the "write" semaphore
2. Insert a block at the tail of the queue
3. Release the "read" semaphore

Read from the queue:
1. Acquire the "read" semaphore
2. Remove a block from the head of the queue
3. Release the "write" semaphore

Note that the "read" semaphore's value is the number of blocks available in the queue, while the "write" semaphore's value is the number of spaces available in the queue.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900