    def loadvideo_decord(self, sample, sample_rate_scale=1, chunk_nb=0):
        """Load video content using Decord"""
        fname = sample
        fname = os.path.join(self.prefix, fname)

        try:
            if self.keep_aspect_ratio:
                if "s3://" in fname:
                    video_bytes = self.client.get(fname)
                    vr = VideoReader(io.BytesIO(video_bytes),
                                     num_threads=1,
                                     ctx=cpu(0))
                else:
                    vr = VideoReader(fname, num_threads=1, ctx=cpu(0))
            else:
                if "s3://" in fname:
                    video_bytes = self.client.get(fname)
                    vr = VideoReader(io.BytesIO(video_bytes),
                                     width=self.new_width,
                                     height=self.new_height,
                                     num_threads=1,
                                     ctx=cpu(0))
                else:
                    vr = VideoReader(fname, width=self.new_width, height=self.new_height,
                                    num_threads=1, ctx=cpu(0))

            # handle temporal segments
            converted_len = int(self.clip_len * self.frame_sample_rate)
            seg_len = len(vr) // self.num_segment

            if self.mode == 'test':
                temporal_step = max(1.0 * (len(vr) - converted_len) / (self.test_num_segment - 1), 0)
                temporal_start = int(chunk_nb * temporal_step)

                bound = min(temporal_start + converted_len, len(vr))
                all_index = [x for x in range(temporal_start, bound, self.frame_sample_rate)]
                while len(all_index) < self.clip_len:
                    all_index.append(all_index[-1])
                vr.seek(0)
                buffer = vr.get_batch(all_index).asnumpy()
                return buffer

            all_index = []
            for i in range(self.num_segment):
                if seg_len <= converted_len:
                    index = np.linspace(0, seg_len, num=seg_len // self.frame_sample_rate)
                    index = np.concatenate((index, np.ones(self.clip_len - seg_len // self.frame_sample_rate) * seg_len))
                    index = np.clip(index, 0, seg_len - 1).astype(np.int64)
                else:
                    if self.mode == 'validation':
                        end_idx = (seg_len - converted_len) // 2
                    else:
                        end_idx = np.random.randint(converted_len, seg_len)
                    str_idx = end_idx - converted_len
                    index = np.linspace(str_idx, end_idx, num=self.clip_len)
                    index = np.clip(index, str_idx, end_idx - 1).astype(np.int64)
                index = index + i*seg_len
                all_index.extend(list(index))

            all_index = all_index[::int(sample_rate_scale)]
            vr.seek(0)
            buffer = vr.get_batch(all_index).asnumpy()
            return buffer
        except:
            print("video cannot be loaded by decord: ", fname)
            return []
Load video content using Decord
videomamba/video_sm/datasets/kinetics.py