Main Menu

ASF video duration

Started by ejm, January 08, 2018, 07:32:46 PM

Previous topic - Next topic

ejm

Hi,
I'm trying to read video duration. The -Composite:Duration tag works well for me, but I've noticed that it does not work for ASF/WMV format videos. ASF:PlayDuration seems to work for these.
Just wondering if this can/should be integrated into the built in -Composite:Duration tag.
I realise that ASF metadata is not writable, but that's ok for my use case because I am only interested in reading.
I've attempted to make my own readonly composite tag (see below). I've named it Duration_ to avoid the circular dependency on Composite:Duration. I know there's probably a better way to override Composite:Duration but I have not figured it out yet.
Here is my config file code:
%Image::ExifTool::UserDefined = (
  'Image::ExifTool::Composite' => {
    Duration_ => {
      Writable => 0,
      Desire => {
        0 => 'Duration',
        1 => 'ASF:PlayDuration',
      },
      ValueConv => q{
        return $val[0] if defined $val[0];
        return $val[1] if defined $val[1];
        return undef;
      },
    },
  },
);

This seems to work on my data but have not tested it comprehensively. Would appreciate any tips/improvements or recommendation of a better way to do this.
Thanks.

Phil Harvey

Very good.  It is fine as you have it, but the ValueConv can be simplified a bit, and you could add a print conversion so the output is in the same format as the existing Duration:

%Image::ExifTool::UserDefined = (
  'Image::ExifTool::Composite' => {
    Duration_ => {
      Writable => 0,
      Desire => {
        0 => 'Duration',
        1 => 'ASF:PlayDuration',
      },
      ValueConv => '$val[0] || $val[1]',
      PrintConv => 'ConvertDuration($val)',
    },
  },
);


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ejm

Great. Thanks very much for your quick reply.

Phil Harvey

About your suggestion of building it into the existing duration:  The thing to do would be to add yet another Composite:Duration tag, because all of the others are particular to their specific file formats.  (See the Composite tags documentation for details.)  I'll think about this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Rather than adding another Composite tag, I have renamed PlayDuration to just Duration in ExifTool 10.76.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ejm

Thank you, that seems like a good fix.