Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error when using libavcodec dll in vc++

Error when using libavcodec dll in vc++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
19 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Cedric Moonen

    You didn't answer my question: are you trying to do what I asked ? So, you have a function that returns a strcture (or a pointer to the struct) and you want to get it ? What is the exact prototype of the function "avcodec_alloc_context" ?

    RahulOP wrote:

    gave me a lot of linker errors LNK 2019 and LNK2001

    Did you link properly to the lib file ? So, did you add the lib in the project settings ? Instead of taking a complicated way, why don't you simply try to correct the initial errors ? If this dll is supplied with a lib file and a header file, then you can simply implicitely load the dll (not using LoadLibrary and GetProcAddress, but simply add the header file to your project and link to the library), this is much more easier to manage.


    Cédric Moonen Software developer
    Charting control

    R Offline
    R Offline
    RahulOP
    wrote on last edited by
    #10

    Quoting from the apiexample.c AVCodec *codec; AVCodecContext *c= NULL; int frame_size, i, j, out_size, outbuf_size; FILE *f; short *samples; float t, tincr; uint8_t *outbuf; /* find the MP2 encoder */ codec = avcodec_find_encoder(CODEC_ID_MP2); c= avcodec_alloc_context(); /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; This is what I am trying to re-write. This is how alloc_code_context is defined in the .h file AVCodecContext *avcodec_alloc_context(void); :doh: I just tried this typedef AVCodecContext*(avcodec_alloc_context)(); and I didnt have any errors.It ran perfectly. Though yes, there is something about memory leaks.Thank you so much for the heads-up

    E C 2 Replies Last reply
    0
    • E Eytukan

      I think he's shooting in the dark!


      --[:jig:]-- [My Current Status]

      R Offline
      R Offline
      RahulOP
      wrote on last edited by
      #11

      VuNic wrote:

      I think he's shooting in the dark!

      Mostly:-D ffmpeg was written for LINUX. All I am trying to do is create a simple application that will encode audio/video files. Trying this with the dlls.

      1 Reply Last reply
      0
      • R RahulOP

        Quoting from the apiexample.c AVCodec *codec; AVCodecContext *c= NULL; int frame_size, i, j, out_size, outbuf_size; FILE *f; short *samples; float t, tincr; uint8_t *outbuf; /* find the MP2 encoder */ codec = avcodec_find_encoder(CODEC_ID_MP2); c= avcodec_alloc_context(); /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; This is what I am trying to re-write. This is how alloc_code_context is defined in the .h file AVCodecContext *avcodec_alloc_context(void); :doh: I just tried this typedef AVCodecContext*(avcodec_alloc_context)(); and I didnt have any errors.It ran perfectly. Though yes, there is something about memory leaks.Thank you so much for the heads-up

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #12

        It seems that you didn't read properly everything I wrote :|. Or you didn't understand. Basically, it's exactly what I'm trying to say till the begining: that you have to use the exact prototype for the typedef (so, with return type and parameters). Anyway, why don't you focus on your main problem ? Which is these link errors you get when you use the header and the lib ? Did you even try that ? Are you sure you properly linked to the library ? Please when answering, read at least my post and answer the questions I ask (there is a reason for which I ask these, even if this is pretty obscure to you).


        Cédric Moonen Software developer
        Charting control

        R 1 Reply Last reply
        0
        • R RahulOP

          Quoting from the apiexample.c AVCodec *codec; AVCodecContext *c= NULL; int frame_size, i, j, out_size, outbuf_size; FILE *f; short *samples; float t, tincr; uint8_t *outbuf; /* find the MP2 encoder */ codec = avcodec_find_encoder(CODEC_ID_MP2); c= avcodec_alloc_context(); /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; This is what I am trying to re-write. This is how alloc_code_context is defined in the .h file AVCodecContext *avcodec_alloc_context(void); :doh: I just tried this typedef AVCodecContext*(avcodec_alloc_context)(); and I didnt have any errors.It ran perfectly. Though yes, there is something about memory leaks.Thank you so much for the heads-up

          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #13

          Can you e-mail me the files? DejaVuNic -at- Gmail I'll try it a try.


          --[:jig:]-- [My Current Status]

          1 Reply Last reply
          0
          • C Cedric Moonen

            It seems that you didn't read properly everything I wrote :|. Or you didn't understand. Basically, it's exactly what I'm trying to say till the begining: that you have to use the exact prototype for the typedef (so, with return type and parameters). Anyway, why don't you focus on your main problem ? Which is these link errors you get when you use the header and the lib ? Did you even try that ? Are you sure you properly linked to the library ? Please when answering, read at least my post and answer the questions I ask (there is a reason for which I ask these, even if this is pretty obscure to you).


            Cédric Moonen Software developer
            Charting control

            R Offline
            R Offline
            RahulOP
            wrote on last edited by
            #14

            I am so sorry. I tried the typedef AVCodecContext* thingy based on your post except that I didnt quote it in my reply. I believe I am properly linked to the library files. These are the steps I followed In the project Properties Select C/C++ General Tab and set the path for 'Include directories' seperated by semicolon( i.e path to libavcodec, libavformat) In the Linker Tab put the path to Lib files of ffmpeg in the option 'Additional Library Directories path' (i.e the path to avformat.lib etc) In the Linker Tab Put the Library files names to the option 'Additional dependencies' ( avformat.lib avcodec.lib) These are the linker errors I am getting fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2019: unresolved external symbol ___divdi3 referenced in function _av_reduce fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2019: unresolved external symbol ___moddi3 referenced in function _av_reduce fflib2 error LNK2001: unresolved external symbol ___moddi3 fflib2 error LNK2001: unresolved external symbol ___moddi3 fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2019: unresolved external symbol __alloca referenced in function _rd8x8_c fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _mpeg1_encode_sequence_header fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _MPV_common_end fflib2 error LNK2019: unresolved external symbol ___umoddi3 referenced in function _mpeg1_encode_sequence_header fflib2 error LNK2019: unresolved external symbol ___fixunssfdi referenced in function _ff_rate_control_init fflib2 error LNK2019: unresolved external symbol ___fixunsdfdi referenced in function _ff_rate_estimate_qscale p.s. Would you mind giving me your e-mail address?

            C 1 Reply Last reply
            0
            • R RahulOP

              I am so sorry. I tried the typedef AVCodecContext* thingy based on your post except that I didnt quote it in my reply. I believe I am properly linked to the library files. These are the steps I followed In the project Properties Select C/C++ General Tab and set the path for 'Include directories' seperated by semicolon( i.e path to libavcodec, libavformat) In the Linker Tab put the path to Lib files of ffmpeg in the option 'Additional Library Directories path' (i.e the path to avformat.lib etc) In the Linker Tab Put the Library files names to the option 'Additional dependencies' ( avformat.lib avcodec.lib) These are the linker errors I am getting fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2019: unresolved external symbol ___divdi3 referenced in function _av_reduce fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2001: unresolved external symbol ___divdi3 fflib2 error LNK2019: unresolved external symbol ___moddi3 referenced in function _av_reduce fflib2 error LNK2001: unresolved external symbol ___moddi3 fflib2 error LNK2001: unresolved external symbol ___moddi3 fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2019: unresolved external symbol __alloca referenced in function _rd8x8_c fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2001: unresolved external symbol __alloca fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _mpeg1_encode_sequence_header fflib2 error LNK2019: unresolved external symbol ___udivdi3 referenced in function _MPV_common_end fflib2 error LNK2019: unresolved external symbol ___umoddi3 referenced in function _mpeg1_encode_sequence_header fflib2 error LNK2019: unresolved external symbol ___fixunssfdi referenced in function _ff_rate_control_init fflib2 error LNK2019: unresolved external symbol ___fixunsdfdi referenced in function _ff_rate_estimate_qscale p.s. Would you mind giving me your e-mail address?

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #15

              Hmmm, strange... Are you sure you linked to all the required libraries ? Didn't you forget some ? Is there any documentation you can read and check if you did everything properly ?

              RahulOP wrote:

              Would you mind giving me your e-mail address?

              I would prefer not to do that. Because this is a forum so if we find a solution to your problem, this can be usefull to somebody else.


              Cédric Moonen Software developer
              Charting control

              R 1 Reply Last reply
              0
              • C Cedric Moonen

                Hmmm, strange... Are you sure you linked to all the required libraries ? Didn't you forget some ? Is there any documentation you can read and check if you did everything properly ?

                RahulOP wrote:

                Would you mind giving me your e-mail address?

                I would prefer not to do that. Because this is a forum so if we find a solution to your problem, this can be usefull to somebody else.


                Cédric Moonen Software developer
                Charting control

                R Offline
                R Offline
                RahulOP
                wrote on last edited by
                #16

                Well, this is an open-source encoder/decoder. So I downloaded both a release version and the SVN version.The SVN version also contains a "libavutil" folder that isnt there in the release version. Apparently when you build the SVN version, you should get a lib for libavutil which you are supposed to link to your program.Unfortuantely I didnt get any lib only dlls for the 3 folders libavformat, libavcodec and libavutil. The documentation isnt very clear and is mostly for Linux. The release version built fine but it had only the 2 folders libavcodec and libavformat. The build on this one gave me the lib files that I am now using. -- modified at 6:05 Wednesday 14th June, 2006 I seem to make the most irresponsible of mistakes:doh: I formatted my system recently and hence missed out on this crucial step which I had done before the format Add a call to `vcvars32.bat' (which sets up the environment variables for the Visual C++ tools) as the first line of `msys.bat'. The standard location for `vcvars32.bat' is `C:\Program Files\Microsoft Visual Studio8\VC\bin\vcvars32.bat', and the standard location for `msys.bat' is `C:\msys\1.0\msys.bat'. If this corresponds to your setup, add the following line as the first line of `msys.bat': call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" I have my lib files!!!! Yay!!!!!

                R 1 Reply Last reply
                0
                • R RahulOP

                  Well, this is an open-source encoder/decoder. So I downloaded both a release version and the SVN version.The SVN version also contains a "libavutil" folder that isnt there in the release version. Apparently when you build the SVN version, you should get a lib for libavutil which you are supposed to link to your program.Unfortuantely I didnt get any lib only dlls for the 3 folders libavformat, libavcodec and libavutil. The documentation isnt very clear and is mostly for Linux. The release version built fine but it had only the 2 folders libavcodec and libavformat. The build on this one gave me the lib files that I am now using. -- modified at 6:05 Wednesday 14th June, 2006 I seem to make the most irresponsible of mistakes:doh: I formatted my system recently and hence missed out on this crucial step which I had done before the format Add a call to `vcvars32.bat' (which sets up the environment variables for the Visual C++ tools) as the first line of `msys.bat'. The standard location for `vcvars32.bat' is `C:\Program Files\Microsoft Visual Studio8\VC\bin\vcvars32.bat', and the standard location for `msys.bat' is `C:\msys\1.0\msys.bat'. If this corresponds to your setup, add the following line as the first line of `msys.bat': call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" I have my lib files!!!! Yay!!!!!

                  R Offline
                  R Offline
                  RahulOP
                  wrote on last edited by
                  #17

                  All right to cut a long story short, the lib files were faulty. So I went back to Dynamic Linking. AVCodec *codec; int i, out_size, size, x, y, outbuf_size; FILE *f; uint8_t *outbuf, *picture_buf; HMODULE hDll3 = LoadLibrary("avcodec.dll"); typedef void (avcodec_find_encoder)(int CODECID); avcodec_find_encoder* p3 = (avcodec_find_encoder*)GetProcAddress(hDll3, "avcodec_find_encoder"); if(p3==NULL) AfxMessageBox("Failed loading3"); p3(CODEC_ID_MPEG1VIDEO); if(p3==NULL) AfxMessageBox("Failed loading3"); codec=(AVCodec *)p3; HMODULE hDll4 = LoadLibrary("avcodec.dll"); //(hDll should not be NULL here) typedef AVCodecContext* (avcodec_alloc_context)(); avcodec_alloc_context* p4 = (avcodec_alloc_context*)GetProcAddress(hDll4, "avcodec_alloc_context"); if(p4==NULL) AfxMessageBox("Failed loading4"); p4(); if(p4==NULL) AfxMessageBox("Failed loading4"); AVCodecContext *avctx = p4(); avctx->bit_rate=400000; avctx->width = 352; avctx->height = 288; /* frames per second */ avctx->frame_rate = 25; avctx->frame_rate_base= 1; avctx->gop_size = 10; /* emit one intra frame every ten frames */ avctx->max_b_frames=1; HMODULE hDll2 = LoadLibrary("avcodec.dll"); //(hDll should not be NULL here) typedef int (avcodec_open)(AVCodecContext *avctx, AVCodec *codec); avcodec_open* p2 = (avcodec_open*)GetProcAddress(hDll2, "avcodec_open"); if(p2==NULL) AfxMessageBox("Failed loading2"); p2((AVCodecContext *)p4,(AVCodec*)p3); Notice the last line--p2. p2 should be of the form (avctx,codec) i.e.alloc_code_context and avcodec_find_Encoder. The problem(given my display of my knowledge of pointes, does this really surprise you?) is that I cant pass avctx and codec directly. Also, since avctx takes values like bit_rate, width,height, those have to be reflected when I open the required codec. Any ideas??

                  C 1 Reply Last reply
                  0
                  • R RahulOP

                    All right to cut a long story short, the lib files were faulty. So I went back to Dynamic Linking. AVCodec *codec; int i, out_size, size, x, y, outbuf_size; FILE *f; uint8_t *outbuf, *picture_buf; HMODULE hDll3 = LoadLibrary("avcodec.dll"); typedef void (avcodec_find_encoder)(int CODECID); avcodec_find_encoder* p3 = (avcodec_find_encoder*)GetProcAddress(hDll3, "avcodec_find_encoder"); if(p3==NULL) AfxMessageBox("Failed loading3"); p3(CODEC_ID_MPEG1VIDEO); if(p3==NULL) AfxMessageBox("Failed loading3"); codec=(AVCodec *)p3; HMODULE hDll4 = LoadLibrary("avcodec.dll"); //(hDll should not be NULL here) typedef AVCodecContext* (avcodec_alloc_context)(); avcodec_alloc_context* p4 = (avcodec_alloc_context*)GetProcAddress(hDll4, "avcodec_alloc_context"); if(p4==NULL) AfxMessageBox("Failed loading4"); p4(); if(p4==NULL) AfxMessageBox("Failed loading4"); AVCodecContext *avctx = p4(); avctx->bit_rate=400000; avctx->width = 352; avctx->height = 288; /* frames per second */ avctx->frame_rate = 25; avctx->frame_rate_base= 1; avctx->gop_size = 10; /* emit one intra frame every ten frames */ avctx->max_b_frames=1; HMODULE hDll2 = LoadLibrary("avcodec.dll"); //(hDll should not be NULL here) typedef int (avcodec_open)(AVCodecContext *avctx, AVCodec *codec); avcodec_open* p2 = (avcodec_open*)GetProcAddress(hDll2, "avcodec_open"); if(p2==NULL) AfxMessageBox("Failed loading2"); p2((AVCodecContext *)p4,(AVCodec*)p3); Notice the last line--p2. p2 should be of the form (avctx,codec) i.e.alloc_code_context and avcodec_find_Encoder. The problem(given my display of my knowledge of pointes, does this really surprise you?) is that I cant pass avctx and codec directly. Also, since avctx takes values like bit_rate, width,height, those have to be reflected when I open the required codec. Any ideas??

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #18

                    One thing you still didn't understand is that a line like as follow is completely wrong !!

                    codec=(AVCodec *)p3

                    Basically, p3 is a pointer to a function. The (AVCodec *) in front of it specifies that the pointer must in fact be interpreted as a pointer to a AVCodec structure. Which of course completely false. Please, take care of what I said previously ! If this function returns an AVCode pointer, then you should do this instead:

                    HMODULE hDll3 = LoadLibrary("avcodec.dll");
                    typedef (AVCode*)(avcodec_find_encoder)(int CODECID);
                    avcodec_find_encoder* p3 = (avcodec_find_encoder*)GetProcAddress(hDll3, "avcodec_find_encoder");
                    if(p3==NULL)
                    AfxMessageBox("Failed loading3");
                    p3(CODEC_ID_MPEG1VIDEO);
                    if(p3==NULL)
                    AfxMessageBox("Failed loading3");

                    // Call the function and get the result:
                    AVCodec* codec = p3(...);

                    Also, note that in the typedef, you specified that this function receive a integer parameter, so of course you need to supply it also (note the ... in the function call). Next, I repeat it once again: don't call LoadLibrary multiple times for the same library, this is useless. And don't forget to call FreeLibrary after it. For this:

                    RahulOP wrote:

                    p2((AVCodecContext *)p4,(AVCodec*)p3);

                    This is the same as above: you cannot cast pointer to functions this way !!. What you need to do, is call p4 (and store the result somewhere, then call p3 and store the result somewhere and finally, call p2 and giving the previous results):

                    AVCodecContext* pContext = p4();
                    AVCoded* pCoded = p3(...); // Don't forget to pass a parameter

                    // You can modify pContext and pCodec before passing them to p2, of course

                    p2(pContext,pCoded);

                    If you have problems, please update all the code with the remarks I explained here before posting another question (otherwise, I will correct the same things over and over again). If you don't understand something, ask for more information (instead of blindly copy/pasting). Hope this helps


                    Cédric Moonen Software developer
                    Charting control

                    R 1 Reply Last reply
                    0
                    • C Cedric Moonen

                      One thing you still didn't understand is that a line like as follow is completely wrong !!

                      codec=(AVCodec *)p3

                      Basically, p3 is a pointer to a function. The (AVCodec *) in front of it specifies that the pointer must in fact be interpreted as a pointer to a AVCodec structure. Which of course completely false. Please, take care of what I said previously ! If this function returns an AVCode pointer, then you should do this instead:

                      HMODULE hDll3 = LoadLibrary("avcodec.dll");
                      typedef (AVCode*)(avcodec_find_encoder)(int CODECID);
                      avcodec_find_encoder* p3 = (avcodec_find_encoder*)GetProcAddress(hDll3, "avcodec_find_encoder");
                      if(p3==NULL)
                      AfxMessageBox("Failed loading3");
                      p3(CODEC_ID_MPEG1VIDEO);
                      if(p3==NULL)
                      AfxMessageBox("Failed loading3");

                      // Call the function and get the result:
                      AVCodec* codec = p3(...);

                      Also, note that in the typedef, you specified that this function receive a integer parameter, so of course you need to supply it also (note the ... in the function call). Next, I repeat it once again: don't call LoadLibrary multiple times for the same library, this is useless. And don't forget to call FreeLibrary after it. For this:

                      RahulOP wrote:

                      p2((AVCodecContext *)p4,(AVCodec*)p3);

                      This is the same as above: you cannot cast pointer to functions this way !!. What you need to do, is call p4 (and store the result somewhere, then call p3 and store the result somewhere and finally, call p2 and giving the previous results):

                      AVCodecContext* pContext = p4();
                      AVCoded* pCoded = p3(...); // Don't forget to pass a parameter

                      // You can modify pContext and pCodec before passing them to p2, of course

                      p2(pContext,pCoded);

                      If you have problems, please update all the code with the remarks I explained here before posting another question (otherwise, I will correct the same things over and over again). If you don't understand something, ask for more information (instead of blindly copy/pasting). Hope this helps


                      Cédric Moonen Software developer
                      Charting control

                      R Offline
                      R Offline
                      RahulOP
                      wrote on last edited by
                      #19

                      Thanks!! Helps a lot!! codec=(AVCodec *)p3 is sheer stupidity since that is the only line i wrote that way. Everything else I did exactly the way you told me. Will be posting my complete code as soon as I iron out the bugs :-)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups