Skip to content

Commit

Permalink
Merge pull request #522 from voxel51/draw-clips
Browse files Browse the repository at this point in the history
Adding support for drawing annotated clips
  • Loading branch information
brimoor authored Sep 9, 2021
2 parents 62449d3 + e90a06b commit 031b183
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions eta/core/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import eta.constants as etac
from eta.core.config import Config, Configurable
import eta.core.data as etad
import eta.core.frameutils as etaf
import eta.core.image as etai
import eta.core.logo as etal
import eta.core.utils as etau
Expand Down Expand Up @@ -698,7 +699,7 @@ def __exit__(self, *args):


def annotate_video(
input_path, video_labels, output_path, annotation_config=None
input_path, video_labels, output_path, support=None, annotation_config=None
):
"""Annotates the video with the given labels.
Expand All @@ -707,6 +708,8 @@ def annotate_video(
video_labels: an `eta.core.video.VideoLabels` instance describing the
content to annotate
output_path: the path to write the output video
support: an optional `[first, last]` range of frames to render. By
default, the entire video is annotated
annotation_config: an optional AnnotationConfig specifying how to
render the annotations. If omitted, the default config is used
"""
Expand All @@ -717,8 +720,15 @@ def annotate_video(
video_labels = video_labels.render_framewise()
mask_index = video_labels.mask_index

if support is not None:
frames = etaf.FrameRange(*support)
else:
frames = None

# Annotate video
with etav.VideoProcessor(input_path, out_video_path=output_path) as vp:
with etav.VideoProcessor(
input_path, frames=frames, out_video_path=output_path
) as vp:
# Set media size
annotation_config.set_media_size(frame_size=vp.output_frame_size)

Expand Down
4 changes: 2 additions & 2 deletions eta/core/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@ def extract_frame(video_path, output_path, start_time=None):


def _make_ffmpeg_select_arg(frames):
ss = "+".join(["eq(n\,%d)" % (f - 1) for f in frames])
ss = "+".join(["eq(n\\,%d)" % (f - 1) for f in frames])
return "select='%s'" % ss


Expand Down Expand Up @@ -3897,7 +3897,7 @@ def write(self, img):
Args:
img: a numpy array
"""
self._ffmpeg.stream(img.tostring())
self._ffmpeg.stream(img.tobytes())

def close(self):
"""Closes the FFmpegVideoWriter."""
Expand Down

0 comments on commit 031b183

Please sign in to comment.