fix: fix inject operator...

This commit is contained in:
acgnhik 2022-06-02 10:59:49 +08:00
parent a5cd17c050
commit 7e4f0620a2
4 changed files with 19 additions and 7 deletions

View File

@ -32,7 +32,7 @@ class MetadataDumper(SwitchableMixin):
def _do_enable(self) -> None:
self._metadata_subscription = self._analyser.metadatas.subscribe(
self._update_metadata
on_next=self._update_metadata, on_error=self._reset_metadata
)
self._join_points_subscription = (
self._joinpoint_extractor.join_points.subscribe(self._update_join_points)
@ -54,6 +54,9 @@ class MetadataDumper(SwitchableMixin):
def _update_metadata(self, metadata: flv_ops.MetaData) -> None:
self._last_metadata = metadata
def _reset_metadata(self, exc: Exception) -> None:
self._last_metadata = None
def _update_join_points(self, join_points: List[flv_ops.JoinPoint]) -> None:
self._last_join_points = join_points

View File

@ -178,9 +178,13 @@ class Analyser:
)
def make_metadata(self) -> MetaData:
assert self._has_audio == self._audio_analysed
assert self._has_video and self._video_analysed
assert self._resolution is not None
assert self._has_audio == self._audio_analysed, (
f'has_audio: {self._has_audio}, audio_analysed: {self._audio_analysed}',
)
assert self._has_video and self._video_analysed, (
f'has_video: {self._has_video}, video_analysed: {self._video_analysed}',
)
assert self._resolution is not None, 'no resolution'
if not self._has_audio:
audiosize = None
@ -241,7 +245,7 @@ class Analyser:
metadata = self.make_metadata()
except Exception as e:
logger.warning(f'Failed to make metadata: {repr(e)}')
pass
self._metadatas.on_error(e)
else:
self._metadatas.on_next(metadata)
@ -302,6 +306,7 @@ class Analyser:
self._audio_sample_rate = tag.sound_rate.value
self._audio_sample_size = tag.sound_size.value
self._stereo = tag.sound_type == SoundType.STEREO
logger.debug(f'Audio analysed: {tag}')
self._num_of_audio_tags += 1
self._size_of_audio_tags += tag.tag_size
@ -314,6 +319,7 @@ class Analyser:
self._keyframe_filepositions.append(self.calc_file_size())
if tag.is_avc_header():
self._resolution = Resolution.from_aac_sequence_header(tag)
logger.debug(f'Resolution: {self._resolution}')
else:
pass
@ -321,6 +327,7 @@ class Analyser:
self._has_video = True
self._video_analysed = True
self._video_codec_id = tag.codec_id.value
logger.debug(f'Video analysed: {tag}')
self._num_of_video_tags += 1
self._size_of_video_tags += tag.tag_size

View File

@ -52,9 +52,9 @@ class Injector:
logger.debug('Injected metadata into the metadata tag')
else:
logger.debug('No metadata tag in the stream')
tag = self._make_metadata_tag()
metadata_tag = self._make_metadata_tag()
logger.debug('Maked a metadata tag for metadata injection')
observer.on_next(tag)
observer.on_next(metadata_tag)
logger.debug('Inserted the artificial metadata tag')
observer.on_next(tag)

View File

@ -133,8 +133,10 @@ class Postprocessor(
self._postprocessing_progress = None
video_path = await self._queue.get()
logger.debug(f'Postprocessing... {video_path}')
if not await self._is_vaild_flv_file(video_path):
logger.warning(f'Invalid flv file: {video_path}')
self._queue.task_done()
continue