예제 #1
0
 def probeInfo(self, fname, posters_as_video=True):
     try:
         self.ffmpeg = FFMpeg()
         info = self.ffmpeg.probe(fname, posters_as_video)
         return info
     except Exception:
         return None
예제 #2
0
 def probeToJson(self, task, fname, output):
     try:
         self.ffmpeg = FFMpeg()
         self.ffmpeg.probeToJson(fname, output)
         if task.isCanceled():
             return None
         return {'task': task.description()}
     except Exception:
         return None
예제 #3
0
 def probeShow(self, task, fname):
     try:
         self.ffmpeg = FFMpeg()
         self.bytes_value = self.ffmpeg.probeGetJson(fname)
         if task.isCanceled():
             return None
         return {'task': task.description()}
     except Exception:
         return None
예제 #4
0
 def probeToJson(self, fname, output=None):
     try:
         self.ffmpeg = FFMpeg()
         self.ffmpeg.probeToJson(fname, output)
         self.finished.emit("probeToJson",
                            "Extract Information To Json succesfully!")
     except Exception as e:
         self.error.emit("probeToJson", e, traceback.format_exc())
         return
예제 #5
0
파일: Converter.py 프로젝트: ltbam/QGISFMV
 def probeShow(self, fname):
     try:
         self.ffmpeg = FFMpeg()
         bytes_value = self.ffmpeg.probeGetJson(fname)
         self.finishedJson.emit(
             "probeShow", "Extract Information succesfully!", bytes_value)
     except Exception as e:
         self.error.emit("probeShow", e, traceback.format_exc())
         return
예제 #6
0
    def convert(self, infile, outfile, options, twopass):
        try:
            timeout = 10

            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(infile)
            if info is None:
                self.error.emit("convert", "",
                                "Can't get information about source file")

            if not info.video and not info.audio:
                self.error.emit("convert", "",
                                'Source file has no audio or video streams')

            if info.video and 'video' in options:
                options = options.copy()
                v = options['video'] = options['video'].copy()
                v['src_width'] = info.video.video_width
                v['src_height'] = info.video.video_height

            if info.format.duration < 0.01:
                self.error.emit("convert", "", 'Zero-length media')

            if twopass:
                optlist1 = self.parse_options(options, 1)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist1,
                                                    timeout=timeout):
                    self.progress.emit(
                        int((50.0 * timecode) / info.format.duration))

                optlist2 = self.parse_options(options, 2)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist2,
                                                    timeout=timeout):
                    self.progress.emit(
                        int(50.0 + (50.0 * timecode) / info.format.duration))
            else:
                optlist = self.parse_options(options, twopass)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist,
                                                    timeout=timeout):
                    self.progress.emit(
                        int((100.0 * timecode) / info.format.duration))
            self.progress.emit(100)
            self.finished.emit("convert", "convert correct Finished!")
        except Exception as e:
            self.error.emit("convert", e, traceback.format_exc())
            return
예제 #7
0
    def convert(self, task, infile, outfile, options, twopass):
        while not task.isCanceled():
            timeout = 10

            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(infile)
            if info is None:
                task.cancel()
                return "Can't get information about source file"

            if not info.video and not info.audio:
                task.cancel()
                return 'Source file has no audio or video streams'

            if info.video and 'video' in options:
                options = options.copy()
                v = options['video'] = options['video'].copy()
                v['src_width'] = info.video.video_width
                v['src_height'] = info.video.video_height

            if info.format.duration < 0.01:
                task.cancel()
                return 'Zero-length media'

            if twopass:
                optlist1 = self.parse_options(options, 1)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist1,
                                                    timeout=timeout):
                    task.setProgress(
                        int((50.0 * timecode) / info.format.duration))

                optlist2 = self.parse_options(options, 2)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist2,
                                                    timeout=timeout):
                    task.setProgress(
                        int(50.0 + (50.0 * timecode) / info.format.duration))
            else:
                optlist = self.parse_options(options, twopass)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist,
                                                    timeout=timeout):
                    task.setProgress(
                        int((100.0 * timecode) / info.format.duration))
            task.setProgress(100)
        return {'task': task.description()}
        if task.isCanceled():
            return None
