View Full Version : libavcodec.dll in VC++
RahulOP
21st June 2006, 10:53
Just wanted to know if there's anybody else out there who's ever done something like this?? I am told the Nokia Multimedia Converter is based on FFMPEG. Is this true??
RahulOP
21st June 2006, 13:19
After weeks of trying to program using the dlls and/or libs, i finally considered building my own gui i.e. Console Programming in vc++
In a new dialog based application i run this code
CString csExecute;
csExecute="C://msys//home//ffmpeg4//ffmpeg.exe";//+ "ffmpeg -i Rahul.avi -s qcif fort.mpeg";
csExecute+= " ";
csExecute+="-i Rahul.avi -s qcif -o fort1.mpeg";
SECURITY_ATTRIBUTES secattr;
ZeroMemory(&secattr,sizeof(secattr));
secattr.nLength = sizeof(secattr);
secattr.bInheritHandle = TRUE;
HANDLE rPipe, wPipe;
//Create pipes to write and read data
CreatePipe(&rPipe,&wPipe,&secattr,0);
//
STARTUPINFO sInfo;
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags=STARTF_USESTDHANDLES;
sInfo.hStdInput=NULL;
sInfo.hStdOutput=wPipe;
sInfo.hStdError=wPipe;
char command[1024];
strcpy(command,csExecute.GetBuffer(csExecute.GetLength()));
//Create the process here.
CreateProcess(0, command,0,0,TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);
CloseHandle(wPipe);
//now read the output pipe here.
char buf[100];
DWORD reDword;
CString m_csOutput,csTemp;
BOOL res;
do
{
res=::ReadFile(rPipe,buf,100,&reDword,0);
csTemp=buf;
m_csOutput+=csTemp.Left(reDword);
}while(res);
AfxMessageBox(m_csOutput);
which does a nifty little trick of displaying output from the console
Now all i get is "Rahul.avi I/O Error
Usually that means that input file is truncated and/or corrupted "which is strange since if i try the same from the command line it encodes fine.
So what am I doing wrong?
3in1
12th July 2006, 14:48
Rahul, are you asking why are you unable to open your encoded file? I have used your code and it works. Your code is encoding dummy frames to MPEG4 as raw frames. If you want to use the file with some player you have to use the container (AVI for example). I guess you can use libaviformat for that.
RahulOP
21st July 2006, 06:02
3in1,
Sorry for the late reply. I realised my error was in this line
csExecute="C://msys//home//ffmpeg4//ffmpeg.exe";//+ "ffmpeg -i Rahul.avi -s qcif fort.mpeg";
After calling ffmpeg.exe i neednt call ffmpeg again. i can just continue with "-i Rahul.avi.................."
I hope this is what you are referring to.
If you are referring to my earlier problem of getting a 100Kb file, i am not sure if i've encoded the complete file. hence the error.
3in1
24th July 2006, 09:27
Rahul, sorry i mixed up that example using libavcodec and you using ffmpeg.
If you are wondering why can't you open that 100Kb file, the answer is, you just saved MPEG4 frames into a file and called it xx.avi. This is not an avi file. You just called it avi. You have to use some library that will store MPEG4 frames into avi container. You can use Libavformat for that purpose i guess.
Or if you are using MSVC++ you can use Vfw32.lib; look for it in msdn.
RahulOP
25th July 2006, 06:02
Rahul, sorry i mixed up that example using libavcodec and you using ffmpeg.
If you are wondering why can't you open that 100Kb file, the answer is, you just saved MPEG4 frames into a file and called it xx.avi. This is not an avi file. You just called it avi. You have to use some library that will store MPEG4 frames into avi container. You can use Libavformat for that purpose i guess.
Or if you are using MSVC++ you can use Vfw32.lib; look for it in msdn.
Ok that makes plenty of sense.
However
a.) I am still not sure if I am ecoding the entire file .Remember that I was using files in the excess of 1Mb
b.) I have no idea how to do what you've said unless you want to show me some code(yeah right LOL!!)
Thanks for all your help though.Really appreciate it :-)
adiboss007
2nd August 2006, 21:19
All,
I have been following this thread for the past few days. Initially, I had the same problem which Rahul did - linker errors, program crashes, etc.
Then, I went through the FFMpeg documentation which is included with its source code (doc/ffmpeg-doc.texi). There is a section called "Visual C++ compatibility". I followed the steps listed there exactly and then used the .lib and .dll files in my Windows wrapper application to encode a YUV file. And that was it ! I did not encounter any problems.
I hope that helped !
Thanks,
Adi
hellfred
3rd August 2006, 18:01
Here (http://ml20rc.msnfanatic.com/ffmpeg/msysguide.html) is an up to date and detailed description how to build libav*.dll and .libs on win32 and use them with MS MSVC IDE.
output_example.c from ffmpeg is used as program compiled in MSVC, that uses the dlls.
Hope that helps.
Hellfred
EDIT:
FFMPEG got several fixes for building shared libs and four building under MinGW:
Revision 5921: Move MinGW special casing for shared lib creation to configure
Revision 5922: Don't hardcode .dll in the MinGW section, use $SLIBSUF instead
Revision 5927: Shared libraries now go in $(shlibdir), not $(libdir)
This may help with older msys sh, not sure about it.
Revision 5926: detect more broken shells
You can access svn web interface here. (http://svn.mplayerhq.hu/ffmpeg/trunk/)
OmerParacha
15th February 2007, 06:43
when i do the following it throws an exception with libavcodec.dll for h264 decoder:
typedef void (*Register)(AVCodec* format);
Register RegisterFn;
AVCodec* h264Decoder;
RegisterFn=(Register)GetProcAddress(hInstLib,"register_avcodec");
if(!RegisterFn)
{
FreeLibrary(hInstLib);
MessageBox("Failed to load function: Register","Decoder");
return;
}
h264Decoder=(AVCodec*)GetProcAddress(hInstLib,"h264_decoder");
if(!h264Decoder)
{
FreeLibrary(hInstLib);
MessageBox("Failed to load function: Decoder","Decoder");
return;
}
it compiles fine but i get the message i wrote in my message boxes that "Failed to load function: Register" similarly "Failed to load function: Decoder"
BUT it works fine for any other functions i call in my code for example
typedef void (*Init)(void);
Init InitFn;
InitFn=(Init)GetProcAddress(hInstLib,"avcodec_init");
if(!InitFn)
{
FreeLibrary(hInstLib);
MessageBox("Failed to load function: Initialize","Decoder");
return;
}
Ne fast replies and help would be appreciated:scared: my guess is the other functions i am using take void parameter but the register_avcodec and the h264_decoder functions of the libavcodec.dll take parameters.
im a beginner at C/C++/VC++ and have always worked on Java so not so good with the .dll word so plzzzz help:eek:
OmerParacha
22nd February 2007, 06:42
well...i got around the issue i posted a few days ago...
the problem is still unclear but the solution was simple...
i got it running. now i'm still trying to decode a frame that i am encoding in a x264 code adaption i wrote on my own for VC++ 8.
decoding, nope not complete still trying to understand what to pass libavcodec.dll's h264 decoder function.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.