File size: 1,728 Bytes
a103028
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

from ..common.Common import *
from ..common.Execute import *
from ..common.Log import *
from ..common.FileTypes import *

class PhotoInfo:
    
    # Width: Width of video, in pixels
    # Height: Height of video, in pixels
    # ColorSpace: ColorSpace of video
    # Size: File size, in bytes
    # FilePath: path of file

    def __init__(self, file_path):
        
        command = "ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,height,width,color_space -of csv=s=x:p=0 " + file_path
                   
        stdout, _, errorCode = ExecuteCommand(command)

        stdout = stdout.split("\n")[0]
        stdout = stdout.strip()

        info = stdout.split("x")

        self.file_path = file_path
        self.file_size = GetFileSize(file_path)

        if len(info) < 4:
            log.error("File " + file_path + " has size " + str(self.Size))
            log.error("Error running command (return code: " + str(errorCode) +  "): " + command + " | Returned string is " + stdout + " | Array is " + str(info))

        index = 0

        self.image_codec = info[index]
        index = index + 1

        self.width = int(info[index])
        index = index + 1

        self.height = int(info[index])
        index = index + 1

        self.color_space = info[index]
        index = index + 1

        if IsPNGFile(file_path):
            self.bit_depth = 10
        elif IsJPGFile(file_path):
            self.bit_depth = 8
        else:
            log.fatal("Unsupported photo file " + file_path)

    def String(self):
            return json.dumps(self, default=lambda o: o.__dict__, 
                sort_keys=True, indent=4)

    def Print(self, stream):
        stream.write(self.String())