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

mp4再生で半透明になる問題修正 #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

huiping192
Copy link

@huiping192 huiping192 commented Jan 26, 2022

defaultのPixelFormatが kCVPixelFormatType_420YpCbCr8BiPlanarVideoRangeになっていて、rangeとしては(luma=[16,235] chroma=[16,240])のため、alpha用のr値が0,255になれなかった問題。

metal部分でrange変更追加して修正.
hevcのalpha部分は修正不要なので、処理わけるようにした

@huiping192 huiping192 changed the title mp4再生で半透明になる問題修正 [WIP]mp4再生で半透明になる問題修正 Jan 26, 2022
@huiping192 huiping192 force-pushed the hotfix/mp4-Transparent-bug branch from 4d3bd2d to 42c893e Compare January 26, 2022 13:43
@huiping192 huiping192 changed the title [WIP]mp4再生で半透明になる問題修正 mp4再生で半透明になる問題修正 Jan 26, 2022
@@ -22,7 +22,8 @@ open class PlayerView: UIView {
private let renderQueue: DispatchQueue = .global(qos: .userInitiated)
private let commandQueue: MTLCommandQueue
private let textureCache: CVMetalTextureCache
private let pipelineState: MTLRenderPipelineState
private let mp4PipelineState: MTLRenderPipelineState
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipelineは常に1つのみを保持するようにしてください

Copy link
Author

@huiping192 huiping192 Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlayerViewインスタンスが作ったらmp4,hevcどっちでも再生可能なので2つ用意する必要があるが、どこか勘違いしてました? もしくはlazy initか

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

将来的にPlayerViewとPlayer・Assetに分割するのでこの実装のままでもOKとします。
ただし変数名に関してはビデオフォーマットではなくシェーダの実態を表す名前にしてください。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名前修正しました

baseCbCrTexture.sample(colorSampler, in.texCoords).rg,
1.0f);
// yuv video range to full range
baseYUVColor.r = (baseYUVColor.r - (16.0f/255.0f)) * (255.0f/(235.0f-16.0f));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

フルレンジのmp4を読み込んだ場合に意図しない変換が行われるように見えます。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range shader内で判定できないので、asset読み込みで指定しないといけないが、それであってますか?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あってます、レンダリング前に判断して分岐する必要があります。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動画読み込み時にPixelFormatType明示的にvideo rangeに指定しました

@huiping192 huiping192 force-pushed the hotfix/mp4-Transparent-bug branch 3 times, most recently from 530c11f to bb58acc Compare February 3, 2022 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants