def iterate_frames(
        self,
        *,
        frame_filter: Union[bool, Iterable[int]] = True,
        video_stream: Optional[av.video.stream.VideoStream] = None,
    ) -> Iterator[tuple[av.VideoFrame, str, int]]:
        """
        If provided, frame_filter must be an ordered sequence in the ascending order.
        'True' means using the frames configured in the reader object.
        'False' or 'None' means returning all the video frames.
        """

        if frame_filter is True:
            frame_filter = itertools.count(self._start, self._step)
            if self._stop:
                frame_filter = itertools.takewhile(lambda x: x <= self._stop, frame_filter)
        elif not frame_filter:
            frame_filter = itertools.count()

        frame_filter_iter = iter(frame_filter)
        next_frame_filter_frame = next(frame_filter_iter, None)
        if next_frame_filter_frame is None:
            return

        es = ExitStack()

        needs_init = video_stream is None
        if needs_init:
            container = es.enter_context(self._read_av_container())
        else:
            container = video_stream.container

        with es:
            if needs_init:
                video_stream = container.streams.video[0]

                if self.allow_threading:
                    video_stream.thread_type = 'AUTO'
                else:
                    video_stream.thread_type = 'NONE'

            frame_counter = itertools.count()
            with closing(self._decode_stream(container, video_stream)) as stream_decoder:
                for frame, frame_number in zip(stream_decoder, frame_counter):
                    if frame_number == next_frame_filter_frame:
                        if video_stream.metadata.get('rotate'):
                            pts = frame.pts
                            frame = av.VideoFrame().from_ndarray(
                                rotate_image(
                                    frame.to_ndarray(format='bgr24'),
                                    360 - int(video_stream.metadata.get('rotate'))
                                ),
                                format ='bgr24'
                            )
                            frame.pts = pts

                        if self._frame_size is None:
                            self._frame_size = (frame.width, frame.height)

                        yield (frame, self._source_path[0], frame.pts)

                        next_frame_filter_frame = next(frame_filter_iter, None)

                    if next_frame_filter_frame is None:
                        return

        If provided, frame_filter must be an ordered sequence in the ascending order.
        'True' means using the frames configured in the reader object.
        'False' or 'None' means returning all the video frames.
        
cvat/apps/engine/media_extractors.py