News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

SetNewValue works MOSTLY

Started by evilpenguin, May 12, 2020, 12:47:06 PM

Previous topic - Next topic

evilpenguin

This question is undoubtedly due to being new to both your API and to the obviously extremely complex rules of image file metadata. But I'm being a bit stumped and my efforts to search the forum haven't solved my problem, so here goes.

I have a vast collection of mpeg 4 video files created by various devices and applications. I have generally just named the files what I want the names to be and all is well. I recently started serving them up to DLNA devices in my home with the very simple minidlna server. And that now gives me a problem. The names shown are generally what is in the "Title" tag in the files, not the name of the files. So, for example, I have dozens of videos I can watch all named "VDEVICE" instead of the name of the file.

But I'm a 200 year old perl programmer, so I went to CPAN, found Image::ExifTool, and wrote me a little script designed to iterate over the directories of files and use the API to set the titles. It works for nearly all files. But a handful just don't work. It appears that what the files that are failing have in common is that they do NOT have a title in them already when I start. Here's the sub that does the work:


sub setTitle {
my ( $filename, $title ) = @_;

my $et   = new Image::ExifTool;
my $info = $et->ImageInfo($filename);

return 1 if ( $info->{Title} eq $title );

print( ( $info->{Title} eq $title ) ? "EQUAL\t" : "Unequal\t" );
print "Title b4 [$info->{Title}] after [$title]\n";

# if ( defined( $info->{Title} ) ) {
# # If it was defined, we need to set it
my $rc = $et->SetNewValue( Title => $title );
# }
# else {
# # If it wasn't defined, we need to add it!
# $et->SetNewValue( Title => $title, AddValue => 1 );
# }

# Whatever we did, we need to write it out.
my $result = $et->WriteInfo($filename);
print $result;

return 0;
}


There's some vestigial code there from attempts to fix, as you can see. And putting results into variables is so I can watch in a debugger. Here's what I can tell you about what I see in those code when it works and when it doesn't:

When it works, the key "Title" exists in the $info result. Also the $info result happens to have a great many more defined tags than the files that are failing, but I have no reason to suspect that has anything to do with it. Please let me know if you want a dump of all the $info content for the cases. The value of $rc is the same in both cases.

The $result in the success case is "1" and in the failure case is "0". I just added the GetValue("Error") and I think that is a major hint:

End of processing at large atom (LargeFileSupport not enabled)

I see a lot about this for command line tool. Where and how do I turn this on for the API? (And I think this may mean that it is a coincidence that this file happens to have no Title?)

StarGeek

You'll find details on how to enable LargeFileSupport under the Options method

This isn't my area of expertise, but I think the code would be along the lines of
my $exifTool = new Image::ExifTool;
$exifTool->Options(LargeFileSupport=> 1);
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

evilpenguin

This is a lesson to all. Work the problem until you are REALLY stumped before you post. I was fixing it at the same time you were helping me. I didn't use precisely the same syntax (although I think yours will work too, based on the documentation), but here's my final subroutine:


# Change the title of $filename to $title. Returns 0 on success.
sub setTitle {
my ( $filename, $title ) = @_;

my $et   = new Image::ExifTool;
$et->Options("LargeFileSupport", 1);
my $info = $et->ImageInfo($filename);

return 1 if ( $info->{Title} eq $title );

print( ( $info->{Title} eq $title ) ? "EQUAL\t" : "Unequal\t" );
print "Title b4 [$info->{Title}] after [$title]\n";

my $rc = $et->SetNewValue( Title => $title );

# Whatever we did, we need to write it out.
my $result = $et->WriteInfo($filename);

return !$result;
}


This works. And large file support was the issue, not the existence or non-existence of the "Title". That turned out to be a coincidence (the thing that produces the very large files for me also doesn't happen to set a title).

Thanks to the forum anyways! And thanks to everyone who works on Image::ExifTool. It helped me out enormously and clearly is something I should explore a lot more when I get the time. It would be fun, for example, to mapp all my photos that carry GPS data...