Comments (8)
Because doing this feels strange no?
It's strange because Timecode.FrameRate
is a BITC timecode frame rate, and not a "video" frame rate. They are not actually the same thing. TimecodeKit is geared towards supporting DAW software that deals in established industry timecode frame rates.
In fact, DAW software relies on the user to tell it what timecode frame rate they are working in because it cannot always know for sure from a video file.
Video rates as a floating-point value are reductive and do not carry enough information to always accurately guess timecode frame rate. So there is no provision in the library to do it yet.
I'm working on an application that had the same problem as you - we're importing video files that only report a floating-point fps value and often lack any embedded meta-data to indicate what the actual timecode frame rate is suppose to be. We had to write a method that "guesses" the nearest timecode frame rate and it's not as simple as you might think.
In fact, this exact discussion has already come up if you checked the closed Issues:
Ultimately the solution was a bit more complex than the sample code that was in that thread.
Perhaps TimecodeKit could use a guessFrameRate(fromVideoFloatingPointRate: Double)
method. But it still wouldn't always guarantee an enum case that is accurate.
from timecodekit.
In short, there are times when a certain floating-point video frame rate could actually mean one of several different timecode frame rates. And then you can often get video frame rates that do not correspond to timecode frame rates at all (like variable frame rates in video codecs which, when read from a video's meta data, actually show the average frame rate. it gets weird).
It's easier to explain with examples, so maybe that could be put at the top in the README.md.
from timecodekit.
Related: at one point, allowing arbitrary frame rate (ie: having an enum case like .video(Double)
) was considered for instances where calculations could be done based on a frame rate but it would add complexity to the library and may not always have the desired outcome:
from timecodekit.
Perhaps there is a possibility of introducing a new struct called VideoTimecode
which will allow separation of time domains. It could have methods to purely process floating-point video frame rates to/from timecode strings etc.
from timecodekit.
Thanks for the thoughtful explanation!
I had no idea about the precision issues, it seems logical for audio.
Using a custom function is actually going to work in my case.
from timecodekit.
No worries, if you have any questions or ideas please feel free.
I know this is a common question/issue so it may either need a preface in the README.md or could become incorporated into the library as a feature if it makes sense.
from timecodekit.
Just an update:
I'm doing some investigation into video file metadata to see if there's a more reliable way to infer a BITC timecode frame rate from a video file. Because there are so many video container types and metadata is not consistently embedded, it's never a sure bet. But often there is more specialized information embedded than just a nominal/average floating-point fps.
Digging through AVFoundation and the FFmpeg source code has been useful. I might have a bit more time next week to get a parser method put together to scrape frame rate info and hopefully provide some useful functionality there.
from timecodekit.
In release 1.2.7, a init?(raw: Double, favorDropFrame: Bool = false)
init has been added to FrameRate
.
It is a failable initializer that will return a valid FrameRate
if the raw
fps matches one of the supported BITC rates.
The exception is that certain rates can be interpreted as one of 2 or 3 different actual BITC rates. Drop frame information cannot be conveyed. For example, 29.97002997 is ambiguous as it is valid for both 29.97 non-drop, 29.97 drop, and 30 drop. For this purpose, the favorDropFrame: Bool = false
parameter will return the drop-frame variant if the raw rate matches more than one rate.
So the utility of such an initializer is questionable, but there may be scenarios where heuristically inferring BITC rate is desired, perhaps as a springboard or default value that the user can then re-select at their discretion.
There is still much room for further research into video file metadata etc. that can be used to form frame rate information more accurately and deterministically. But for the time being, I will close this thread as that is a separate feature that may come at a later date.
from timecodekit.
Related Issues (20)
- Formatter coloration issues when focused or not (macOS) HOT 2
- Introduce a `Timecode.Delta` object to allow abstract timecode math HOT 5
- Replace TimeValue with TimeInterval? HOT 1
- TCC from fractional seconds HOT 2
- Add `Timecode(_ exactly: FrameCount)` init and `setTimecode(_ exactly: FrameCount)` methods HOT 1
- Update Documentation
- API change: `.setTimecode(...)` methods `throws` instead of returning `Bool` HOT 3
- Make all stored properties in `Timecode` struct mutable HOT 1
- Add methods to use a `Timecode` struct as a template HOT 2
- Documentation update
- Add `clamping`, `wrapping` overloads for to ancillary value type init/methods HOT 3
- Integer init and setter for Samples HOT 1
- Linux support HOT 1
- `Timecode.FrameRate`: Add failable init from rational frame rate (fraction) HOT 3
- Frame Rate & Timecode Conversion to/from Rational Numbers (fractions) HOT 3
- `Timecode`: Add `CMTime` init, `setTimecode()` methods and `cmTime` property HOT 1
- Negative rational values HOT 2
- Support for 96, 96/1.001 HOT 2
- AVFoundation Extensions Improvements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timecodekit.