예제 #1
0
    def __init__(self,
                 preset=None,
                 verbose=False,
                 encParams={},
                 seqParams={},
                 allParams={}):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(DiracEncoder, self).__init__()

        allParams.update(encParams)
        allParams.update(seqParams)

        if 'frame_rate' in allParams:
            allParams['frame_rate'] = rational(allParams['frame_rate'])
        if "pix_asr" in allParams:
            allParams['pix_asr'] = rational(allParams['pix_asr'])

        if _encoder_version == (0, 5, 4):
            self.encoder = EncoderWrapper(preset=preset,
                                          bufsize=1024 * 1024,
                                          verbose=verbose,
                                          encParams=allParams,
                                          seqParams=allParams)
        else:  # _encoder_version == (0,6,0):
            self.encoder = EncoderWrapper(preset=preset,
                                          bufsize=1024 * 1024,
                                          verbose=verbose,
                                          allParams=allParams)
예제 #2
0
    def __init__(self, preset=None, verbose=False, encParams={}, seqParams={}, allParams={}):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(DiracEncoder, self).__init__()

        allParams.update(encParams)
        allParams.update(seqParams)
        
        if 'frame_rate' in allParams:
            allParams['frame_rate'] = rational(allParams['frame_rate'])
        if "pix_asr" in allParams:
            allParams['pix_asr'] = rational(allParams['pix_asr'])
            
        if _encoder_version == (0,5,4):
            self.encoder = EncoderWrapper(preset=preset, bufsize=1024*1024, verbose=verbose, encParams=allParams, seqParams=allParams)
        else: # _encoder_version == (0,6,0):
            self.encoder = EncoderWrapper(preset=preset, bufsize=1024*1024, verbose=verbose, allParams=allParams)
예제 #3
0
class DiracEncoder(component):
    """
    DiracEncoder([preset][,verbose][,encParams][,seqParams][,allParams]) -> new Dirac encoder component

    Creates a component to encode video using the Dirac codec. Configuration based on
    optional preset, optionally overriden by individual encoder and sequence parameters.
    All three 'params' arguments are munged together, so do what you like :)

    Keyword arguments:
    
    - preset     -- "CIF" or "SD576" or "HD720" or "HD1080" (presets for common video formats)
    - verbose    -- NOT YET IMPLEMENTED (IGNORED)
    - encParams  -- dict of encoder setup parameters only
    - seqParams  -- dict of video sequence parameters only
    - allParams  -- dict of encoder setup parameters, sequence parameters, and source parameters, all munged together
    """
    def __init__(self,
                 preset=None,
                 verbose=False,
                 encParams={},
                 seqParams={},
                 allParams={}):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(DiracEncoder, self).__init__()

        allParams.update(encParams)
        allParams.update(seqParams)

        if 'frame_rate' in allParams:
            allParams['frame_rate'] = rational(allParams['frame_rate'])
        if "pix_asr" in allParams:
            allParams['pix_asr'] = rational(allParams['pix_asr'])

        if _encoder_version == (0, 5, 4):
            self.encoder = EncoderWrapper(preset=preset,
                                          bufsize=1024 * 1024,
                                          verbose=verbose,
                                          encParams=allParams,
                                          seqParams=allParams)
        else:  # _encoder_version == (0,6,0):
            self.encoder = EncoderWrapper(preset=preset,
                                          bufsize=1024 * 1024,
                                          verbose=verbose,
                                          allParams=allParams)

    def main(self):
        """Main loop"""
        done = False
        msg = None
        while not done:

            while self.dataReady("inbox"):
                frame = self.recv("inbox")
                data = "".join(frame['yuv'])
                self.encoder.sendFrameForEncode(data)

                while 1:  # loop until 'needdata' event breaks out of this
                    try:
                        bytes = self.encoder.getCompressedData()
                        self.send(bytes, "outbox")

                    except "NEEDDATA":
                        break

                    except "ENCODERERROR":
                        print("Encoder Error")
                        raise RuntimeError("ENCODERERROR")

                    except "INTERNALFAULT":
                        print("Internal Fault")
                        raise RuntimeError("INTERNALFAULT")

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, shutdownMicroprocess):
                    self.send(msg, "signal")
                    done = True

                elif isinstance(msg, producerFinished):
                    # write 'end of sequence' data
                    data = self.encoder.getEndSequence()
                    self.send(data, "outbox")
                    yield 1
                    self.send(msg, "signal")

            if not done:
                self.pause()

            yield 1
예제 #4
0
class DiracEncoder(component):
    """
    DiracEncoder([preset][,verbose][,encParams][,seqParams][,allParams]) -> new Dirac encoder component

    Creates a component to encode video using the Dirac codec. Configuration based on
    optional preset, optionally overriden by individual encoder and sequence parameters.
    All three 'params' arguments are munged together, so do what you like :)

    Keyword arguments:
    
    - preset     -- "CIF" or "SD576" or "HD720" or "HD1080" (presets for common video formats)
    - verbose    -- NOT YET IMPLEMENTED (IGNORED)
    - encParams  -- dict of encoder setup parameters only
    - seqParams  -- dict of video sequence parameters only
    - allParams  -- dict of encoder setup parameters, sequence parameters, and source parameters, all munged together
    """

    def __init__(self, preset=None, verbose=False, encParams={}, seqParams={}, allParams={}):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
        super(DiracEncoder, self).__init__()

        allParams.update(encParams)
        allParams.update(seqParams)
        
        if 'frame_rate' in allParams:
            allParams['frame_rate'] = rational(allParams['frame_rate'])
        if "pix_asr" in allParams:
            allParams['pix_asr'] = rational(allParams['pix_asr'])
            
        if _encoder_version == (0,5,4):
            self.encoder = EncoderWrapper(preset=preset, bufsize=1024*1024, verbose=verbose, encParams=allParams, seqParams=allParams)
        else: # _encoder_version == (0,6,0):
            self.encoder = EncoderWrapper(preset=preset, bufsize=1024*1024, verbose=verbose, allParams=allParams)

        
    def main(self):
        """Main loop"""
        done = False
        msg = None
        while not done:

            while self.dataReady("inbox"):
                frame = self.recv("inbox")
                data = "".join(frame['yuv'])
                self.encoder.sendFrameForEncode(data)

                while 1:  # loop until 'needdata' event breaks out of this
                    try:
                        bytes = self.encoder.getCompressedData()
                        self.send(bytes,"outbox")

                    except "NEEDDATA":
                        break

                    except "ENCODERERROR":
                        print "Encoder Error"
                        raise "ENCODERERROR"

                    except "INTERNALFAULT":
                        print "Internal Fault"
                        raise "INTERNALFAULT"


            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, shutdownMicroprocess):
                    self.send(msg,"signal")
                    done=True
                    
                elif isinstance(msg, producerFinished):
                    # write 'end of sequence' data
                    data = self.encoder.getEndSequence()
                    self.send(data, "outbox")
                    yield 1
                    self.send(msg, "signal")
                    

            if not done:
                self.pause()

            yield 1