Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoStream.rate and VideoStream.framerate no longer available #1005

Closed
6 tasks
uvjustin opened this issue Jul 6, 2022 · 0 comments
Closed
6 tasks

VideoStream.rate and VideoStream.framerate no longer available #1005

uvjustin opened this issue Jul 6, 2022 · 0 comments
Labels

Comments

@uvjustin
Copy link
Contributor

uvjustin commented Jul 6, 2022

Overview

After #910 was merged, VideoStream.rate and VideoStream.framerate are no longer populated from an InputContainer.

Expected behavior

These fields should be populated.

Investigation

Using the below test_streams.py file (augment the current test_streams.py with 2 additional lines), the test case now fails. Pre #910 it succeeded.

import av

from .common import TestCase, fate_suite


class TestStreams(TestCase):
    def test_stream_tuples(self):

        for fate_name in ("h264/interlaced_crop.mp4",):

            container = av.open(fate_suite(fate_name))

            video_streams = tuple([s for s in container.streams if s.type == "video"])
            self.assertEqual(video_streams, container.streams.video)

            audio_streams = tuple([s for s in container.streams if s.type == "audio"])
            self.assertEqual(audio_streams, container.streams.audio)

    def test_selection(self):

        container = av.open(fate_suite("h264/interlaced_crop.mp4"))
        video = container.streams.video[0]
        # audio_stream = container.streams.audio[0]
        # audio_streams = list(container.streams.audio[0:2])

        self.assertEqual([video], container.streams.get(video=0))
        self.assertEqual([video], container.streams.get(video=(0,)))
        self.assertIsNotNone(video.rate)
        self.assertIsNotNone(video.framerate)

        # TODO: Find something in the fate suite with video, audio, and subtitles.

Actual behavior

fails

Research

I have done the following:

Additional context

This is because the InputContainer's cinit was changed to initialize a separate AVCodecContext, and the parameters are copied over from the stream's AVCodecParameters using lib.avcodec_parameters_to_context(). However, AVCodecParameters does not include a video framerate, so the AVCodecContext never has the framerate field initialized for video streams. Note that AudioStream does not have this issue as the sample_rate field gets copied properly.
As mentioned on #910, we can either solve this by:

  1. Copying the stream's avg_frame_rate into codec_context's framerate during InputContainer cinit, continuing to rely on passthrough into the codec_context when the properties are acccessed, or
  2. Adding the rate/framerate properties directly to VideoStream (pointing them to the AVStream's avg_frame_rate).
    There's a broader architectural theme here - continue relying on passthrough attribute access or not?
@uvjustin uvjustin added the bug label Jul 6, 2022
jlaine added a commit to uvjustin/PyAV that referenced this issue Oct 17, 2022
…#1005)

These properties are only set for codecs that store the frame rate value
in the bitstream. To obtain an estimated frame rate, it is better to use
`VideoStream.average_rate`.

See: https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html#a4d08b297e97eefd66c714df4fff493c8

Co-authored-by: Jeremy Lainé <jeremy.laine@m4x.org>
jlaine added a commit to uvjustin/PyAV that referenced this issue Oct 17, 2022
…#1005)

These properties are only set for codecs that store the frame rate value
in the bitstream. To obtain an estimated frame rate, it is better to use
`VideoStream.average_rate`.

See: https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html#a4d08b297e97eefd66c714df4fff493c8

Co-authored-by: Jeremy Lainé <jeremy.laine@m4x.org>
jlaine added a commit to uvjustin/PyAV that referenced this issue Oct 17, 2022
…#1005)

These properties are only set for codecs that store the frame rate value
in the bitstream. To obtain an estimated frame rate, it is better to use
`VideoStream.average_rate`.

See: https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html#a4d08b297e97eefd66c714df4fff493c8

Co-authored-by: Jeremy Lainé <jeremy.laine@m4x.org>
@jlaine jlaine closed this as completed in 71afd21 Oct 17, 2022
@tyler-rt tyler-rt mentioned this issue May 30, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant