1

Topic: Mpeg2lib Forum

Hi

Is there a forum for MPEG2Lib delphi library? I have a few questions regarding it but don't want to disturb author by e-mails; on the other hand other users might find this information useful too.

2

Re: Mpeg2lib Forum

There is no specific forum for MPEG2Lib, but you are welcome to use this one

Michael Vinther

> software developer <

Re: Mpeg2lib Forum

Thanks.

Currently I have two questions:
1. Is it possible to get image (not pixel) aspect ratio of the movie?
2. How can I get duration of the movie?

Thanks in advance.

4

Re: Mpeg2lib Forum

1.
I'm not sure I understand what you mean. You can get the image height and width in pixels, but nothing else.

2.
If you seek to the end of the movie (or perhaps 100kb before) you can get the timestamp. Compare that to the timestamp in the beginning.

Michael Vinther

> software developer <

Re: Mpeg2lib Forum

I have been very happy using Your library for some time, however there is one thing being a little bit annoying: it seems that mpeg2lib works with mpeg2 files in rather "exclusive" way, i.e. if I access, for instance, vob via library this file becomes inaccessible by other programs. However, dvd2avi program (and mpeg2lib library is based on its code, correct me, if I'm wrong) doesn't behave like that - I can access the same vob with dvd2avi and, for instance, virtualdub (via vfapi) simultaniously without problems. And vice versa, if I open vob in virtualdub, I can't access it via mpeg2lib getting "Can not open file filename.vob" error message.

I'm not sure I understand what you mean. You can get the image height and width in pixels, but nothing else

I had in mind aspect ratio (actually, display aspect ratio, or DAR) for anamorphic mpeg2 file.

In any case, Your library is really cool; it even works under wine emulator in linux without a glitch smile

6

Re: Mpeg2lib Forum

I haven't considered how the file is opened, but if is important in your application there are two ways of changing it. You can either change it directly in the DirectFileOpen function in dirfile.c and recompile the DLL, or you can use the streaming mode of the MPEG2Lib and do all the file handling yourself.

I don't know how to get the aspect ratio, so I can't help you there.

Michael Vinther

> software developer <

Re: Mpeg2lib Forum

And I have one question concerning streams: is it possible to access video file as FileStream, not MemoryStream (as in example, included with mpeg2lib)?
Main concern for me is StreamGetCallback function:
[code]function StreamGetCallback(Offset: Int64; Buffer: Pointer; Count: DWord; Owner: TObject): DWord; stdcall;
begin

8

Re: Mpeg2lib Forum

Yes, you can use any stream. It will look something like this:

[code]
function StreamGetCallback(Offset: Int64; Buffer: Pointer; Count: DWord; Owner: TObject): DWord; stdcall;
begin

Michael Vinther

> software developer <

Re: Mpeg2lib Forum

admin,Aug 31 2004, 04:17 PM wrote:

I haven't considered how the file is opened, but if is important in your application there are two ways of changing it. You can either change it directly in the DirectFileOpen function in dirfile.c and recompile the DLL, or you can use the streaming mode of the MPEG2Lib and do all the file handling yourself.

First, I've tried the easier way (access vob in streaming mode) and got the following results:
1. If MemoryStream is used, it works ok. However, if I'm correct, there may be potential errors with large files, i.e. files which size exceeds physical memory size. If I'm wrong, please correct me.
2. If FileStream is used (I used example code above), it works too, however the same problem occurs if the vob is already opened in any other program (or another instance of my program) I get the error "can not open video file". Or vice versa, if I open vob in my program, nobody can access it.

And recompiling of mpeg2lib library itself happend to be not as easy as make make_install. First, initially I didn't have windows c/c++ compiler. I tried to use free of charge borland's bcc (5.5), currently without success though. However, I blame my head/hands first; but it would help a lot if You could advice decent free windows c/c++ compiler.

And one more question about changes which I should do in dirfile.c. Should I simply add "FILE_SHARE_READ" option to CreateFile function? I would check it out myself if I could compile the library, however at the moment I can't but I have opportunity to ask this question smile

Sorry for disturbance (hope I'm not too annoying) and thanks in advance

10

Re: Mpeg2lib Forum

Yes, FILE_SHARE_READ sounds right. I have only use MS Visual C++ to compile it, so I'm afraid I can't help you there. I generally hate C++ compilers since there is always trouble with search path setup, compiler options and incompatibilities. - Much easier with Delphi  smile
I compiled a DLL with the FILE_SHARE_READ flag so I suggest you try that. It is available here.

Anyway, you don't have to use Delphi's build in stream handling, you could also implerment it yourself using Windows calls - CreateFile etc.. Then you can set the attributes as you need.

Michael Vinther

> software developer <

Re: Mpeg2lib Forum

Yes! It works like a charm, thank You VERY much!

admin,Sep 23 2004, 08:33 PM wrote:

Anyway, you don't have to use Delphi's build in stream handling, you could also implerment it yourself using Windows calls - CreateFile etc.. Then you can set the attributes as you need.

hmm, I didn't think about that; thanks for the tip

...and thanks again for updated dll!

12

Re: Mpeg2lib Forum

I have a problem with mpeg2lib.dll which is by the way, a great little DLL, if I get one thing working.
Instead of using it for Delphi I am using it under C++ Builder.
But the DLL works sometimes and when adding code it crashes horrendously. Seems some kind of memory overwriting but I can't find anything in my code.
If somebody could find any errors in the provided code, it would be much apprieciated.

1   OpenMPEG2File(FileName,0,-1)
2   SkipMPEG2Frames(NewFrame-FFileInfo->Frame);
3   GetMPEG2FrameInfo(FFrameInfo);
4   BMInfo=(BITMAPINFO *)new char[sizeof(BITMAPINFO)];
5   BMInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
6   BMInfo->bmiHeader.biWidth=FFrameInfo->Width;
7   BMInfo->bmiHeader.biHeight=FFrameInfo->Height;
8   BMInfo->bmiHeader.biPlanes=1;
9   BMInfo->bmiHeader.biBitCount=24;
10 BMInfo->bmiHeader.biCompression=BI_RGB;
11 BMInfo->bmiHeader.biSizeImage=FFrameInfo->Width*FFrameInfo->Height*3;
12 bp=new Graphics::TBitmap();
13 bp->Width=FFrameInfo->Width;
14 bp->Height=FFrameInfo->Height;
15 bp->PixelFormat=pf24bit;
16 r=GetMPEG2Frame();
17 if (r!=NULL)
18  SetDIBits(NULL,bp->Handle,0,FFrameInfo->Height,r,BMInfo,DIB_RGB_COLORS);
19 delete BMInfo;
20 return bp;

This code snippet crashes upon SetDIBits (can also crash elsewhere if I add other code), but works perfectly if I remove line 2. So it seems a bit strange and I can only explain it by some kind of memory leak.

//MensSana

13

Re: Mpeg2lib Forum

Did you try copying the image data via memcpy to the ScanLine member of TBitmap?

Michael Vinther

> software developer <

14

Re: Mpeg2lib Forum

Did not work either. The program just crashed there instead at SetDIBits.
Actually it did not execute the loop..
for (y=0; y<bp->Width; y++) since it overwrote the code in someway.

But...

since I suspected somekind of memory overwriting I added the code
char s[100]; before all the variable I was using meaning

  char s[100];   // Needed due to memory leak

  Graphics::TBitmap *bp;
  char *framedata;
  BITMAPINFO *BMInfo;


...and strangely enough s was overwritten, by 4 bytes!!!! and the program worked perfectly.
So either some variable in mpeg2lib.dll is underdimensioned, or
one of my variable accessing mpeg2lib.dll is....

I use the following when defining the DLL....

const unsigned int VideoFormatRGB24=1; // RGB interleaved, default
const unsigned int VideoFormatGray8=2; // Y plane
const unsigned int VideoFormatYUV24Planar=3; // YUV planes

struct TVideoFrameInfo {
int Width, Height;
double FrameRate;
double AspectRatio;
};

struct TVideoFileInfo {
__int64 Size;
__int64 Position;
DWORD Frame;
DWORD VideoPTS;
};

enum TMPEGPixelFormat {vpfNone,vpfRGB24,vpfGray8,vpfYUV24Planar};

typedef DWORD (__stdcall *TStreamGetCallback)(__int64 Offset,char *Buffer,DWORD Count,DWORD ID);
typedef int (*TOpenMPEG2File)(char *FileName,__int64 Offset,__int64 Size);
typedef int (*TOpenMPEG2Disk)(byte Drive,__int64 Offset,__int64 Size);
typedef int (*TOpenMPEG2Stream)(TStreamGetCallback StreamGetCallback,int SequentialStream,__int64 Size,DWORD ID);
typedef void (*TCloseMPEG2File)();
typedef void (*TSetMPEG2PixelFormat)(int Format);
typedef void (*TGetMPEG2FrameInfo)(TVideoFrameInfo *FrameInfo);
typedef void (*TGetMPEG2FileInfo)(TVideoFileInfo *FileInfo);
typedef byte *(*TGetMPEG2Frame)();
typedef void (*TSkipMPEG2Frames)(int FrameCount);
typedef void (*TMPEG2Seek)(__int64 Position);
typedef void (*TSetRGBScaleFlag)(int DoScaling);
typedef __int64 (*TWriteDataToFile)(char *FileName, __int64 Size);


...which I obtained thorugh the DLL soruce file.
Do you know if I declared anything in the wrong way??

Thanks

//MensSana

15

Re: Mpeg2lib Forum

....Seems that it is enough to set char s[11];
and the program works. Lower than that and a crash occurs.

16

Re: Mpeg2lib Forum

Solved the problem......sort of!!

Seems to be some error within GetMPEG2FrameInfo function....
When I use it as in the example above, it overwrites part of my code, whereas
I moved it to directly after opening the MPEG2 file, and the error disappeared.

I would think that there an array or variable that is underdimensioned for the task within that function in the DLL.

//MensSana

17

Re: Mpeg2lib Forum

Hi

It sounds a bit strange. You can look at GetMPEG2FrameInfo yourself in my mpeg2lib.cpp, declared as
DLLExport(void) GetMPEG2FrameInfo(TVideoFrameInfo *FrameInfo)

You can see that it just sets these 4 fields of the struct.
When you use the function, does it return the correct values?

Michael Vinther

> software developer <

18

Re: Mpeg2lib Forum

You are right. The code is short, and should not overwrite other code or data.
When using GetMPEG2FramInfo, the correct values are also returned, but something is
overwriting my code, and besides from what I have shown of the code earlier, there is not much more to show.
So I am a bit of a loss exactly where the problem might be.

//MensSana