Problem using libexiv2 (v 0.26) in a C++ application
I am developing a specialized scientific application in C++, dealing with photos and videos, with a need to analyze metadata, for which I use the excellent libexiv2 library.
But I am presently stopped by the following problem (which will most probably sound ridiculous to many system analysts):
In order to analyze metadata included in a JPEG image file, I successfully execute:
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (imagefilepath);
But I found no way to do the same thing with a QuickTime video file.
If I try:
Exiv2::BasicIo::AutoPtrio = Exiv2::ImageFactory::createIo (fichier, true);
Exiv2::QuickTimeVideo::AutoPtr video = Exiv2::newQTimeInstance (io, false);
my program aborts, because of the “lack of dynamic links for newQTimeInstance”.
Could the explanation simply be that I have not installed libexiv2 correctly? Or is my code incorrect?
Any help would be much appreciated!
You have to build exiv2 for video. By default, you don't have video support. You can check with the command:
$ exiv2 -vVg videoThis will display enable-video=1 when video support is enabled.
Exiv2 v0.27 is scheduled for 28 December 2018. You can down load the current release candidate from http://exiv2.dyndns.org
Thanks very much for your quick and helpful answer.
I knew I had to activate somehow the video support while installing libexiv2, but I failed doing it properly.
My personal problem is that I am very little knowledgeable in installing external libraries.
I work under Visual Studio 2013, in a WIN32 configuration.
I understand I may not use “exiv2-0.26-trunk/exiv2-trunk/msvc”, because I am with WIN32 and I need the video support option. Therefore I use “exiv2-0.26-trunk/exiv2-trunk/src”, after having modified “exiv2-0.26-trunk/exiv2-trunk/include/exiv2/exv_msvc.h” to set: #define EXV_ENABLE_VIDEO 1. But thisproves not to be sufficient.
Obviously I am still missing something basic.
What you've done sounds correct to me. I'm surprised it hasn't enabled you to move forward.
Tomorrow I'll do a build of Exiv2 v0.27RC2/video-enabled using Visual Studio 2013. I will verify that the video code is working and attach the build to this issue.
I'm not sure your code is correct. Normally, you'd use the image factory to open the file and create the Image handler as follows:
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); assert(image.get() != 0); image->readMetadata();I don't think you need to use:
Before I do the build, can I ask you to download and test some files on your build. I found some video files here: https://github.com/mediaelement/mediaelement-files
When I build v0.26 on MacOS-X, I see:
$ exiv2 -vVg video exiv2 0.26 001a00 (64 bit build) enable_video=1 xmlns=video:http://www.video/ $ exiv2 -pa big_buck_bunny.* big_buck_bunny.jpg Xmp.xmp.CreatorTool XmpText 31 Adobe Fireworks CS6 (Macintosh) big_buck_bunny.jpg Xmp.xmp.CreateDate XmpText 20 2012-11-15T21:36:37Z big_buck_bunny.jpg Xmp.xmp.ModifyDate XmpText 20 2012-11-15T21:36:56Z big_buck_bunny.jpg Xmp.dc.format XmpText 10 image/jpeg big_buck_bunny.mp4 Xmp.video.FileSize XmpText 7 5.25558 big_buck_bunny.mp4 Xmp.video.FileName XmpText 18 big_buck_bunny.mp4 big_buck_bunny.mp4 Xmp.video.MimeType XmpText 15 video/quicktime ... big_buck_bunny.mp4 Xmp.video.AspectRatio XmpText 4 16:9 big_buck_bunny.webm Xmp.video.FileName XmpText 19 big_buck_bunny.webm big_buck_bunny.webm Xmp.video.FileSize XmpText 7 4.83615 big_buck_bunny.webm Xmp.video.MimeType XmpText 14 video/matroska big_buck_bunny.webm Xmp.video.EBMLVersion XmpText 1 1 big_buck_bunny.webm Xmp.video.EBMLReadVersion XmpText 1 1 ... $
Thanks very much indeed for your new detailed answer. Your last message helped me to progress a lot: so far I had been thinking that my code was probably the problem rather than the installation of libexiv2, and you indicate clearly that it is the other way around. My code for videos should indeed be the same as for photos (my initial guess):
Exiv2::Image::AutoPtr video = Exiv2::ImageFactory::open (videofilepath);
Assert (video.get () != 0);
rather than the complicated erroneous code I mentioned previously, and my error definitely lies somewhere in my libexiv2 installation. In effect, when I try to open your “big_buck_bunny “ file with the appropriate code (see above), the “ImageFactory::open” crashes, and if I try a getType() function, the result is “0” (unrecognized format).
If I refer to the “ReadDMe.txt” file contained in “exiv2-0.26-trunk/exiv2-trunk/msvc”, paragraph “1.4 Configuring build options”, I get lost precisely in the use of files “configure.bat” and “configure.py”.
I just downloaded Python 3.7 (so far unknown to me) but I have no idea on how to use it so as to reach the point where I can enter the famous option “-V” for “—enable-video”. I do not know if things look the same in your Mac configuration, but maybe you could show me an example. Once I get to the point where readMetadata () works, I will be in a well-known environment for the rest of my developments.
Thanks again for your invaluable help.
You really don't need to use configure.bat/configure.py combination. You can think of that as an "experts" build tool. Before I developed that (for v0.25), changing exv_msvc.h was the only way to set the build options for Visual Studio builds. configure.py does a lot of work to tailor/rewrite MSVC solution and project files to precisely match your build configuration.. For v0.27, we have adopted CMake and conan to achieve the same aim.
So, you are close to happiness. Please perform the build with VIDEO enabled in exv_msvc.h and run the command to be sure you have enabled video support.
c:\this\and\that\exiv2\msvc> bin\exiv2 -vVg videoI don't remember at the moment in which directory exiv2.exe is build. Run the command to determine the location of exiv2.exe:
c:\this\and\that\exiv2\msvc> dir/s exiv2.exe.
Once again, thank you for your advice, thanks to which I stop wasting time in “useless areas” of the exiv2 world. Unfortunately, even though I am now sure, thanks to you, that my code is correct (using exiv2::ImageFactory to open video files, which obviously must be managed like other image types), I am still unable to install correctly libexiv2 in my own C++ solution (under Visual Studio 2013). The aim is not to obtain exiv2.exe, but libexiv2.dll with video handling enabled.
At the beginning of my work with exiv2, a few years ago, my initial question was: should I build my own solution adding a “libexiv2” project created from scratch using the exiv2 source code? , or should I first build exiv2 (exiv2-trunk/msvc/eviv2.sln), then extract and use libexiv2.lib and libexiv2.dll?
So far, as long as I was only concerned by still images, I have made the second choice and all was 100% OK. But now, when I follow the same procedure, even after having set to 1 the parameter EXV_ENABLE_VIDEO, I get everything working but with still no recognition of video files. Would you by any chance have an example of installation procedure? Maybe using “Cmake with Conan” would be easier, but my problem is that I do not know anything about those tools…
If it sounds useful, I could give you the exact step-by-step procedure I have been using so far, which is clearly insufficient to cope with video management. But if my story is getting boring (which I can easily imagine!), please disregard this message and accept my thanks for all your help so far.
Don't go down the conan/cmake road. This is a very good road (that's why we have chosen it). However, it might make your life more difficult while you learn those tools.
For sure, you don't need to copy the Exiv2 source into your project. The whole point of using a library is to enable large code bodies to used and you only need two things:
1) The header files
2) The library (both the .lib and .dll)
I always recommend that people use the exiv2.exe command-line utility because I know what it is! I don't need/want to know about your project. When you get exiv2 to report that video is enabled, your library is good.
........> bin\exiv2 -vVg video
So let's discuss how to compile and link the library using your code. I've copied ReadMe.txt from the MSVC build for Exiv2 v.0.27 RC2 which was released on Saturday. Please read the notes. I think you can see how to link exiv2.lib and xmp.lib with your code. At run-time, your executable will use exiv2.dll.
I highly recommend that you work with exifprint.cpp (which you have). When you know how to compile, link and run a little program, you'll have more courage to tackle working with your own code.
As part of my work to release Exiv2 v0.27, I'm going to do some testing on the video code. Exiv2 is extensively tested, however the video code was contributed by students a few years ago. Building and testing is optional and regrettably it doesn't get much attention.
If you're still stuck, we could talk one-to-one on Skype next week when I've reviewed the video code on Visual Studio 2013.
Visual Studio 2017 Release DLL Bundle ------------------------------------- Structure of the bundle: ------------------------ bin/exiv2.exe exiv2 and sample applications bin/exiv2.dll dll lib/exiv2.lib & xmp.lib link libraries include/exiv2/ include files share/exiv2/cmake consume CMake files samples/exifprint.cpp sample code ReadMe.txt This file license.txt GPLv2.0 Software License releasenotes.txt Late breaking news README.md Developer Manual README-CONAN.md Developer Manual Appendix exiv2.png Exiv2 Logo +----------------------------------------------------------------------------+ | Caution: Use a Windows unzip utility such as 7z or winzip | | Cygwin unzip utilities can result in incorrect security with bin/exiv2.dll | +----------------------------------------------------------------------------+ To run exiv2.exe from the bundle: c:\> cd <bundle>\bin <bundle>\bin> exiv2 Add the bin to your PATH: c:\> cd <bundle>\bin <bundle>\bin>set PATH=%CD%;%PATH% To compile and link your own code: +-------------------------------------------------------------------------------+ | Caution: You must use the same version of Visual Studio as the build | | You will need to use the "Visual Studio Command Prompt" | | or initialise the DOS environment by calling vcvarsall.bat | | C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64>vcvars64.bat | +-------------------------------------------------------------------------------+ c:\> cd <bundle> <bundle>> cl /EHsc -Iinclude /MD samples\exifprint.cpp /link lib\exiv2.lib <bundle>> exifprint --version exiv2=0.27.0 ... xmlns=xmpidq:http://ns.adobe.com/xmp/Identifier/qual/1.0/ <bundle>>
Firstly, and to clear up things, I work with Dr François Louange (73 years old), a French PHD in signal processing, as a photo/video analyst. You can find his bio here : http://ipaco.fr/page38.html
He asked me to serve as intermediary between you and him, as he's not familiar at all with all the Internet/Forum/Blog stuff. All the previous posts here were written by him.
Anyway, here's its last reply:
I have had no opportunity to work on the integration of exiv2 into my software since our last exchange (health problems), and I took the opportunity of your new released 0.27 version to resume my attempts.
I am still stuck, due to my real difficulties in the field of “system engineering” (I am presently developing a large scientific application, which makes use of exiv2, but my skills in purely “system” areas are about 40 years old…). I have no difficulty at all using eviv2 functions, which I have done for several years with success, dealing so far with photos only. But my personal “nightmares” always lie in installing external software libraries.
So far I have used your Visual Studio solutions (.SLN files, available last time in exiv2-0.26-trunk) to build libexiv2 and to integrate the .LIB, .DLL and .HPP files into my solution. It always worked fine, except that I had no access to video metadata. I understand that now I should use Cmake to build the 0.27 version with the right options, but I have no clue about that tool. My goal is to build the libexiv2.LIB and .DLL files, to be used with my application under Visual Studio 2013 in WIN32 mode. Is there any pragmatic advice you could give me, an example I could follow, or anyone who could help me (including at charge)?
Thanks in advance for your help. I send you, and to the “exiv2” project, my sincere best wishes for the coming new year.
Happy New Year.
Thanks for your message. I was a little surprised when you "disappeared" in December. I was very busy with v0.27, so I didn't "ping" you.
I'd like you to consider moving to the Community Edition of Visual C++ 2017 and using CMake with v0.27. I understand that changing tools and building libraries can be rather challenging, however if you and I use the same tools, it's easier for me to help you. My license for Visual Studio 2013 has expired and while I can continue to run batch scripts to build for that platform, I am unable to launch the IDE and use it interactively.
If you'd like to send me your code (on a CD/DVD or as a download), I will investigate getting your code to work with VS 2017. I don't require payment to investigate this. If this is going to be a lot of work, we can discuss payment - however offer is to investigate for nothing. I am retired and have no desire to do consultancy.
If you're unable to move to 2017, I believe I can do a build of Exiv2 v0.27 with VS2013. CMake creates solution/vcxproj files. Integrating your code with that build is probably quite easy. However if you have issues, I may be unable to help because of my license issue with VS2013. If you send me your code, I assure you that it will be treated with respect and privacy.
I believe there is a community edition of Visual Studio 2013 and we could both use that. However, if we're going to cooperate, I'd prefer to work with Microsoft's more recent product offerings.
Thank you for using Exiv2. I'm optimistic that we can easily find a path forward.
Happy New Year, Robin, and many thanks for your quite positive and helpful message. I wish you and your “baby” EXIV2 a lot of success and satisfaction in 2019.
You are absolutely right, I must first migrate from Visual 2013 to Visual 2017. This is now my first priority (in the past, I already managed to migrate from VS 2003 to VS 2013) and I will let you know as soon as my solution works under VS2017 (or if I meet too big problems). This should take me a few days.
Thanks again and best regards.
François and Antoine
Exiv2 isn't a baby any more. It's a rebellious teenager (born 2003). I think it's going to be a beautiful swan as it moves into the future with Luis and Dan.
Good Luck with moving to Visual Studio 2017. I hope that transition doesn't cause you too much pain.
If VS2017 is diffult, I have two suggestions:
1) Send me your code (on a CD/DVD or download)
2) Come to England and work with me 1-to-1
We had a "Exiv2 Developer's Week-end" in May 2018 at my home in England. Luis is Spanish. He live in lives in Switzerland and speaks French (and English). We haven't discussed a weekend together in 2019. However, if you need 1-to-1 help, that would be the perfect time for us to help you.
Dear Robin, I did it at last! My solution (93 projects) is now managed by Visual Studio 2017 Community. It has been sort of a struggle, with many small modifications required, mainly due to drastic changes in Windows 10 (Windows Kits, etc.). I have reinstalled exiv2 version 0.26 as I did before, using your “exiv2.sln” solution.
Still, the result is a bit strange: in Release mode, my software IPACO now runs exactly like before, including for exiv2, which is operational with photos and not with videos (in spite of “#define EXV_ENABLE_VIDEO 1”). But in Debug mode, it crashes when executing certain exiv2 functions. I do not know why, but this is not that crucial, since the aim is anyway to integrate exiv2 0.27 and to enable IPACO to work also with videos.
What do you advise me to do now?
Best regards. Francois.
As you know, build engineering is hard work. Seldom appreciated. A lot of build engineering work involves unfamiliar tools. Writing C++ seems easy by comparison to fixing the build. In most offices the senior people only write code and get the young folks (college hires) to manage the build and test suite. Wrong way round to me. Having confidence in the build and test tools ensures the product is working well.
To move forward from here, you should:
1) Install python3
2) Install conan
- install conan with pip3
- instructions on the conan web site
3) Download and install CMake for windows
- install it for "all users" and be sure it's on your PATH
4) Download the Exiv2 0.27 Source bundle from http://exiv2.org
- build exiv2 v0.27 as documented in README-CONAN.md.
When you build with CMake, you have to choose Shared (DLL) or Static when you run CMake. Although Visual Studio can dynamically switch between DLLs and Static, CMake does not support that. I personally dislike static libraries. However when folks distribute software, they often like "one big .exe" with everything in a single file.
Choosing is documented in README.md section 2.3. The default is to build DLLs. To build static, use the CMake option -DBUILD_SHARED_LIBS=Off.
You will need the CMake option -DEXIV2_ENABLE_VIDEO=On to build the video code.
Running the test suite is documented in README.md, however it's rather clunky as you need to install MinGW/msys2 to run our bash test scripts. We're transitioning to a new cross-platform test suite in python3 and hope to complete that work for Exiv2 v0.28. However you can run exiv2.exe from the command line to be certain that you've built it ok.
dir/s exiv2.exe cd bla/bla/bin exiv2 --verbose --version exiv2 -pa --grep DateTime http://clanmills.com/Stonehenge.jpg Exif.Image.DateTime Ascii 20 2015:07:16 20:25:28 Exif.Photo.DateTimeOriginal Ascii 20 2015:07:16 15:38:54 Exif.Photo.DateTimeDigitized Ascii 20 2015:07:16 15:38:54
When you've done that, you'll be ready for a break.
Then we need to integrate your code with the build. I think you can do that in Visual Studio by dragging and dropping project files.
I've never used Visual Studio 2017 GUI. Microsoft added support for CMake in Visual Studio 2017. So, I'm going to play with Visual Studio 2017 and give you an update. I don't expect pain.
I'm surprised that Exiv2 v0.26 with Video enabled is causing you trouble. If you get stuck with Exiv2 v0.27, I'll investigate what you've said about v0.26. However, if you're successful with v0.27, we don't need to bother.
Thanks a lot, Robin, for your last long and detailed message. I agree that build engineering is a very complex job. I used to be myself a system engineer, working close to hardware and assembler, in the low layers of operating systems, but that was more than 40 years ago… Today, being half-retired, I am still able to develop scientific software tools but I confess that I am lost with modern build techniques. I am only a bit familiar with Visual Studio.
However I started trying to follow your detailed roadmap, and so far I managed to install successfully Python, Pip3, Conan and Cmake in my PC (under Windows 10 professional 64 bits). Now I am facing the README-CONAN.md file, with the feeling that I try to read Chinese, but I am ready to take the necessary time to progress.
However, I am wondering whether I have any chance to succeed, and on the other hand I remember that you told me the following, on November 18th:
“Don't go down the conan/cmake road. This is a very good road (that's why we have chosen it). However, it might make your life more difficult while you learn about those tools.
For sure, you don't need to copy the Exiv2 source into your project. The whole point of using a library is to enable large code bodies to used and you only need two things:
1) The header files
2) The library (both the .lib and .dll)”
Did this mean that there exists a simpler way for me to obtain those .lb, .dll and .hpp files?
Again, thank you for your patience.
Yes. There is another way to proceed.
You can download the "build bundle" from here http://exiv2.org For Visual Studio 2017, it is: http://www.exiv2.org/builds/exiv2-0.27.0-msvc64.zip It's a DLL/Release build for 64 bits.
I've copied the file ReadMe.txt in the bundle below. I've documented how to build samples/exifprint.cpp without even using the Visual Studio GUI. This command is sufficient:
cl /EHsc -Iinclude /MD samples\exifprint.cpp /link lib\exiv2.lib
However there are a couple of things you have to do.
1) In a DOS Shell (cmd.exe), run the command:
cd c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC vcvarsall.bat
2) When you run the
cl /EHsc -Iinclude ..../link lib\exiv2.lib you must be in the exact directory in build bundle that I have specified.
This is essential because the option:
-Iinclude tells the compiler exactly where to find the exiv2 header files. Similarly, the option:
/link lib\exiv2.lib tells the linker exactly where to find the library.
3) You will require exiv2.dll at run time to execute the code once it is built.
I recommend that you try to follow my instructions below in ReadMe.txt as it should work easily and give you confidence.
Start up Visual Studio 2017, and Use File/New to create a new Console Application, I called it exifprint
Build and run the application.
It doesn't do anything interesting (it doesn't do anything)
#include <iostream> after
std::cout << "hello world\n"; to the code body
Build and run the application. It will say "hello world"
It knows nothing about exiv2.
I have downloaded the bundle to: c:\users\rmills\temp\exiv2-0.27.0-msvc
I the "Solution Explorer", Add the file
c:\users\rmills\temp\exiv2-0.27.0-msvc\samples\exifprint.cpp and remove the existing exifprint.cpp
Right-clink on the Solution exifprint and open the Properties.
In C/C++, Update "Additional Include Directories" with
In Linker, Update "Additional Library Directories" with
In Linker, Update "Libraries" to include exiv2.lib
Be sure to select x64 in the target drop-down in the GUI.
You'll need to specify the output directory to be:
It's very difficult for me to write those instructions and I'm sure you can't follow what I'm describing. However this is "everyday" Visual Studio.
I can't make it simpler.
I'm struggling to get him to link exiv2.lib. I know he will. I'm 1000% confident. I haven't used Visual Studio for a few years. It'll be easy, however I have to figure something out and I don't have any more time until Sunday evening.
Visual Studio 2017 Release DLL Bundle ------------------------------------- Structure of the bundle: ------------------------ bin/exiv2.exe exiv2 and sample applications bin/exiv2.dll dll lib/exiv2.lib & xmp.lib link libraries lib/cmake/exiv2 consume CMake files include/exiv2/ include files samples/exifprint.cpp sample code logs build and test logs ReadMe.txt This file license.txt GPLv2.0 Software License releasenotes.txt Late breaking news README.md Developer Manual README-CONAN.md Developer Manual Appendix exiv2.png Exiv2 Logo +----------------------------------------------------------------------------+ | Caution: Use a Windows unzip utility such as 7z or winzip | | Cygwin unzip utilities can result in incorrect security with bin/exiv2.dll | +----------------------------------------------------------------------------+ To run exiv2.exe from the bundle: c:\> cd <bundle>\bin <bundle>\bin> exiv2 Add the bin to your PATH: c:\> cd <bundle>\bin <bundle>\bin>set PATH=%CD%;%PATH% To compile and link your own code: +-------------------------------------------------------------------------------+ | Caution: You must use the same version of Visual Studio as the build | | You will need to use the "Visual Studio Command Prompt" | | or initialise the DOS environment by calling vcvarsall.bat | | C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64>vcvars64.bat | +-------------------------------------------------------------------------------+ c:\> cd <bundle> <bundle>> cl /EHsc -Iinclude /MD samples\exifprint.cpp /link lib\exiv2.lib <bundle>> exifprint --version exiv2=0.27.0 ... xmlns=xmpidq:http://ns.adobe.com/xmp/Identifier/qual/1.0/ <bundle>>
I've put together a Visual C++ 2017 Project in the attached zip. This is a copy of the "download bundle" and I've added 2 files in UserProject. exifprint.sln and exivprint/exifprint.vcxproject. This will compile and link samples/exifprint.cpp.