from enum import Enum

class VideoEncoder(Enum):

    AV1         = {'label': 'av1', 'index': 1}
    VP9         = {'label': 'vp9', 'index': 2}
    H264        = {'label': 'h264', 'index': 3}
    COPY        = {'label': 'copy', 'index': 4}

    UNDEFINED   = {'label': 'undefined', 'index': 0}

    def label(self):
        """Returns the stream type as string"""
        return str(self.value['label'])

    def index(self):
        """Returns the stream type index"""
        return int(self.value['index'])

    @staticmethod
    def fromLabel(label : str):
        tlist = [t for t in VideoEncoder if t.value['label'] == str(label)]
        if tlist:
            return tlist[0]
        else:
            return VideoEncoder.UNDEFINED

    @staticmethod
    def fromIndex(index : int):
        tlist = [t for t in VideoEncoder if t.value['index'] == int(index)]
        if tlist:
            return tlist[0]
        else:
            return VideoEncoder.UNDEFINED
