예제 #1
0
	def playFile(self, filename, videoPid, audioPid):
		streamName = "dream" + str(randint(0, maxint))
		transcode = []

		doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$", filename.lower())

		if not doDirect or self.getTranscodeVideo():
			videoNormList = self.getVideoNorm().split(",")
#			,height=%s
			transcode.append("vcodec=%s,vb=%d,venc=ffmpeg{strict-rc=1},width=%s,height=%s,canvas-width=%s,canvas-height=%s,canvas-aspect=%s,fps=%s" % (
				self.getVideoCodec(),self.getVideoBitrate(),
				str(int(float(videoNormList[0]) - float(videoNormList[0]) * float(self.getOverscanCorrection()) / 100)),
				str(int(float(videoNormList[1]) - float(videoNormList[1]) * float(self.getOverscanCorrection()) / 100)),
				videoNormList[0], videoNormList[1], videoNormList[2], videoNormList[3]
			))
			if self.getSOverlay():
				transcode.append("soverlay")
		if not doDirect or self.getTranscodeAudio():
			transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" % (
				self.getAudioCodec(),
				self.getAudioBitrate(),
				self.getAudioChannels(),
				self.getSamplerate()
			))
		if re.match("[a-zA-Z]:", filename):
			# Fix for subtitles with VLC on Windows.
			filename = filename.replace("/", "\\")

		filename = filename.replace("\\", "\\\\").replace("'", "\\'")
#		input = filename + " :dvdread-caching=3000 :sub-track=1 :audio-track=1 :sout=#"
		input = filename + " :sout=#"

		if len(transcode) > 0:
			input += "transcode{%s}:" % (",".join(transcode))

		mux="ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
		input += "std{access=http,mux=%s,dst=/%s.ts} :sout-all :sout-keep" % (mux, streamName)

		print "[VLC] playfile", input

		xml = self.__xmlRequest("status", {"command": "in_play", "input": input})
		error = xml.getElementsByTagName("error")
		if error is not None and len(error) > 0:
			self.lastError = getText(error[0].childNodes).strip()
			if len(self.lastError) == 0:
				self.lastError = None
			else:
				print "[VLC] VlcControl error:", self.lastError
			return None
		else:
			self.lastError = None
		return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(), streamName)
예제 #2
0
    def playFile(self, filename, videoPid, audioPid):
        stats = self.status()
        if stats is not None and stats.has_key("apiversion"):
            apiversion = int(stats["apiversion"])
        else:
            apiversion = 2

        streamName = "dream" + str(randint(0, maxint))
        transcode = []

        doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$",
                                                  filename.lower())

        if not doDirect or self.getTranscodeVideo():
            videoNormList = self.getVideoNorm().split(",")
            # Video settings
            transcode.append("vcodec=%s,vb=%d,venc=ffmpeg,fps=%s" %
                             (self.getVideoCodec(), self.getVideoBitrate(),
                              videoNormList[3]))
            #New canvas - since VLC 0.9
            transcode.append(
                "vfilter=canvas{width=%s,height=%s,aspect=%s}" %
                (str(
                    int(
                        float(videoNormList[0]) - float(videoNormList[0]) *
                        float(self.getOverscanCorrection()) / 100)),
                 str(
                     int(
                         float(videoNormList[1]) - float(videoNormList[1]) *
                         float(self.getOverscanCorrection()) / 100)),
                 videoNormList[2]))
            if self.getSOverlay():
                transcode.append("soverlay")
        if not doDirect or self.getTranscodeAudio():
            transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" %
                             (self.getAudioCodec(), self.getAudioBitrate(),
                              self.getAudioChannels(), self.getSamplerate()))
        if re.match("[a-zA-Z]:", filename):
            # Fix for subtitles with VLC on Windows.
            filename = filename.replace("/", "\\")

        filename = filename.replace("\\", "\\\\").replace("'", "\\'")
        if apiversion > 2:
            inputPar = "?" + urlencode({
                "command": "in_play"
            }).replace('+', '%20')
        else:
            inputPar = ""

        input = filename
        if apiversion > 2:
            inputPar += "&" + urlencode({"input": input}).replace('+', '%20')
        else:
            inputPar += input

        input = ":sout=#"

        if len(transcode) > 0:
            input += "transcode{%s}:" % (",".join(transcode))

        mux = "ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
        input += "std{access=http,mux=%s,dst=/%s.ts}" % (mux, streamName)
        if apiversion > 2:
            inputPar += "&" + urlencode({"option": input}).replace('+', '%20')
        else:
            inputPar += " " + input

        input = ":sout-all"
        if apiversion > 2:
            inputPar += "&" + urlencode({"option": input}).replace('+', '%20')
        else:
            inputPar += " " + input

        input = ":sout-keep"
        if apiversion > 2:
            inputPar += "&" + urlencode({"option": input}).replace('+', '%20')
        else:
            inputPar += " " + input

        if not apiversion > 2:
            inputPar = "?" + urlencode({
                "command": "in_play",
                "input": inputPar
            }).replace('+', '%20')

        print "[VLC] playfile", inputPar

        xml = self.__xmlRequestRaw("status", inputPar)
        error = xml.getElementsByTagName("error")
        if error is not None and len(error) > 0:
            self.lastError = getText(error[0].childNodes).strip()
            if len(self.lastError) == 0:
                self.lastError = None
            else:
                print "[VLC] VlcControl error:", self.lastError
            return None
        else:
            self.lastError = None
        return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(),
                                       streamName)
