Duration return type?

Started by guthrie, November 04, 2018, 05:01:40 PM

Previous topic - Next topic

guthrie

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'


guthrie

#1
OK; got it:

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


This is a change required by Python-3.