예제 #1
0
def create_output(plugin):
    """Decides where to write the stream.

    Depending on arguments it can be one of these:
     - The stdout pipe
     - A subprocess' stdin pipe
     - A named pipe that the subprocess reads from
     - A regular file

    """

    if (args.output or args.stdout) and (args.record or args.record_and_pipe):
        console.exit(
            "Cannot use record options with other file output options.")

    if args.output:
        if args.output == "-":
            out = FileOutput(fd=stdout)
        else:
            out = check_file_output(args.output, args.force)
    elif args.stdout:
        out = FileOutput(fd=stdout)
    elif args.record_and_pipe:
        record = check_file_output(args.record_and_pipe, args.force)
        out = FileOutput(fd=stdout, record=record)
    else:
        http = namedpipe = record = None

        if not args.player:
            console.exit("The default player (VLC) does not seem to be "
                         "installed. You must specify the path to a player "
                         "executable with --player.")

        if args.player_fifo:
            try:
                namedpipe = NamedPipe()
            except OSError as err:
                console.exit("Failed to create pipe: {0}", err)
        elif args.player_http:
            http = create_http_server()

        title = create_title(plugin)

        if args.record:
            record = check_file_output(args.record, args.force)

        log.info("Starting player: {0}".format(args.player))

        out = PlayerOutput(args.player,
                           args=args.player_args,
                           quiet=not args.verbose_player,
                           kill=not args.player_no_close,
                           namedpipe=namedpipe,
                           http=http,
                           record=record,
                           title=title)

    return out
예제 #2
0
    def __init__(self, session, *streams, **options):
        if not self.is_usable(session):
            raise StreamError("cannot use FFMPEG")

        self.session = session
        self.process = None
        self.streams = streams

        self.pipes = [
            NamedPipe("ffmpeg-{0}-{1}".format(os.getpid(),
                                              random.randint(0, 1000)))
            for _ in self.streams
        ]
        self.pipe_threads = [
            threading.Thread(target=self.copy_to_pipe, args=(self, stream, np))
            for stream, np in zip(self.streams, self.pipes)
        ]

        ofmt = options.pop("format", "matroska")
        outpath = options.pop("outpath", "pipe:1")
        videocodec = session.options.get(
            "ffmpeg-video-transcode") or options.pop("vcodec", "copy")
        audiocodec = session.options.get(
            "ffmpeg-audio-transcode") or options.pop("acodec", "copy")
        metadata = options.pop("metadata", {})
        maps = options.pop("maps", [])
        copyts = options.pop("copyts", False)

        self._cmd = [self.command(session), '-nostats', '-y']
        for np in self.pipes:
            self._cmd.extend(["-i", np.path])

        self._cmd.extend(['-c:v', videocodec])
        self._cmd.extend(['-c:a', audiocodec])

        for m in maps:
            self._cmd.extend(["-map", str(m)])

        if copyts:
            self._cmd.extend(["-copyts"])
            self._cmd.extend(["-start_at_zero"])

        for stream, data in metadata.items():
            for datum in data:
                self._cmd.extend(["-metadata:{0}".format(stream), datum])

        self._cmd.extend(['-f', ofmt, outpath])
        log.debug("ffmpeg command: {0}".format(' '.join(self._cmd)))
        self.close_errorlog = False

        if session.options.get("ffmpeg-verbose"):
            self.errorlog = sys.stderr
        elif session.options.get("ffmpeg-verbose-path"):
            self.errorlog = open(session.options.get("ffmpeg-verbose-path"),
                                 "w")
            self.close_errorlog = True
        else:
            self.errorlog = devnull()
예제 #3
0
    def __init__(self, session, *streams, **options):
        if not self.is_usable(session):
            raise StreamError("cannot use FFMPEG")

        self.session = session
        self.process = None
        self.streams = streams

        self.is_muxed = options.pop("is_muxed", True)
        ofmt = options.pop("format", "matroska")
        outpath = options.pop("outpath", "pipe:1")
        videocodec = session.options.get(
            "ffmpeg-video-transcode") or options.pop("vcodec", "copy")
        audiocodec = session.options.get(
            "ffmpeg-audio-transcode") or options.pop("acodec", "copy")
        metadata = options.pop("metadata", {})
        maps = options.pop("maps", [])
        copyts = options.pop("copyts", False)

        self._cmd = [self.command(session), '-nostats', '-y']
        delayVideo = str(getE2config('WPvideoDelay', '0'))
        if delayVideo != '0':
            self._cmd.extend(['-itsoffset', delayVideo])

        if self.is_muxed:
            #self.pipes = [NamedPipe("ffmpeg-{0}-{1}".format(os.getpid(), random.randint(0, 1000))) for _ in self.streams]
            self.pipes = []
            self.pipesFiles = []
            for _ in self.streams:  #zmiana, zeby nie bylo duplikatow
                tmpName = "ffmpeg-{0}-{1}".format(os.getpid(),
                                                  random.randint(0, 1000))
                pipeFile = os.path.join(tempfile.gettempdir(), tmpName)
                if os.path.exists(pipeFile):
                    tmpName += str(random.randint(0, 9))
                #log.debug("pipeFile: {0}".format(pipeFile))
                self.pipes.extend([NamedPipe(tmpName)])
                self.pipesFiles.extend([pipeFile])
            #log.debug("pipeFile: {0}".format(self.pipesFiles))
            self.pipe_threads = [
                threading.Thread(target=self.copy_to_pipe,
                                 args=(self, stream, np))
                for stream, np in zip(self.streams, self.pipes)
            ]

            for np in self.pipes:
                self._cmd.extend(["-i", np.path])
        else:
            self._cmd.extend(["-i", self.streams[0]])

        self._cmd.extend(['-c:v', videocodec])
        self._cmd.extend(['-c:a', audiocodec])

        for m in maps:
            self._cmd.extend(["-map", str(m)])

        if copyts:
            self._cmd.extend(["-copyts"])
            self._cmd.extend(["-start_at_zero"])

        for stream, data in metadata.items():
            for datum in data:
                self._cmd.extend(["-metadata:{0}".format(stream), datum])

        self._cmd.extend(['-f', ofmt, outpath])

        log.debug("ffmpeg command: {0}".format(' '.join(self._cmd)))
        self.close_errorlog = False

        if session.options.get("ffmpeg-verbose"):
            self.errorlog = sys.stderr
        elif session.options.get("ffmpeg-verbose-path"):
            self.errorlog = open(session.options.get("ffmpeg-verbose-path"),
                                 "w")
            self.close_errorlog = True
        else:
            self.errorlog = devnull()