예제 #8
0
    def AddFileRowToManager(self,
                            name,
                            filename,
                            load_id=None,
                            islocal=False,
                            klv_folder=None):
        ''' Add file Video to new Row '''
        # We limit the number of videos due to the buffer
        if self.VManager.rowCount() > 5:
            qgsu.showUserAndLogMessage(
                QCoreApplication.translate(
                    "ManagerDock",
                    "You must delete some video from the list before adding a new one"
                ))
            return

        self.islocal = islocal
        self.klv_folder = klv_folder
        self.isStreaming = False
        w = QWidget()
        layout = QVBoxLayout()
        pbar = QProgressBar()
        layout.addWidget(pbar)
        w.setLayout(layout)
        rowPosition = self.VManager.rowCount()

        pbar.setGeometry(0, 0, 300, 30)
        pbar.setValue(0)
        pbar.setMaximumHeight(30)

        if load_id is None:
            row_id = 0
            if rowPosition != 0:
                row_id = int(self.VManager.item(rowPosition - 1, 0).text()) + 1
        else:
            row_id = load_id

        self.VManager.insertRow(rowPosition)

        self.VManager.setItem(rowPosition, 0, QTableWidgetItem(str(row_id)))

        self.VManager.setItem(rowPosition, 1, QTableWidgetItem(name))
        self.VManager.setItem(
            rowPosition, 2,
            QTableWidgetItem(
                QCoreApplication.translate("ManagerDock", "Loading")))
        self.VManager.setItem(rowPosition, 3, QTableWidgetItem(filename))
        self.VManager.setItem(rowPosition, 4, QTableWidgetItem("-"))
        self.VManager.setCellWidget(rowPosition, 5, w)

        self.VManager.setVisible(False)
        self.VManager.horizontalHeader().setStretchLastSection(True)
        self.VManager.setVisible(True)

        # resolve if it is a stream
        if "://" in filename:
            self.isStreaming = True

        if not self.isStreaming:
            # Disable row if not exist video file
            if not os.path.exists(filename):
                self.ToggleActiveRow(rowPosition, value="Missing source file")
                for j in range(self.VManager.columnCount()):
                    try:
                        self.VManager.item(rowPosition,
                                           j).setFlags(Qt.NoItemFlags
                                                       | Qt.ItemIsEnabled)
                        self.VManager.item(rowPosition, j).setBackground(
                            QColor(211, 211, 211))
                    except Exception:
                        self.VManager.cellWidget(rowPosition, j).setStyleSheet(
                            "background-color:rgb(211,211,211);")
                        pass
                return

            pbar.setValue(30)
            info = FFMpeg().probe(filename)
            if info is None:
                qgsu.showUserAndLogMessage(
                    QCoreApplication.translate("ManagerDock",
                                               "Failed loading FFMPEG ! "))
                return
            info.format.duration
            # init non-blocking metadata buffered reader
            self.meta_reader[str(rowPosition)] = BufferedMetaReader(
                filename, pass_time=self.pass_time)
            qgsu.showUserAndLogMessage(
                "",
                "buffered non-blocking metadata reader initialized.",
                onlyLog=True)

            pbar.setValue(60)
            try:
                # init point we can center the video on
                self.initialPt[str(rowPosition)] = getVideoLocationInfo(
                    filename, islocal, klv_folder)
                if not self.initialPt[str(rowPosition)]:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(
                            QCoreApplication.translate(
                                "ManagerDock",
                                "Start location not available.")))
                    self.ToggleActiveRow(rowPosition, value="Not MISB")
                    pbar.setValue(99)
                    return
                else:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(self.initialPt[str(rowPosition)][2]))
            except Exception:
                qgsu.showUserAndLogMessage(
                    QCoreApplication.translate(
                        "ManagerDock", "This video don't have Metadata ! "))
                pbar.setValue(99)
                self.ToggleActiveRow(rowPosition, value="Not MISB")
                return

            pbar.setValue(90)

            dtm_path = parser['GENERAL']['DTM_file']
            if self.initialPt[str(rowPosition)] and dtm_path != '':
                try:
                    initElevationModel(self.initialPt[str(rowPosition)][0],
                                       self.initialPt[str(rowPosition)][1],
                                       dtm_path)
                    qgsu.showUserAndLogMessage("",
                                               "Elevation model initialized.",
                                               onlyLog=True)
                except Exception:
                    None
        else:
            self.meta_reader[str(rowPosition)] = StreamMetaReader(filename)
            qgsu.showUserAndLogMessage("",
                                       "StreamMetaReader initialized.",
                                       onlyLog=True)
            self.initialPt[str(rowPosition)] = None

        pbar.setValue(100)
        if islocal:
            self.ToggleActiveRow(rowPosition, value="Ready Local")
        else:
            self.ToggleActiveRow(rowPosition, value="Ready")
        # Add video to settings list
        AddVideoToSettings(str(row_id), filename)
