-
Notifications
You must be signed in to change notification settings - Fork 417
Add support for FFmpeg 5.0 #910
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
Conversation
f1e581e to
71478e3
Compare
71478e3 to
a611f51
Compare
|
@mikeboers This is progressing better than I thought. One interesting aspect is that we now hit the exact same failures as the ones encountered against FFmpeg 4.4. |
a611f51 to
7c6375a
Compare
0673d00 to
5c954d8
Compare
|
@jlaine Using a separate |
| to_avrational(rate or 24, &codec_context.framerate) | ||
|
|
||
| stream.avg_frame_rate = codec_context.framerate | ||
| stream.time_base = codec_context.time_base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this was in the existing code, but is codec_context.time_base ever set before here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think time_base gets initialized to a sane value, but it would be worth double checking. I really appreciate you looking at this PR, feel free to tinker and suggest changes as I'm not 100% sure of what I'm doing! When in doubt I look at how FFmpeg (CLI) does it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will also tinker with it a bit when I get a chance. It doesn't seem too far off. I think some of the failing tests may actually be the result of existing mismatches between PyAV and ffmpeg. It's hard to get everything to align fully as some of the fields like framerate can get set by ffmpeg in a number of different places depending on the container/codec used.
|
NOTE: I noticed there is an issue in I've probably also introduced a memory leak, I need to free the AVCodecContext. EDIT: no I did not, as the |
5c954d8 to
6b1295f
Compare
|
For the subtitles test failing on 5.0, I think we can just change the test to also accept the regular ASS format without the "Dialogue: " prefix and the two timestamps (basically just allow what it's failing on now). |
No I don't think that's the issue. I've tried changing the format, which does strip away the timings from the output. However I think it masks the underlying issue which is that the timings look plain wrong. |
|
The current ASS format doesn't include the timings in the output though. Are you checking them in pts is in lib.AV_TIME_BASE and start/end display times are in ms, we have: |
ae1619c to
5eaa500
Compare
OK you're exactly right, so I have reworked the tests as suggested to explicitly check timings. I've also made "ass" format the default instead of "ass_with_timings" to get consistent behaviour across FFmpeg versions. That leaves the other failures related to rates. |
557cc2b to
6c70bf7
Compare
6c70bf7 to
5695e7e
Compare
23fd0dc to
e075808
Compare
53d8da3 to
428e50f
Compare
|
@jlaine This looks pretty good and the tests seem to be passing. |
|
I had put off merging this to see if any bug-fixes needed to land in the 9.x branch, as it will be the last one supporting FFmpeg < 4.3. It looks as though we're in a good place, so we're close to the point where this PR should land. One thing that bothers me is that we're hardly testing anything at all on Windows (i.e. only FFmpeg 4.3). Conda seems to have dropped the ball on packaging FFmpeg for Windows.. |
|
Maybe we can try to use the Windows binaries from https://github.com/BtbN/FFmpeg-Builds/releases instead of from Conda? |
uvjustin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. I left some comments with a few things I noticed when getting a stopgap release ready on the ha-av fork.
| if codec: | ||
| # allocate and initialise decoder | ||
| codec_context = lib.avcodec_alloc_context3(codec) | ||
| err_check(lib.avcodec_parameters_to_context(codec_context, stream.codecpar)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avcodec_parameters_to_context does not set the framerate field of AVCodecContext: https://www.ffmpeg.org/doxygen/trunk/codec__par_8c_source.html#l00182
As Stream.rate/Stream.framerate relies on getattr pass through to its codec_context's rate/framerate, this means Stream.rate/Stream.framerate are no longer valid for input video streams.
Two ways we can remedy this:
- We can set the codec_context's framerate here and continue to rely on this passthrough feature.
- We can add
rate/framerateproperties directly toVideoStream.
Note thatAudioStreamdoes not have this issue as thesample_ratefield gets copied properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not even sure we should be doing anything:
https://www.ffmpeg.org/doxygen/trunk/structAVCodecContext.html#a4d08b297e97eefd66c714df4fff493c8
decoding: For codecs that store a framerate value in the compressed bitstream, the decoder may export it here. { 0, 1} when unknown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure it's not always set. It was causing a failure in our test suite that I remedied using the 2nd option above.
However, what you said actually implies we should rely on the first option above (passthrough), because the decoder may export it when decoding the bitstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've reached the point where not merging is actively hurting the project, so I'm going to hit the button. Would you mind opening an issue to discuss the "framerate" point you made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
We now allocate and populate an AVCodecContext ourselves. avcodec_copy_context is also gone, so stop using it. We relax the Stream.average_rate tests for older FFmpeg, as the videos output by these older FFmpeg's seem to give a slightly wrong FPS since the switch to our own AVCodecContext.
428e50f to
c02ac56
Compare
No description provided.