Skip to content

Commit

Permalink
#604 write video files in chunks based on EOS when CHUNK_SIZE=0 (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomskikh authored Jan 12, 2024
1 parent b13a4f7 commit 62f8a11
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
10 changes: 2 additions & 8 deletions adapters/gst/gst_plugins/python/video_files_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ def _open(self):

filesink: Gst.Element = sink.get_by_name(filesink_name)
os.makedirs(self.base_location, exist_ok=True)
if self.chunk_size > 0:
dst_location = os.path.join(self.base_location, f'{self.chunk_idx:04}.mov')
else:
dst_location = os.path.join(self.base_location, f'video.mov')
dst_location = os.path.join(self.base_location, f'{self.chunk_idx:04}.mov')
self.logger.info(
'Writing video from source %s to file %s', self.source_id, dst_location
)
Expand Down Expand Up @@ -314,10 +311,7 @@ def handle_video_frame(
writer = self.writers.get(frame.source_id)
if writer is None:
base_location = os.path.join(self.location, frame.source_id)
if self.chunk_size > 0:
json_filename_pattern = f'{Patterns.CHUNK_IDX}.json'
else:
json_filename_pattern = 'meta.json'
json_filename_pattern = f'{Patterns.CHUNK_IDX}.json'
video_writer = VideoFilesWriter(
base_location,
frame.source_id,
Expand Down
7 changes: 1 addition & 6 deletions adapters/python/sinks/metadata_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ def _close(self):
self.file.close()

def _open(self):
if self.chunk_size > 0:
self.location = self.pattern.replace(
Patterns.CHUNK_IDX, f'{self.chunk_idx:04}'
)
else:
self.location = self.pattern
self.location = self.pattern.replace(Patterns.CHUNK_IDX, f'{self.chunk_idx:04}')
self.lines = 0
self.logger.info('Opening file %s', self.location)
os.makedirs(os.path.dirname(self.location), exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/savant_101/10_adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ The video file sink adapter extends the JSON metadata adapter by writing video f
**Parameters**:

- ``DIR_LOCATION``: a location to write files to; can be a regular path or a path template; supported substitution parameters are ``%source_id`` and ``%src_filename``;
- ``CHUNK_SIZE``: a chunk size in a number of frames; the stream is split into chunks and is written to separate folders with consecutive numbering; default is ``10000``; A value of ``0`` disables chunking, resulting in a continuous stream of frames by ``source_id``;
- ``CHUNK_SIZE``: a chunk size in a number of frames; the stream is split into chunks and is written to separate folders with consecutive numbering; default is ``10000``; A value of ``0`` disables limit for number of frames in a chunk: the stream will be split into chunks only by EOS messages;
- ``SKIP_FRAMES_WITHOUT_OBJECTS``: a flag indicating whether frames without objects are ignored in output; the default value is ``False``;
- ``SOURCE_ID``: an optional filter to filter out frames with a specific ``source_id`` only;
- ``SOURCE_ID_PREFIX`` an optional filter to filter out frames with a matching ``source_id`` prefix only.
Expand Down

0 comments on commit 62f8a11

Please sign in to comment.