예제 #9
0
class Converter(QObject):
    """
    Converter Video Class
    """

    video_codecs = {}
    audio_codecs = {}
    subtitle_codecs = {}
    formats = {}
    ffmpeg = FFMpeg()

    for cls in audio_codec_list:
        name = cls.codec_name
        audio_codecs[name] = cls

    for cls in video_codec_list:
        name = cls.codec_name
        video_codecs[name] = cls

    for cls in subtitle_codec_list:
        name = cls.codec_name
        subtitle_codecs[name] = cls

    for cls in format_list:
        name = cls.format_name
        formats[name] = cls

    def parse_options(self, opt, twopass=None):
        """
        Parse Options
        """
        f = opt["format"]
        if f not in self.formats:
            log.error("Requested unknown format: " + str(f))

        format_options = self.formats[f]().parse_options(opt)
        if format_options is None:
            log.error("Unknown container format error")
        """ audio options"""
        if "audio" not in opt or twopass == 1:
            opt_audio = {"codec": None}
        else:
            opt_audio = opt["audio"]
            if not isinstance(opt_audio, dict) or "codec" not in opt_audio:
                log.error("Invalid audio codec specification")

        c = opt_audio["codec"]
        if c not in self.audio_codecs:
            log.error("Requested unknown audio codec " + str(c))

        audio_options = self.audio_codecs[c]().parse_options(opt_audio)
        if audio_options is None:
            log.error("Unknown audio codec error")
        """ video options"""
        if "video" not in opt:
            opt_video = {"codec": None}
        else:
            opt_video = opt["video"]
            if not isinstance(opt_video, dict) or "codec" not in opt_video:
                log.error("Invalid video codec specification")

        c = opt_video["codec"]
        if c not in self.video_codecs:
            log.error("Requested unknown video codec " + str(c))

        video_options = self.video_codecs[c]().parse_options(opt_video)
        if video_options is None:
            log.error("Unknown video codec error")

        if "subtitle" not in opt:
            opt_subtitle = {"codec": None}
        else:
            opt_subtitle = opt["subtitle"]
            if not isinstance(opt_subtitle,
                              dict) or "codec" not in opt_subtitle:
                log.error("Invalid subtitle codec specification")

        c = opt_subtitle["codec"]
        if c not in self.subtitle_codecs:
            log.error("Requested unknown subtitle codec " + str(c))

        subtitle_options = self.subtitle_codecs[c]().parse_options(
            opt_subtitle)
        if subtitle_options is None:
            log.error("Unknown subtitle codec error")
        """ aggregate all options"""
        optlist = audio_options + video_options + subtitle_options + format_options

        if twopass == 1:
            optlist.extend(["-pass", "1"])
        elif twopass == 2:
            optlist.extend(["-pass", "2"])

        return optlist

    def convert(self, task, infile, outfile, options, twopass):
        """
        Convert Video
        """
        try:
            while not task.isCanceled():
                info = self.ffmpeg.probe(infile)
                if info is None:
                    task.cancel()
                    return "Can't get information about source file"

                if not info.video and not info.audio:
                    task.cancel()
                    return "Source file has no audio or video streams"

                if info.video and "video" in options:
                    options = options.copy()
                    v = options["video"] = options["video"].copy()
                    v["src_width"] = info.video.video_width
                    v["src_height"] = info.video.video_height

                if info.format.duration < 0.01:
                    task.cancel()
                    return "Zero-length media"

                if twopass:
                    optlist1 = self.parse_options(options, 1)
                    for timecode in self.ffmpeg.convert(
                            infile, outfile, optlist1, task):
                        task.setProgress(
                            int((50.0 * timecode) / info.format.duration))

                    optlist2 = self.parse_options(options, 2)
                    for timecode in self.ffmpeg.convert(
                            infile, outfile, optlist2, task):
                        task.setProgress(
                            int(50.0 +
                                (50.0 * timecode) / info.format.duration))
                else:
                    optlist = self.parse_options(options, twopass)
                    for timecode in self.ffmpeg.convert(
                            infile, outfile, optlist, task):
                        task.setProgress(
                            int((100.0 * timecode) / info.format.duration))
                task.setProgress(100)
                return {"task": task.description()}
            if task.isCanceled():
                return None
        except Exception:
            return None

    def probeToJson(self, task, fname, output):
        """
        Task for save video information to Json
        """
        try:
            self.ffmpeg.probeToJson(fname, output)
            if task.isCanceled():
                return None
            return {"task": task.description()}
        except Exception:
            return None

    def probeShow(self, task, fname):
        """
        Task for show video information
        """
        try:
            self.bytes_value = self.ffmpeg.probeGetJson(fname)
            if task.isCanceled():
                return None
            return {"task": task.description()}
        except Exception:
            return None

    def probeInfo(self, fname, posters_as_video=True):
        """
        Extract video information
        """
        try:
            info = self.ffmpeg.probe(fname, posters_as_video)
            return info
        except Exception:
            return None
예제 #10
0
class Converter(QObject):

    video_codecs = {}
    audio_codecs = {}
    subtitle_codecs = {}
    formats = {}

    for cls in audio_codec_list:
        name = cls.codec_name
        audio_codecs[name] = cls

    for cls in video_codec_list:
        name = cls.codec_name
        video_codecs[name] = cls

    for cls in subtitle_codec_list:
        name = cls.codec_name
        subtitle_codecs[name] = cls

    for cls in format_list:
        name = cls.format_name
        formats[name] = cls

    def parse_options(self, opt, twopass=None):

        f = opt['format']
        if f not in self.formats:
            log.error('Requested unknown format: ' + str(f))

        format_options = self.formats[f]().parse_options(opt)
        if format_options is None:
            log.error('Unknown container format error')

        ''' audio options'''
        if 'audio' not in opt or twopass == 1:
            opt_audio = {'codec': None}
        else:
            opt_audio = opt['audio']
            if not isinstance(opt_audio, dict) or 'codec' not in opt_audio:
                log.error('Invalid audio codec specification')

        c = opt_audio['codec']
        if c not in self.audio_codecs:
            log.error('Requested unknown audio codec ' + str(c))

        audio_options = self.audio_codecs[c]().parse_options(opt_audio)
        if audio_options is None:
            log.error('Unknown audio codec error')

        ''' video options'''
        if 'video' not in opt:
            opt_video = {'codec': None}
        else:
            opt_video = opt['video']
            if not isinstance(opt_video, dict) or 'codec' not in opt_video:
                log.error('Invalid video codec specification')

        c = opt_video['codec']
        if c not in self.video_codecs:
            log.error('Requested unknown video codec ' + str(c))

        video_options = self.video_codecs[c]().parse_options(opt_video)
        if video_options is None:
            log.error('Unknown video codec error')

        if 'subtitle' not in opt:
            opt_subtitle = {'codec': None}
        else:
            opt_subtitle = opt['subtitle']
            if not isinstance(opt_subtitle, dict) or 'codec' not in opt_subtitle:
                log.error('Invalid subtitle codec specification')

        c = opt_subtitle['codec']
        if c not in self.subtitle_codecs:
            log.error('Requested unknown subtitle codec ' + str(c))

        subtitle_options = self.subtitle_codecs[c](
        ).parse_options(opt_subtitle)
        if subtitle_options is None:
            log.error('Unknown subtitle codec error')

        ''' aggregate all options'''
        optlist = audio_options + video_options + subtitle_options + format_options

        if twopass == 1:
            optlist.extend(['-pass', '1'])
        elif twopass == 2:
            optlist.extend(['-pass', '2'])

        return optlist

    # TODO : No puede cancelarse?arreglar
    def convert(self, task, infile, outfile, options, twopass):
        while not task.isCanceled():
            timeout = 10

            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(infile)
            if info is None:
                task.cancel()
                return "Can't get information about source file"

            if not info.video and not info.audio:
                task.cancel()
                return 'Source file has no audio or video streams'

            if info.video and 'video' in options:
                options = options.copy()
                v = options['video'] = options['video'].copy()
                v['src_width'] = info.video.video_width
                v['src_height'] = info.video.video_height

            if info.format.duration < 0.01:
                task.cancel()
                return 'Zero-length media'

            if twopass:
                optlist1 = self.parse_options(options, 1)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist1,
                                                    timeout=timeout):
                    task.setProgress(
                        int((50.0 * timecode) / info.format.duration))

                optlist2 = self.parse_options(options, 2)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist2,
                                                    timeout=timeout):
                    task.setProgress(
                        int(50.0 + (50.0 * timecode) / info.format.duration))
            else:
                optlist = self.parse_options(options, twopass)
                for timecode in self.ffmpeg.convert(infile, outfile, optlist,
                                                    timeout=timeout):
                    task.setProgress(
                        int((100.0 * timecode) / info.format.duration))
            task.setProgress(100)
        return {'task': task.description()}
        if task.isCanceled():
            return None

    def probeToJson(self, task, fname, output):
        try:
            self.ffmpeg = FFMpeg()
            self.ffmpeg.probeToJson(fname, output)
            if task.isCanceled():
                return None
            return {'task': task.description()}
        except Exception:
            return None

    def probeShow(self, task, fname):
        try:
            self.ffmpeg = FFMpeg()
            self.bytes_value = self.ffmpeg.probeGetJson(fname)
            if task.isCanceled():
                return None
            return {'task': task.description()}
        except Exception:
            return None

    def probeInfo(self, fname, posters_as_video=True):
        try:
            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(fname, posters_as_video)
            return info
        except Exception:
            return None
