コード例 #1
0
ファイル: Scanner.py プロジェクト: dimarr/vidscan
	def processFile(self, fullpath, lines): 
		vf = VideoFile(fullpath, os.path.relpath(fullpath, self.path).replace('\\', '/'))		
		# loop through lines of ffmpeg output
		for line in lines:
			# Extract video file info
			# Duration: 01:37:58.08, start: 0.000000, bitrate: 997 kb/s"
			match = re.search('Duration: (\d\d:\d\d:\d\d\.\d\d),[^,]+, bitrate: (\d+ [a-z\/]+)', line)
			if match:
				if vf.duration or vf.bitrate:
					raise AppError("Video file data already exists. Check regex")
				else:
					vf.duration = match.group(1)
					vf.bitrate = match.group(2)
			# Extract video stream info
			# Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x352 [SAR 1:1 DAR 20:11], 23.98 tbr, 23.98 tbn, 23.98 tbc
			match = re.search('Stream #\d+:\d+[^:]*: Video: ([^,]+), [^,]+, ([^,]+)', line)
			if match:
				if vf.v_codec or vf.v_resolution:
					raise AppError('Video stream already exists. Check regex')
				else:
					vf.v_codec = match.group(1)
					vf.v_resolution = match.group(2)
			# Exract audio stream info
			# Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 126 kb/s
			# Stream #0:1(eng): Audio: aac, 48000 Hz, stereo, fltp (default)
			match = re.search('Stream #\d+:\d+[^:]*: Audio: ([^,]+), [^,]+, ([^,]+), [^,]+(?:, (\d+ [a-z\/]+))?', line)
			if match:
				if vf.a_codec or vf.a_channel or vf.a_bitrate:
					raise AppError('Audio stream already exists. Check regex')
				else:
					vf.a_codec = match.group(1)
					vf.a_channel = match.group(2)
					if match.group(3) is not None:
						vf.a_bitrate = match.group(3)
		# Determine if file requires video transcoding
		# These video codecs do not need transcoding:
		# 1) h264 (High)
		# 2) h264 (Main) OR h264 (Main) (avc1 / 0x31637661) 
		if not (vf.v_codec == '' or re.search('h264 \(High\)', vf.v_codec) or re.match('^h264 \(Main\)(\s\(avc1 .*)?$', vf.v_codec)):
			vf.op_flag = vf.op_flag | VideoFileOp.TRANSCODE_VIDEO
		
		# Determine if file requires audio transcoding
		if not (vf.a_codec == '' or re.search('aac|mp3|dts', vf.a_codec, re.IGNORECASE)):
		   vf.op_flag = vf.op_flag | VideoFileOp.TRANSCODE_AUDIO
		vf.size = os.path.getsize(fullpath)
		   
		return vf