Problem using libexiv2 (v 0.26) in a C++ application

Added by antoine cousyn 21 days ago

Hello everyone!

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);
image->readMetadata ();

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);
io->open ();
Exiv2::QuickTimeVideo::AutoPtr video = Exiv2::newQTimeInstance (io, false);
video->readMetadata ();

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!

Thank you


Replies (8)

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by Robin Mills 21 days ago

You have to build exiv2 for video. By default, you don't have video support. You can check with the command:

$ exiv2 -vVg video
This 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

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by antoine cousyn 20 days ago

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.

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by Robin Mills 20 days ago

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.

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by Robin Mills 20 days ago

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: Exiv2::new QT....

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
...
$ 

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by antoine cousyn 19 days ago

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);
video->readMetadata ();

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.

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by Robin Mills 19 days ago

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 video
I 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
.

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by antoine cousyn 19 days ago

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.

RE: Problem using libexiv2 (v 0.26) in a C++ application - Added by Robin Mills 18 days ago

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>>

(1-8/8)

Redmine Appliance - Powered by TurnKey Linux