예제 #11
0
    def AddFileRowToManager(self,
                            name,
                            filename,
                            load_id=None,
                            islocal=False,
                            klv_folder=None):
        ''' Add file Video to new Row '''
        # We limit the number of videos due to the buffer
        self.loading = True
        if self.VManager.rowCount() > 5:
            qgsu.showUserAndLogMessage(QCoreApplication.translate(
                "ManagerDock",
                "You must delete some video from the list before adding a new one"
            ),
                                       level=QGis.Warning)
            self.loading = False
            return

        self.islocal = islocal
        self.klv_folder = klv_folder
        w = QWidget()
        layout = QVBoxLayout()
        pbar = QProgressBar()
        layout.addWidget(pbar)
        w.setLayout(layout)
        rowPosition = self.VManager.rowCount()
        self.videoPlayable.append(False)

        pbar.setGeometry(0, 0, 300, 30)
        pbar.setValue(0)
        pbar.setMaximumHeight(30)

        if load_id is None:
            row_id = 0
            if rowPosition != 0:
                row_id = int(self.VManager.item(rowPosition - 1, 0).text()) + 1
        else:
            row_id = load_id

        self.VManager.insertRow(rowPosition)

        self.VManager.setItem(rowPosition, 0, QTableWidgetItem(str(row_id)))

        self.VManager.setItem(rowPosition, 1, QTableWidgetItem(name))
        self.VManager.setItem(
            rowPosition, 2,
            QTableWidgetItem(
                QCoreApplication.translate("ManagerDock", "Loading")))
        self.VManager.setItem(rowPosition, 3, QTableWidgetItem(filename))
        self.VManager.setItem(rowPosition, 4, QTableWidgetItem("-"))
        self.VManager.setCellWidget(rowPosition, 5, w)

        self.VManager.setVisible(False)
        self.VManager.horizontalHeader().setStretchLastSection(True)
        self.VManager.setVisible(True)

        # resolve if it is a stream
        if "://" in filename:
            self.videoIsStreaming.append(True)
        else:
            self.videoIsStreaming.append(False)

        if not self.videoIsStreaming[-1]:
            # Disable row if not exist video file
            if not os.path.exists(filename):
                self.ToggleActiveRow(rowPosition, value="Missing source file")
                for j in range(self.VManager.columnCount()):
                    try:
                        self.VManager.item(rowPosition,
                                           j).setFlags(Qt.NoItemFlags
                                                       | Qt.ItemIsEnabled)
                        self.VManager.item(rowPosition, j).setBackground(
                            QColor(211, 211, 211))
                    except Exception:
                        self.VManager.cellWidget(rowPosition, j).setStyleSheet(
                            "background-color:rgb(211,211,211);")
                        pass
                self.loading = False
                return

            pbar.setValue(30)
            info = FFMpeg().probe(filename)
            if info is None:
                qgsu.showUserAndLogMessage(
                    QCoreApplication.translate("ManagerDock",
                                               "Failed loading FFMPEG ! "))

            klvIdx = getKlvStreamIndex(filename, islocal)

            # init non-blocking metadata buffered reader
            self.meta_reader.append(
                BufferedMetaReader(filename,
                                   klv_index=klvIdx,
                                   pass_time=self.pass_time,
                                   interval=self.buf_interval))

            pbar.setValue(60)
            try:
                # init point we can center the video on
                self.initialPt.append(
                    getVideoLocationInfo(filename, islocal, klv_folder))
                if not self.initialPt[rowPosition]:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(
                            QCoreApplication.translate(
                                "ManagerDock",
                                "Start location not available.")))
                    self.ToggleActiveRow(rowPosition,
                                         value="Video not applicable")
                    pbar.setValue(100)

                else:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(self.initialPt[rowPosition][2]))
                    pbar.setValue(90)
                    self.videoPlayable[rowPosition] = True
            except Exception:
                qgsu.showUserAndLogMessage(
                    QCoreApplication.translate(
                        "ManagerDock", "This video doesn't have Metadata ! "))
                pbar.setValue(100)
                self.ToggleActiveRow(rowPosition, value="Video not applicable")

        else:
            self.meta_reader.append(StreamMetaReader(filename))
            qgsu.showUserAndLogMessage("",
                                       "StreamMetaReader initialized.",
                                       onlyLog=True)
            self.initialPt.append(None)
            self.videoPlayable[rowPosition] = True

        url = ""
        if self.videoIsStreaming[-1]:
            # show video from splitter (port +1)
            oldPort = filename.split(":")[2]
            newPort = str(int(oldPort) + 10)
            proto = filename.split(":")[0]
            url = QUrl(proto + "://127.0.0.1:" + newPort)
        else:
            url = QUrl.fromLocalFile(filename)

        self.playlist.addMedia(QMediaContent(url))

        if self.videoPlayable[rowPosition]:
            pbar.setValue(100)
            if islocal:
                self.ToggleActiveRow(rowPosition, value="Ready Local")
            else:
                self.ToggleActiveRow(rowPosition, value="Ready")
            # Add video to settings list
            AddVideoToSettings(str(row_id), filename)

        self.loading = False
예제 #12
0
    def AddFileRowToManager(self, name, filename):
        ''' Add file Video to new Row '''
        w = QWidget()
        layout = QVBoxLayout()
        pbar = QProgressBar()
        layout.addWidget(pbar)
        w.setLayout(layout)
        rowPosition = self.VManager.rowCount()

        self.VManager.insertRow(rowPosition)
        self.VManager.setItem(rowPosition, 0,
                              QTableWidgetItem(str(rowPosition)))
        self.VManager.setItem(rowPosition, 1, QTableWidgetItem(name))
        self.VManager.setItem(
            rowPosition, 2,
            QTableWidgetItem(
                QCoreApplication.translate("ManagerDock", "Loading")))
        self.VManager.setItem(rowPosition, 3, QTableWidgetItem(filename))
        self.VManager.setItem(rowPosition, 4, QTableWidgetItem("-"))
        self.VManager.setCellWidget(rowPosition, 5, w)

        self.VManager.setVisible(False)
        self.VManager.horizontalHeader().setStretchLastSection(True)

        pbar.setGeometry(0, 0, 300, 30)
        pbar.setValue(30)
        pbar.setMaximumHeight(30)
        self.pBars[str(rowPosition)] = pbar
        self.VManager.setVisible(True)

        if not self.isStreaming:
            info = FFMpeg().probe(filename)
            info.format.duration
            # init non-blocking metadata buffered reader
            self.meta_reader[str(rowPosition)] = BufferedMetaReader(
                filename,
                pass_time=self.pass_time,
                intervall=self.buffer_intervall,
                min_buffer_size=self.min_buffer_size)
            qgsu.showUserAndLogMessage(
                "",
                "buffered non-blocking metadata reader initialized.",
                onlyLog=True)

            pbar.setValue(60)

            try:
                # init point we can center the video on
                self.initialPt[str(rowPosition)] = getVideoLocationInfo(
                    filename)
                if not self.initialPt[str(rowPosition)]:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(
                            QCoreApplication.translate(
                                "ManagerDock",
                                "Start location not available!")))
                    self.ToggleActiveRow(rowPosition, value="Not MISB")
                    pbar.setValue(0)
                    return
                else:
                    self.VManager.setItem(
                        rowPosition, 4,
                        QTableWidgetItem(self.initialPt[str(rowPosition)][2]))
            except Exception:
                qgsu.showUserAndLogMessage(
                    QCoreApplication.translate(
                        "ManagerDock", "This video don't have Metadata ! "))
                pbar.setValue(0)
                self.ToggleActiveRow(rowPosition, value="Not MISB")
                return

            pbar.setValue(90)

            if self.initialPt[str(rowPosition)] and dtm_path != '':
                initElevationModel(self.initialPt[str(rowPosition)][0],
                                   self.initialPt[str(rowPosition)][1],
                                   dtm_path)
                qgsu.showUserAndLogMessage("",
                                           "Elevation model initialized.",
                                           onlyLog=True)
        else:
            self.meta_reader[str(rowPosition)] = None
            self.initialPt[str(rowPosition)] = None

        pbar.setValue(100)
        self.ToggleActiveRow(rowPosition, value="Ready")
예제 #13
0
class Converter(QObject):

    finished = pyqtSignal(str, str)
    finishedJson = pyqtSignal(str, str, bytes)
    error = pyqtSignal(str, Exception, basestring)
    progress = pyqtSignal(float)

    video_codecs = {}
    audio_codecs = {}
    subtitle_codecs = {}
    formats = {}

    for cls in audio_codec_list:
        name = cls.codec_name
        audio_codecs[name] = cls

    for cls in video_codec_list:
        name = cls.codec_name
        video_codecs[name] = cls

    for cls in subtitle_codec_list:
        name = cls.codec_name
        subtitle_codecs[name] = cls

    for cls in format_list:
        name = cls.format_name
        formats[name] = cls

    def parse_options(self, opt, twopass=None):

        f = opt['format']
        if f not in self.formats:
            log.error('Requested unknown format: ' + str(f))

        format_options = self.formats[f]().parse_options(opt)
        if format_options is None:
            log.error('Unknown container format error')
        ''' audio options'''
        if 'audio' not in opt or twopass == 1:
            opt_audio = {'codec': None}
        else:
            opt_audio = opt['audio']
            if not isinstance(opt_audio, dict) or 'codec' not in opt_audio:
                log.error('Invalid audio codec specification')

        c = opt_audio['codec']
        if c not in self.audio_codecs:
            log.error('Requested unknown audio codec ' + str(c))

        audio_options = self.audio_codecs[c]().parse_options(opt_audio)
        if audio_options is None:
            log.error('Unknown audio codec error')
        ''' video options'''
        if 'video' not in opt:
            opt_video = {'codec': None}
        else:
            opt_video = opt['video']
            if not isinstance(opt_video, dict) or 'codec' not in opt_video:
                log.error('Invalid video codec specification')

        c = opt_video['codec']
        if c not in self.video_codecs:
            log.error('Requested unknown video codec ' + str(c))

        video_options = self.video_codecs[c]().parse_options(opt_video)
        if video_options is None:
            log.error('Unknown video codec error')

        if 'subtitle' not in opt:
            opt_subtitle = {'codec': None}
        else:
            opt_subtitle = opt['subtitle']
            if not isinstance(opt_subtitle,
                              dict) or 'codec' not in opt_subtitle:
                log.error('Invalid subtitle codec specification')

        c = opt_subtitle['codec']
        if c not in self.subtitle_codecs:
            log.error('Requested unknown subtitle codec ' + str(c))

        subtitle_options = self.subtitle_codecs[c]().parse_options(
            opt_subtitle)
        if subtitle_options is None:
            log.error('Unknown subtitle codec error')
        ''' aggregate all options'''
        optlist = audio_options + video_options + subtitle_options + format_options

        if twopass == 1:
            optlist.extend(['-pass', '1'])
        elif twopass == 2:
            optlist.extend(['-pass', '2'])

        return optlist

    @pyqtSlot(str, str, dict, bool)
    def convert(self, infile, outfile, options, twopass):
        try:
            timeout = 10

            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(infile)
            if info is None:
                self.error.emit("convert", "",
                                "Can't get information about source file")

            if not info.video and not info.audio:
                self.error.emit("convert", "",
                                'Source file has no audio or video streams')

            if info.video and 'video' in options:
                options = options.copy()
                v = options['video'] = options['video'].copy()
                v['src_width'] = info.video.video_width
                v['src_height'] = info.video.video_height

            if info.format.duration < 0.01:
                self.error.emit("convert", "", 'Zero-length media')

            if twopass:
                optlist1 = self.parse_options(options, 1)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist1,
                                                    timeout=timeout):
                    self.progress.emit(
                        int((50.0 * timecode) / info.format.duration))

                optlist2 = self.parse_options(options, 2)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist2,
                                                    timeout=timeout):
                    self.progress.emit(
                        int(50.0 + (50.0 * timecode) / info.format.duration))
            else:
                optlist = self.parse_options(options, twopass)
                for timecode in self.ffmpeg.convert(infile,
                                                    outfile,
                                                    optlist,
                                                    timeout=timeout):
                    self.progress.emit(
                        int((100.0 * timecode) / info.format.duration))
            self.progress.emit(100)
            self.finished.emit("convert", "convert correct Finished!")
        except Exception as e:
            self.error.emit("convert", e, traceback.format_exc())
            return

    @pyqtSlot(str, str)
    def probeToJson(self, fname, output=None):
        try:
            self.ffmpeg = FFMpeg()
            self.ffmpeg.probeToJson(fname, output)
            self.finished.emit("probeToJson",
                               "Extract Information To Json succesfully!")
        except Exception as e:
            self.error.emit("probeToJson", e, traceback.format_exc())
            return

    @pyqtSlot(str)
    def probeShow(self, fname):
        try:
            self.ffmpeg = FFMpeg()
            bytes_value = self.ffmpeg.probeGetJson(fname)
            self.finishedJson.emit("probeShow",
                                   "Extract Information succesfully!",
                                   bytes_value)
        except Exception as e:
            self.error.emit("probeShow", e, traceback.format_exc())
            return

    def probeInfo(self, fname, posters_as_video=True):
        try:
            self.ffmpeg = FFMpeg()
            info = self.ffmpeg.probe(fname, posters_as_video)
            return info
        except Exception as e:
            return None