Closed Nunatic02 closed 1 year ago
I just merged a PR to update to the latest black to fix the linting errors. So you can merge or rebase with master to fix the Linting build.
Other than that, it looks like there are some tests with hard-coded fps numbers that need to be updated.
I just merged a PR to update to the latest black to fix the linting errors. So you can merge or rebase with master to fix the Linting build.
Other than that, it looks like there are some tests with hard-coded fps numbers that need to be updated.
Wow cool! Thank you so much! Should I go ahead and merge master to my forked repo, and fix those test cases? I'm kind of nervous because I have never made changes to any open source packages before 🥺.
Should I go ahead and merge master to my forked repo, and fix those test cases?
Yes, that'd be great 👍
I'm kind of nervous because I have never made changes to any open source packages before 🥺.
Really? I'm impressed by your thoroughness. If you need help with technical issues regarding git or something, feel free to ask for help!
@almarklein Thank you so much Almar! You have made my day! 🥰
I've forgotten about this, sorry!
Motivation
Tis PR is to solve the issue mentioned in https://github.com/imageio/imageio/issues/949
Goal of this PR
Trying to set
meta["fps"]
to be thefps
value parsed from ffmpeg banner of the input video stream, instead of thetbr
value of the output video stream. Code ReferenceCurrent Status
Currently, we are setting
meta["fps"]
to prefer thetbr
value of the output video source. For example, for the ffmpeg banner below:videolines[0]
will beStream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 620x680 [SAR 1:1 DAR 31:34], 1117 kb/s, 29.45 fps, 29.08 tbr, 90k tbn (default)
videolines[-1]
will beStream #0:0(und): Video: rawvideo (RGB[24] / 0x18424752), rgb24, 620x680 [SAR 1:1 DAR 31:34], q=2-31, 294276 kb/s, 29.08 fps, 29.08 tbn (default)
meta["fps"] = fps
will be set to thetbr
value of the output video stream, namely 29.08. What we actually want is thefps
value of the input video stream, namely 29.45.Changes
1. change to be parsing data from the output video stream the input video stream
Because we are interating through
(videolines[0], videolines[-1])
, the fps value will always be parsing data fromvideolines[-1]
. Namely, the output video stream. However, we should really be parsing data from the input video stream. So I've changed it to[videolines[0]]
. A benefit for keeping thefor line in [videolines[0]]
structure, even when there's only one element in the array, is that in cases when we don't have any video stream,videolines[0]
will be None, and the code will still work.2. Change to remove the preference of
tbr
overfps
As I've described in https://github.com/imageio/imageio/issues/949, we should by default parse and use ffmpeg's
fps
, instead oftbr
, as ourfps
metadata. Because the source code ofimageio
is usingfps
asaverage frame rate
, namelytotal # of frames / total duration
. And ffmpeg'sfps
value also denotesaverage frame rate
, whiletbr
is just a guessed frame rate. If not doing so,get_data(index)
will always return the wrong video frame data whenfps
andtbr
of a video doesn't match. And even worse, trying runget_data
of the last few frames will result in fatalIndexError
.So I've removed
matches.sort(key=lambda x: x[1] == "tbr", reverse=True)
, because the function of this line is to prefertbr
overfps
. And I've also removed matching fortbr
, because we don't need that value. I don't think there's any cause wheretbr
data exists, whilefps
data is missing.