Пример #1
0
class HTTPLiveVariantStream(KNDistributor):
    """Encode an input mpegts stream to the desired quality and segment the stream to chunks"""
    
    def __init__(self,name,encoderArguments,destdir=None,ffmpegbin=None):
        """
        Args:
        name: Name of this quality (Used in path names)
        encoderArguments: :class:`configobj.ConfigObj` with valid ffmpeg options. This will be passed to a new :class:`FFMpeg` object.
        destdir: The location where files will be saved.
        ffmpegbin: Path to ffmpeg binary.
        """
        super(HTTPLiveVariantStream,self).__init__(name=name)

        self.name = name
        """Name of this variant"""

        self.encoder = None
        """The :class:`FFMpeg` object used for encoding"""

        self.segmenter = None
        """The :class:`HTTPLiveSegmenter` object used for segmenting"""

        self.destinationDirectory = None
        self.setDestdir(destdir)
        # Set up the encoder
        if ffmpegbin:
            self.encoder = FFMpeg(name=name, ffmpegbin=ffmpegbin,encoderArguments=encoderArguments)
        else:
            self.encoder = FFMpeg(name=name, encoderArguments=encoderArguments)

        self.segmenter = HTTPLiveSegmenter(name=self.name+"_segmenter",destdir=self.destinationDirectory)

        # Hook everything up
        self.addOutlet(self.encoder)
        self.encoder.addOutlet(self.segmenter)

    def willStart(self):
        config = self._findObjectInInletChainOfClass(knive.Knive).config
        self.segmenter.segmenterbin = config['paths']['segmenterbin']

        
    def setDestdir(self,destdir,createDir=False):
        """Set the location where files will be saved to destdir.

        Args:
            createDir: (bool) Create the directory if it doesn't exist already. Else throws an exception.
        """

        self.log.debug("Settings destinationDirectory to %s" % destdir)
        destdir = os.path.abspath(destdir)
        if os.path.exists(destdir):
            self.destinationDirectory = destdir
            self.log.debug("Will create files in '%s'" % self.destinationDirectory)
        else:
            if(createDir):
                try:
                    os.mkdir(destdir)
                    self.setDestdir(destdir)
                except:
                    raise
            else:
                raise Exception("Directory does not exist %s" % destdir)
Пример #2
0
class HTTPLiveVariantStream(KNDistributor):
    """Encode an input mpegts stream to the desired quality and segment the stream to chunks"""
    def __init__(self, name, encoderArguments, destdir=None, ffmpegbin=None):
        """
        Args:
        name: Name of this quality (Used in path names)
        encoderArguments: :class:`configobj.ConfigObj` with valid ffmpeg options. This will be passed to a new :class:`FFMpeg` object.
        destdir: The location where files will be saved.
        ffmpegbin: Path to ffmpeg binary.
        """
        super(HTTPLiveVariantStream, self).__init__(name=name)

        self.name = name
        """Name of this variant"""

        self.encoder = None
        """The :class:`FFMpeg` object used for encoding"""

        self.segmenter = None
        """The :class:`HTTPLiveSegmenter` object used for segmenting"""

        self.destinationDirectory = None
        self.setDestdir(destdir)
        # Set up the encoder
        if ffmpegbin:
            self.encoder = FFMpeg(ffmpegbin=ffmpegbin,
                                  encoderArguments=encoderArguments)
        else:
            self.encoder = FFMpeg(encoderArguments=encoderArguments)

        self.segmenter = HTTPLiveSegmenter(name=self.name + "_segmenter",
                                           destdir=self.destinationDirectory)

        # Hook everything up
        self.addOutlet(self.encoder)
        self.encoder.addOutlet(self.segmenter)

    def willStart(self):
        config = self._findObjectInInletChainOfClass(knive.Knive).config
        self.segmenter.segmenterbin = config['paths']['segmenterbin']

    def setDestdir(self, destdir, createDir=False):
        """Set the location where files will be saved to destdir.

        Args:
            createDir: (bool) Create the directory if it doesn't exist already. Else throws an exception.
        """

        self.log.debug("Settings destinationDirectory to %s" % destdir)
        destdir = os.path.abspath(destdir)
        if os.path.exists(destdir):
            self.destinationDirectory = destdir
            self.log.debug("Will create files in '%s'" %
                           self.destinationDirectory)
        else:
            if (createDir):
                try:
                    os.mkdir(destdir)
                    self.setDestdir(destdir)
                except:
                    raise
            else:
                raise Exception("Directory does not exist %s" % destdir)