MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / decode

Function decode

slowfast/datasets/decoder.py:327–446  ·  view source on GitHub ↗

Decode the video and perform temporal sampling. Args: container (container): pyav container. sampling_rate (int): frame sampling rate (interval between two sampled frames). num_frames (int): number of frames to sample. clip_idx (int): if clip_idx

(
    container,
    sampling_rate,
    num_frames,
    clip_idx=-1,
    num_clips=10,
    video_meta=None,
    target_fps=30,
    backend="pyav",
    max_spatial_scale=0,
    use_offset=False,
    sparse=False,
    total_frames=None,
    start_index=0
)

Source from the content-addressed store, hash-verified

325
326
327def decode(
328 container,
329 sampling_rate,
330 num_frames,
331 clip_idx=-1,
332 num_clips=10,
333 video_meta=None,
334 target_fps=30,
335 backend="pyav",
336 max_spatial_scale=0,
337 use_offset=False,
338 sparse=False,
339 total_frames=None,
340 start_index=0
341):
342 """
343 Decode the video and perform temporal sampling.
344 Args:
345 container (container): pyav container.
346 sampling_rate (int): frame sampling rate (interval between two sampled
347 frames).
348 num_frames (int): number of frames to sample.
349 clip_idx (int): if clip_idx is -1, perform random temporal
350 sampling. If clip_idx is larger than -1, uniformly split the
351 video to num_clips clips, and select the
352 clip_idx-th video clip.
353 num_clips (int): overall number of clips to uniformly
354 sample from the given video.
355 video_meta (dict): a dict contains VideoMetaData. Details can be find
356 at `pytorch/vision/torchvision/io/_video_opt.py`.
357 target_fps (int): the input video may have different fps, convert it to
358 the target video fps before frame sampling.
359 backend (str): decoding backend includes `pyav` and `torchvision`. The
360 default one is `pyav`.
361 max_spatial_scale (int): keep the aspect ratio and resize the frame so
362 that shorter edge size is max_spatial_scale. Only used in
363 `torchvision` backend.
364 Returns:
365 frames (tensor): decoded frames from the video.
366 """
367 # Currently support two decoders: 1) PyAV, and 2) TorchVision.
368 assert clip_idx >= -1, "Not valied clip_idx {}".format(clip_idx)
369 try:
370 if backend == "pyav":
371 frames, fps, decode_all_video = pyav_decode(
372 container,
373 sampling_rate,
374 num_frames,
375 clip_idx,
376 num_clips,
377 target_fps,
378 use_offset=use_offset,
379 )
380 elif backend == "torchvision":
381 frames, fps, decode_all_video = torchvision_decode(
382 container,
383 sampling_rate,
384 num_frames,

Callers

nothing calls this directly

Calls 5

pyav_decodeFunction · 0.85
torchvision_decodeFunction · 0.85
get_start_end_idxFunction · 0.85
temporal_samplingFunction · 0.85
get_seq_framesFunction · 0.85

Tested by

no test coverage detected