ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: guthrie on November 04, 2018, 05:01:40 PM

Title: Duration return type?
Post by: guthrie on November 04, 2018, 05:01:40 PM
I have a small python script that gets the "Duration" of a video file, and then to see if it was successful checks:
    (if "Duration" in result: ...)
But this gives an error - as the return type of the Duration call is of type:
   type(result):  <class 'bytes'>
I had not run this program for quite a while, but ... it used to work fine(!).

(Originally I had used -s3 to get file duration, but then I didn't know how to tell if it had accidentally found a non-video file. And that also changed the formatting...)

Code is:

filename="G:\VideoFile.mp4"
result = subprocess.Popen(["exifTool", "-n", "-Duration",  filename],
                            stdout = subprocess.PIPE,
                            stderr = subprocess.STDOUT)
ans = result.stdout.readline().strip()

Result is:
>>> ans
b'Duration                        : 7055.251'

Title: Re: Duration return type?
Post by: guthrie on November 04, 2018, 08:02:24 PM
OK; got it:

               result.stdout.readline().strip().decode("utf-8")


This is a change required by Python-3.