def _load_audio_source(log_api: LogApi, uid: uuid.UUID, path: Path) -> Optional[ffms2.AudioSource]: """Create FFMS audio source. :param log_api: logging API :param uid: uid of the stream (for logging) :param path: path to the audio file :return: resulting FFMS audio source or None if failed to create """ log_api.info(f"audio {uid} started loading ({path})") if not path.exists(): log_api.error(f"error loading audio {uid} (file {path} not found)") return None try: indexer = ffms2.Indexer(str(path)) for track in indexer.track_info_list: indexer.track_index_settings(track.num, 1, 0) index = indexer.do_indexing2() except ffms2.Error as ex: log_api.error(f"error loading audio {uid} ({ex})") return None try: track_number = index.get_first_indexed_track_of_type( ffms2.FFMS_TYPE_AUDIO) source = ffms2.AudioSource(str(path), track_number, index) except ffms2.Error as ex: log_api.error(f"error loading audio {uid} ({ex})") return None else: log_api.info(f"audio {uid} finished loading") return source
def _load_video_source(log_api: LogApi, uid: uuid.UUID, path: Path) -> T.Optional[ffms2.VideoSource]: """Create video source. :param log_api: logging API :param uid: uid of the stream (for logging) :param path: path to the video file :return: input path and resulting video source """ log_api.info(f"video {uid} started loading ({path})") if not path.exists(): log_api.error(f"error loading video {uid} (file {path} not found)") return None try: source = ffms2.VideoSource(str(path)) except ffms2.Error as ex: log_api.error(f"error loading video {uid} ({ex})") return None else: log_api.info(f"video {uid} finished loading") return source