def probeVideo(self, filename=None): """ Probes a video file. Caveat: Supports only 1 video channel and 1 audio chanel @param: file Video file to probe @return Dictionary. Key "video" contains dictionary of VideoStream objects and key "audio" contains a dictionary of AudioStream objects """ loggerJobCreationRuntime.info("================================================================================") loggerJobCreationRuntime.info("Processing :" + str(filename)) # Prepare CL ffprobeCLBuilder = FFPROBECLGenerator() ffprobeCLBuilder.addInputFile(util.escapePathForOSIndependentShell(filename)) ffprobeCLBuilder.addShowStreams() cl = ffprobeCLBuilder.tocl() loggerJobCreationRuntime.info("ffprobe cl:" + str(cl)) # Run CL # clRunner = CLRunner(stdout=subprocess.PIPE, stderr=subprocess.PIPE) clRunner = CLRunner(shell=True) clRunner.run(cl) ffprobeRawOutput = clRunner.stdout() loggerJobCreationRuntime.info("ffprobe raw output:" + str(ffprobeRawOutput)) # Parse CL output ffprobeParser = FFprobeParser() streams = ffprobeParser.parseShowStreamsOuput(ffprobeRawOutput) # Second pass: Build media instances countStreams = len(streams) mediaStreams = list() if countStreams > 0: for i in range(0, countStreams, 1): stream = streams[i] mediaStream = None if stream["codec_type"] in "video": mediaStream = ApertureConverterPlugin.createVideoStream(d=stream) mediaStreams.append(mediaStream) elif stream["codec_type"] in "audio": mediaStream = ApertureConverterPlugin.createAudioStream(d=stream) mediaStreams.append(mediaStream) streamsMediaObjects = dict(video=dict(), audio=dict()) for i in range(0, len(mediaStreams)): mediaStream = mediaStreams[i] streams = None if mediaStream.getType() in "video": streams = (streamsMediaObjects["video"]) elif mediaStream.getType() in "audio": streams = (streamsMediaObjects["audio"]) streams[mediaStream.getStreamIndex()] = mediaStream loggerJobCreationRuntime.info("ffprobe converted output:" + str(streamsMediaObjects)) return streamsMediaObjects
def probeImage(self, filename=None): """ Probes an image file @param: file Image file to probe @return Dictionary. Key "image" contains dictionary of ImageStream objects """ loggerJobCreationRuntime.info("================================================================================") loggerJobCreationRuntime.info("Processing :" + str(filename)) # Get Image width identifyCLBuilder0 = IdentifyCLGenerator() identifyCLBuilder0.addInputFile(util.escapePathForOSIndependentShell(filename)) identifyCLBuilder0.addFormatOption() identifyCLBuilder0.addFormatWidthOption() cl0 = identifyCLBuilder0.tocl() loggerJobCreationRuntime.info("identify cl:" + str(cl0)) clRunner0 = CLRunner(shell=True) clRunner0.run(cl0) identifyCLRawOutput0 = clRunner0.stdout() identifyParser0 = IdentifyParser() width = identifyParser0.parseFormatWidthOption(identifyCLRawOutput0) # Get Image height identifyCLBuilder1 = IdentifyCLGenerator() identifyCLBuilder1.addInputFile(util.escapePathForOSIndependentShell(filename)) identifyCLBuilder1.addFormatOption() identifyCLBuilder1.addFormatHeightOption() cl1=identifyCLBuilder1.tocl() loggerJobCreationRuntime.info("identify cl:" + str(cl1)) clRunner1=CLRunner(shell=True) clRunner1.run(cl1) identifyCLRawOutput1=clRunner1.stdout() identifyParser1 = IdentifyParser() height = identifyParser1.parseFormatHeightOption(identifyCLRawOutput1) # Get Image DPI X identifyCLBuilder2 = IdentifyCLGenerator() identifyCLBuilder2.addInputFile(util.escapePathForOSIndependentShell(filename)) identifyCLBuilder2.addFormatOption() identifyCLBuilder2.addFormatHorizontalDPIOption() cl2=identifyCLBuilder2.tocl() loggerJobCreationRuntime.info("identify cl:" + str(cl2)) clRunner2=CLRunner(shell=True) clRunner2.run(cl2) identifyCLRawOutput2=clRunner2.stdout() identifyParser2 = IdentifyParser() dpiX = identifyParser2.parseFormatHorizontalDPIOption(identifyCLRawOutput2) # Get Image DPI Y identifyCLBuilder3 = IdentifyCLGenerator() identifyCLBuilder3.addInputFile(util.escapePathForOSIndependentShell(filename)) identifyCLBuilder3.addFormatOption() identifyCLBuilder3.addFormatVerticalDPIOption() cl3=identifyCLBuilder3.tocl() loggerJobCreationRuntime.info("identify cl:" + str(cl3)) clRunner3=CLRunner(shell=True) clRunner3.run(cl3) identifyCLRawOutput3=clRunner3.stdout() identifyParser3 = IdentifyParser() dpiY = identifyParser3.parseFormatVerticalDPIOption(identifyCLRawOutput3) # Get Image Quality identifyCLBuilder4 = IdentifyCLGenerator() identifyCLBuilder4.addInputFile(util.escapePathForOSIndependentShell(filename)) identifyCLBuilder4.addFormatOption() identifyCLBuilder4.addFormatQualityOption() cl4=identifyCLBuilder4.tocl() loggerJobCreationRuntime.info("identify cl:" + str(cl4)) clRunner4=CLRunner(shell=True) clRunner4.run(cl4) identifyCLRawOutput4=clRunner4.stdout() identifyParser4 = IdentifyParser() quality = identifyParser4.parseFormatQualityOption(identifyCLRawOutput4) imageStream = ImageStream(filename=filename, width=width, height=height, quality=quality, densityX=dpiX, densityY=dpiY) imageStreams = dict() imageStreams["0"] = imageStream streamsMediaObjects = dict(image=imageStreams) return streamsMediaObjects