Add video format detection and support for 4:2:2 formats #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Preface: I don't have much experience with Go, but this has worked for me and I figured I might as well open a PR for visibility. I don't plan on adjusting the PR. Feel free to take the code as is or use it as inspiration for a more proper implementation; or simply close the PR if this is not something that is desirabe to have.
I use go-transcode to be able to preview stock videos (many of them quite old and with now outdated video encoding) on the web as part of a larger media management system (for a custom-built DAM service). I ran into the issue that transcoding a video with a 4:2:2 format didn't work, because the
high
preset doesn't support 4:2:2 chroma subsampling. To fix this, I added basic video format detection and made it so that thehigh422
profile is used if a video with any 4:2:2 format is detected.According to the ffmpeg docs the
high422
profile only supportsyuv420p
,yuv422p
,yuv420p10le
andyuv422p10le
, which is something I only realized after looking up all the 4:2:2 formats I was able to find. I still kept all of them in theis422Format
check and using thehigh422
profile might or might not work for them.