예제 #3
0
    def playFile(self, filename, videoPid, audioPid):
        streamName = "dream" + str(randint(0, maxint))
        transcode = []

        doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$",
                                                  filename.lower())

        if not doDirect or self.getTranscodeVideo():
            videoNormList = self.getVideoNorm().split(",")
            # Video settings
            transcode.append("vcodec=%s,vb=%d,venc=ffmpeg,fps=%s" %
                             (self.getVideoCodec(), self.getVideoBitrate(),
                              videoNormList[3]))
            #New canvas - since VLC 0.9
            transcode.append(
                "vfilter=canvas{width=%s,height=%s,aspect=%s}" %
                (str(
                    int(
                        float(videoNormList[0]) - float(videoNormList[0]) *
                        float(self.getOverscanCorrection()) / 100)),
                 str(
                     int(
                         float(videoNormList[1]) - float(videoNormList[1]) *
                         float(self.getOverscanCorrection()) / 100)),
                 videoNormList[2]))
            if self.getSOverlay():
                transcode.append("soverlay")
        if not doDirect or self.getTranscodeAudio():
            transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" %
                             (self.getAudioCodec(), self.getAudioBitrate(),
                              self.getAudioChannels(), self.getSamplerate()))
        if re.match("[a-zA-Z]:", filename):
            # Fix for subtitles with VLC on Windows.
            filename = filename.replace("/", "\\")

        filename = filename.replace("\\", "\\\\").replace("'", "\\'")
        param = {"command": "in_play", "input": filename, "option": []}

        input = ":sout=#"

        if len(transcode) > 0:
            input += "transcode{%s}:" % (",".join(transcode))

        mux = "ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
        input += "std{access=http,mux=%s,dst=/%s.ts}" % (mux, streamName)
        param["option"].append(input)

        param["option"].append(":sout-all")
        param["option"].append(":sout-keep")

        if self.apiversion() <= 2:
            param["input"] = param["input"] + ' ' + ' '.join(param["option"])
            del param["option"]

        print "[VLC] playfile", param

        xml = self.__xmlRequest("status", param)
        error = xml.getElementsByTagName("error")
        if error is not None and len(error) > 0:
            self.lastError = getText(error[0].childNodes).strip()
            if len(self.lastError) == 0:
                self.lastError = None
            else:
                print "[VLC] VlcControl error:", self.lastError
            return None
        else:
            self.lastError = None
        host = self.getHost()
        port = self.getHttpPort()
        if self.getPassword():
            username = ''  # VLC uses empty username
            authorization = base64.encodestring(
                '%s:%s' % (username, self.getPassword()))[:-1]
            host = authorization + "@" + host
        return "http://%s:%d/%s.ts" % (host, port, streamName)
예제 #4
0
	def playFile(self, filename, videoPid, audioPid):
		streamName = "dream" + str(randint(0, maxint))
		transcode = []

		doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$", filename.lower())

		if not doDirect or self.getTranscodeVideo():
			videoNormList = self.getVideoNorm().split(",")
			# Video settings
			transcode.append("vcodec=%s,vb=%d,venc=ffmpeg,fps=%s" % (
				self.getVideoCodec(),self.getVideoBitrate(),
				videoNormList[3]
			))
			#New canvas - since VLC 0.9
			transcode.append("vfilter=canvas{width=%s,height=%s,aspect=%s}" % (
				str(int(float(videoNormList[0]) - float(videoNormList[0]) * float(self.getOverscanCorrection()) / 100)),
				str(int(float(videoNormList[1]) - float(videoNormList[1]) * float(self.getOverscanCorrection()) / 100)),
				videoNormList[2]
			))
			if self.getSOverlay():
				transcode.append("soverlay")
		if not doDirect or self.getTranscodeAudio():
			transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" % (
				self.getAudioCodec(),
				self.getAudioBitrate(),
				self.getAudioChannels(),
				self.getSamplerate()
			))
		if re.match("[a-zA-Z]:", filename):
			# Fix for subtitles with VLC on Windows.
			filename = filename.replace("/", "\\")

		filename = filename.replace("\\", "\\\\").replace("'", "\\'")
		param = {
			"command": "in_play",
			"input": filename,
			"option": []
		}

		input = ":sout=#"

		if len(transcode) > 0:
			input += "transcode{%s}:" % (",".join(transcode))

		mux = "ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
		input += "std{access=http,mux=%s,dst=/%s.ts}" % (mux, streamName)
		param["option"].append(input)

		param["option"].append(":sout-all")
		param["option"].append(":sout-keep")

		if self.apiversion() <= 2:
			param["input"] = param["input"] + ' ' + ' '.join(param["option"])
			del param["option"]

		print "[VLC] playfile", param

		xml = self.__xmlRequest("status", param)
		error = xml.getElementsByTagName("error")
		if error is not None and len(error) > 0:
			self.lastError = getText(error[0].childNodes).strip()
			if len(self.lastError) == 0:
				self.lastError = None
			else:
				print "[VLC] VlcControl error:", self.lastError
			return None
		else:
			self.lastError = None
		return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(), streamName)
예제 #5
0
    def playFile(self, filename, videoPid, audioPid):
        streamName = "dream" + str(randint(0, maxint))
        transcode = []
        parameters = ""
        oldVLC = self.getVLCType()

        doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$",
                                                  filename.lower())

        if not doDirect or self.getTranscodeVideo():
            videoNormList = self.getVideoNorm().split(",")
            # Video settings
            transcode.append("vcodec=%s,vb=%d,venc=ffmpeg,fps=%s" %
                             (self.getVideoCodec(), self.getVideoBitrate(),
                              videoNormList[3]))
            #New canvas - since VLC 0.9
            if oldVLC:
                transcode.append(
                    "vfilter=canvas{width=%s,height=%s,aspect=%s}" %
                    (str(
                        int(
                            float(videoNormList[0]) - float(videoNormList[0]) *
                            float(self.getOverscanCorrection()) / 100)),
                     str(
                         int(
                             float(videoNormList[1]) -
                             float(videoNormList[1]) *
                             float(self.getOverscanCorrection()) / 100)),
                     videoNormList[2]))
            if self.getSOverlay():
                transcode.append("soverlay")
                if not oldVLC:
                    parameters += " :sout-spu"

        if not doDirect or self.getTranscodeAudio():
            transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" %
                             (self.getAudioCodec(), self.getAudioBitrate(),
                              self.getAudioChannels(), self.getSamplerate()))
        # txt or dvbs subtitles:
        transcode.append("scodec=dvbs")

        # Fix for nat. chars in path/filename
        if not re.match("dvd", filename):
            filename = urllib.pathname2url(filename)

        if re.match("[a-zA-Z]:", filename):
            # Fix for subtitles with VLC on Windows.
            filename = filename.replace("/", "\\")

        # Fix for overlay subtitles with VLC > 1.1
        if not re.match("dvd", filename) and not re.match("http:", filename):
            filename = "file:///" + filename

        filename = filename.replace("\\", "\\\\").replace("'", "\\'")

        # yellow overlay subtitles
        if self.getSubYellow():
            parameters += " :freetype-color=0xFFFF00"

        # caching
        if re.match("dvd", filename):
            parameters += " :dvdread-caching=3000"
        else:
            parameters += " :file-caching=1000"

        # languages/tracks
        if self.getlangInputType() == "language":
            if self.gettypeAudio() != "---":
                parameters += " :audio-language=%s" % self.gettypeAudio()
            if self.gettypeSubtitles() != "---":
                parameters += " :sub-language=%s" % self.gettypeSubtitles()
        else:
            if self.gettypeAudio() != "-1":
                parameters += " :audio-track=%s" % self.gettypeAudio()
            if self.gettypeSubtitles() != "-1":
                parameters += " :sub-track=%s" % self.gettypeSubtitles()

        if re.match("dvd", filename):
            # sout-all only, if is not selected subtitle track or subtitle language
            if self.gettypeSubtitles() == "---" or self.gettypeSubtitles(
            ) == "-1":
                parameters += " :sout-all"
        else:
            parameters += " :sout-all"

        input = filename
        sout = ":sout=#"

        if len(transcode) > 0:
            sout += "transcode{%s}:" % (",".join(transcode))

        mux = "ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
        sout += "std{access=http,mux=%s,dst=/%s.ts}" % (mux, streamName)

        if oldVLC:
            input += " " + sout + parameters
            sout = ""
        else:
            params = "".join((sout, parameters)).split(' ')
            sout = ""
            for par in params:
                sout += "&option=%s" % quote_plus(par.lstrip(':'))

        print "[VLC] playfile", input
        print "[VLC] sout", sout

        xml = self.__xmlRequest("status", [("command", "in_play"),
                                           ("input", input)], sout)

        error = xml.getElementsByTagName("error")
        if error is not None and len(error) > 0:
            self.lastError = getText(error[0].childNodes).strip()
            if len(self.lastError) == 0:
                self.lastError = None
            else:
                print "[VLC] VlcControl error:", self.lastError
            return None
        else:
            self.lastError = None
        return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(),
                                       streamName)
예제 #6
0
    def playFile(self, filename, videoPid, audioPid):
        streamName = "dream" + str(randint(0, maxint))
        transcode = []

        doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$",
                                                  filename.lower())

        if not doDirect or self.getTranscodeVideo():
            videoNormList = self.getVideoNorm().split(",")
            #			,height=%s
            transcode.append(
                "vcodec=%s,vb=%d,venc=ffmpeg{strict-rc=1},width=%s,height=%s,canvas-width=%s,canvas-height=%s,canvas-aspect=%s,fps=%s"
                % (self.getVideoCodec(), self.getVideoBitrate(),
                   str(
                       int(
                           float(videoNormList[0]) - float(videoNormList[0]) *
                           float(self.getOverscanCorrection()) / 100)),
                   str(
                       int(
                           float(videoNormList[1]) - float(videoNormList[1]) *
                           float(self.getOverscanCorrection()) / 100)),
                   videoNormList[0], videoNormList[1], videoNormList[2],
                   videoNormList[3]))
            if self.getSOverlay():
                transcode.append("soverlay")
        if not doDirect or self.getTranscodeAudio():
            transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" %
                             (self.getAudioCodec(), self.getAudioBitrate(),
                              self.getAudioChannels(), self.getSamplerate()))
        if re.match("[a-zA-Z]:", filename):
            # Fix for subtitles with VLC on Windows.
            filename = filename.replace("/", "\\")

        filename = filename.replace("\\", "\\\\").replace("'", "\\'")
        #		input = filename + " :dvdread-caching=3000 :sub-track=1 :audio-track=1 :sout=#"
        input = filename + " :sout=#"

        if len(transcode) > 0:
            input += "transcode{%s}:" % (",".join(transcode))

        mux = "ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
        input += "std{access=http,mux=%s,dst=/%s.ts} :sout-all :sout-keep" % (
            mux, streamName)

        print "[VLC] playfile", input

        xml = self.__xmlRequest("status", {
            "command": "in_play",
            "input": input
        })
        error = xml.getElementsByTagName("error")
        if error is not None and len(error) > 0:
            self.lastError = getText(error[0].childNodes).strip()
            if len(self.lastError) == 0:
                self.lastError = None
            else:
                print "[VLC] VlcControl error:", self.lastError
            return None
        else:
            self.lastError = None
        return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(),
                                       streamName)
예제 #7
0
	def playFile(self, filename, videoPid, audioPid):
		streamName = "dream" + str(randint(0, maxint))
		transcode = []
		parameters = ""
		oldVLC = self.getVLCType()

		doDirect = isDvdUrl(filename) or re.match("(?i).*\.(mpg|mpeg|ts)$", filename.lower())

		if not doDirect or self.getTranscodeVideo():
			videoNormList = self.getVideoNorm().split(",")
			# Video settings
			transcode.append("vcodec=%s,vb=%d,venc=ffmpeg,fps=%s" % (
				self.getVideoCodec(),self.getVideoBitrate(),
				videoNormList[3]
			))
			#New canvas - since VLC 0.9
			if oldVLC:
				transcode.append("vfilter=canvas{width=%s,height=%s,aspect=%s}" % (
					str(int(float(videoNormList[0]) - float(videoNormList[0]) * float(self.getOverscanCorrection()) / 100)),
					str(int(float(videoNormList[1]) - float(videoNormList[1]) * float(self.getOverscanCorrection()) / 100)),
					videoNormList[2]
				))
			if self.getSOverlay():
				transcode.append("soverlay")
				if not oldVLC:
					parameters += " :sout-spu"

		if not doDirect or self.getTranscodeAudio():
			transcode.append("acodec=%s,ab=%d,channels=%d,samplerate=%s" % (
				self.getAudioCodec(),
				self.getAudioBitrate(),
				self.getAudioChannels(),
				self.getSamplerate()
			))
		# txt or dvbs subtitles:
		transcode.append("scodec=dvbs")

		# Fix for nat. chars in path/filename
		if not re.match("dvd", filename):
			filename = urllib.pathname2url(filename)

		if re.match("[a-zA-Z]:", filename):
			# Fix for subtitles with VLC on Windows.
			filename = filename.replace("/", "\\")

		# Fix for overlay subtitles with VLC > 1.1
		if not re.match("dvd", filename) and not re.match("http:", filename):
			filename = "file:///" + filename

		filename = filename.replace("\\", "\\\\").replace("'", "\\'")

		# yellow overlay subtitles
		if self.getSubYellow():
			parameters += " :freetype-color=0xFFFF00"

		# caching
		if re.match("dvd", filename):
			parameters += " :dvdread-caching=3000"
		else:
			parameters += " :file-caching=1000"

		# languages/tracks
		if self.getlangInputType()=="language":
			if self.gettypeAudio()!="---":
				parameters += " :audio-language=%s" % self.gettypeAudio()
			if self.gettypeSubtitles()!="---":
				parameters += " :sub-language=%s" % self.gettypeSubtitles()
		else:
			if self.gettypeAudio()!="-1":
				parameters += " :audio-track=%s" % self.gettypeAudio()
			if self.gettypeSubtitles()!="-1":
				parameters += " :sub-track=%s" % self.gettypeSubtitles()

		if re.match("dvd", filename):
			# sout-all only, if is not selected subtitle track or subtitle language
			if self.gettypeSubtitles()=="---" or self.gettypeSubtitles()=="-1": 
				parameters += " :sout-all"
		else:
			parameters += " :sout-all"

		input = filename
		sout = ":sout=#"

		if len(transcode) > 0:
			sout += "transcode{%s}:" % (",".join(transcode))

		mux="ts{pid-video=%d,pid-audio=%d}" % (videoPid, audioPid)
		sout += "std{access=http,mux=%s,dst=/%s.ts}" % (mux, streamName)

		if oldVLC:
			input +=  " " + sout + parameters
			sout = ""
		else:
			params = "".join((sout,parameters)).split(' ')
			sout = ""
			for par in params:
				sout +="&option=%s" % quote_plus(par.lstrip(':'))

		print "[VLC] playfile", input
		print "[VLC] sout", sout

		xml = self.__xmlRequest("status", [("command", "in_play"),("input", input)], sout)

		error = xml.getElementsByTagName("error")
		if error is not None and len(error) > 0:
			self.lastError = getText(error[0].childNodes).strip()
			if len(self.lastError) == 0:
				self.lastError = None
			else:
				print "[VLC] VlcControl error:", self.lastError
			return None
		else:
			self.lastError = None
		return "http://%s:%d/%s.ts" % (self.getHost(), self.getHttpPort(), streamName)