kingslay / KSPlayer

A video player for iOS、macOS、tvOS、visionOS , based on AVPlayer and FFmpeg, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, SwiftUI, support subtitles.
https://apps.apple.com/app/tracyplayer/id6450770064
GNU General Public License v3.0
935 stars 192 forks source link

Black video Seek Issue #54

Closed wertpoiu closed 4 years ago

wertpoiu commented 4 years ago

(tvOS Only) Start Seeking right after video starts lets say after 1 or 2 seconds video will go all black had to restart video. and wait few seconds to seek. Please fix @kingslay

UnknownCoder807 commented 4 years ago

This sounds like its related to the issue I have.

https://github.com/kingslay/KSPlayer/issues/45

UnknownCoder807 commented 4 years ago

ok after speaking to @wertpoiu this is definitely the same issue as I was having.

Please @kingslay try and replicate this yourself. its dead simple

    @IBAction func sliderChanged(_ sender: UISlider) {
        print("Slider has been changed")
        playerView.seek(time: Double(sender.value))
    }

then seek through a media and you will sometimes see this issue. It is very intermittent for me.

If you want a video link (although any video will have the issue) then I can send you one via email?

This issue alone is stopping me from shipping your fabulous player with my iptv app.

This works fine on the simulator but not on an actual apple tv. it also doesn't work for me on an actual iPad.

Logging from iPad Pro

KSPlayer: KSMEPlayer.swift:263 play() | play KSPlayer.KSMEPlayer
KSPlayer: KSPlayerLayer.swift:100 state | playerStateDidChange - bufferFinished
KSPlayer: KSPlayerLayer.swift:267 changeLoadState(player:) | ["decodeVideoTime": 1.3811132500122767, "openTime": 1.159458458336303, "decodeAudioTime": 1.3716274999896996, "prepareTime": 0.00011070832260884345, "findTime": 1.3485552500060294, "readAudioTime": 1.371377500006929, "readVideoTime": 1.3712795416649897, "firstTime": 4.56799208332086]
2020-08-01 18:23:15.287168+0100 [21961:1054953] [CAMetalLayerDrawable texture] should not be called after already presenting this drawable. Get a nextDrawable instead.
2020-08-01 18:23:15.288268+0100 [21961:1055003] Each CAMetalLayerDrawable can only be presented once!
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
2020-08-01 18:23:20.356041+0100 [21961:1054999] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)
2020-08-01 18:23:20.356380+0100 [21961:1054999] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)
wertpoiu commented 4 years ago

yes its a issue with playerView.seek

kingslay commented 4 years ago

you must use touchUpInside not valueChanged

    open func slider(value: Double, event: ControlEvents) {
        if event == .valueChanged {
            toolBar.currentTime = value
        } else if event == .touchUpInside {
            seek(time: value)
        }
    }
UnknownCoder807 commented 4 years ago

I’m not using the built in slider. I am using my own slider.

kingslay commented 4 years ago

yes i know. But when was your method called? is on valueChanged?

UnknownCoder807 commented 4 years ago

I don't know what you are asking me. I have a UISlider which has an action of

 @IBAction func sliderChanged(_ sender: UISlider) {
        playerView.seek(time: Double(sender.value))
    }

this is how I detect the slider has been dragged (slided? changed?) by the end user

wertpoiu commented 4 years ago

Do you actual apple tv to test? @kingslay

kingslay commented 4 years ago

no. i only have the simulator

UnknownCoder807 commented 4 years ago

The same issue arises on a real ipad or iphone. Please try and replicate it as its a major deal-breaker for using your player.

kingslay commented 4 years ago

The same issue arises on a real ipad or iphone. Please try and replicate it as its a major deal-breaker for using your player.

I feel like this is a problem with your code. You should only seek when the user's finger leaves the progress bar. not just seek while dragging.

UnknownCoder807 commented 4 years ago

ok, I will change my code to only do seek when the user stops dragging. see if this helps.

wertpoiu commented 4 years ago

this is issue is with KSMEPlayer and seek method while using avplayer as a first player i dont find this issue, If i use playerView.seek method manually then this issue arises as well.

wertpoiu commented 4 years ago

Can i email you video?

kingslay commented 4 years ago

It can be. Can you reproduce the problem in the demo now?

wertpoiu commented 4 years ago

It can be. Can you reproduce the problem in the demo now?

it happens in real device only

kingslay commented 4 years ago

can it happens in real iPhone device? i only have a real iPhone device

wertpoiu commented 4 years ago

can it happens in real iPhone device? i only have a real iPhone device

No its not happening in iphone, but if you will implement playerView.seek method manually then it can happen

UnknownCoder807 commented 4 years ago

@kingslay I've sent you an email with a very basic demo showing the issue. this demo is for iPhone or iPad. Please run on a real device because on the simulator it works ok.

wertpoiu commented 4 years ago

seek issue is so bad on tvos that if video starts and (i seek with my manual seek method) i start seeking right away, audio dont pause and after that i play other video there is 2,3 sounds coming out of tv of same video.

kingslay commented 4 years ago

@kingslay I've sent you an email with a very basic demo showing the issue. this demo is for iPhone or iPad. Please run on a real device because on the simulator it works ok.

OK . i will try it

wertpoiu commented 4 years ago

you must use touchUpInside not valueChanged

    open func slider(value: Double, event: ControlEvents) {
        if event == .valueChanged {
            toolBar.currentTime = value
        } else if event == .touchUpInside {
            seek(time: value)
        }
    }

i tried this it didnt work

kingslay commented 4 years ago

@snappycode1 @wertpoiu i have update the code 5b88b7fbe7c146047ee303dab374e60a11964ff8. please try again.

wertpoiu commented 4 years ago

@snappycode1 @wertpoiu i have update the code 5b88b7f. please try again.

it seems fixed black video issue and 2 3 sounds were playing issue. But if seek forward and backward sometimes video stucks and keep loading and dont play. I have to press play, pause 2 3 times

UnknownCoder807 commented 4 years ago

@snappycode1 @wertpoiu i have update the code 5b88b7f. please try again.

I still have the seek issue. The frame is frozen and the following is logged

KSPlayer: KSPlayerLayer.swift:100 state | playerStateDidChange - bufferFinished
2020-08-04 17:20:33.187684+0100 Test Seek[33429:1526278] [CAMetalLayerDrawable texture] should not be called after already presenting this drawable. Get a nextDrawable instead.
2020-08-04 17:20:33.190915+0100 Test Seek[33429:1526311] Each CAMetalLayerDrawable can only be presented once!
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
2020-08-04 17:20:38.193815+0100 Test Seek[33429:1526315] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)
2020-08-04 17:20:38.194161+0100 Test Seek[33429:1526315] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)

the last line of this log is repeated loads of times a second.

This is using the same demo I sent to you via email.

kingslay commented 4 years ago

@snappycode1 @wertpoiu i have update the code 5b88b7f. please try again.

I still have the seek issue. The frame is frozen and the following is logged

KSPlayer: KSPlayerLayer.swift:100 state | playerStateDidChange - bufferFinished
2020-08-04 17:20:33.187684+0100 Test Seek[33429:1526278] [CAMetalLayerDrawable texture] should not be called after already presenting this drawable. Get a nextDrawable instead.
2020-08-04 17:20:33.190915+0100 Test Seek[33429:1526311] Each CAMetalLayerDrawable can only be presented once!
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
IOSurfaceCompressionFootprint of 0 used 
2020-08-04 17:20:38.193815+0100 Test Seek[33429:1526315] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)
2020-08-04 17:20:38.194161+0100 Test Seek[33429:1526315] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)

the last line of this log is repeated loads of times a second.

This is using the same demo I sent to you via email.

do you had clean Build Folder?

kingslay commented 4 years ago

You can see if you have access to this method. clear(drawable: CAMetalDrawable, renderPassDescriptor: MTLRenderPassDescriptor) Normal doesn't go into this method.

UnknownCoder807 commented 4 years ago

I cleaned the build folder, built the project again and same. As soon as I seek the video it freezes and displays the above logging. On a real ipad using the demo I sent.

I checked the source code for KSPlayer to make sure the changes you made are definitely there and they are so I'm using the latest public code.

kingslay commented 4 years ago

I cleaned the build folder, built the project again and same. As soon as I seek the video it freezes and displays the above logging. On a real ipad using the demo I sent.

I checked the source code for KSPlayer to make sure the changes you made are definitely there and they are so I'm using the latest public code.

You can see if you have access to this method? clear(drawable: CAMetalDrawable, renderPassDescriptor: MTLRenderPassDescriptor)

UnknownCoder807 commented 4 years ago

Forgive my ignorance and not knowing, but how do I check for that function? thanks.

kingslay commented 4 years ago

i had update the code b7f4a55b2c710822bf98ad42827b34527ff68d46 . please try again

UnknownCoder807 commented 4 years ago

i had update the code b7f4a55 . please try again

Sadly still the same on the real iPad. I really appreciate your work on this.

wertpoiu commented 4 years ago

I am sorry Black video issue is still there and multiple audio's are playing for same video even the video is paused and multiple audios are playing

wertpoiu commented 4 years ago

Its happening with manual seek only, and one more issue with internal seek i have to press play pause 2,3 times to play video after seeking.

kingslay commented 4 years ago

My side of the viewing is very stuck and cannot be reproduced. So I download 131956.mkv to local and play it. Still can't reproduce. You can replace the url in my demo to play it, and then use my own seek to see if it can reproduce the problem.


   if let url = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8") {
            objects.append(KSPlayerResource(url: url, options: KSOptions(), name: "m3u8视频"))
        }
kingslay commented 4 years ago

Or you can download that video and play it locally. See if it works.

kingslay commented 4 years ago

@snappycode1 What is the system version of your iOS device?

UnknownCoder807 commented 4 years ago

@snappycode1 What is the system version of your iOS device?

I have 2 iPads. one is on iOS 13 and the other on iOS 14 beta 4

Both devices have the same issue.

UnknownCoder807 commented 4 years ago

My side of the viewing is very stuck and cannot be reproduced. So I download 131956.mkv to local and play it. Still can't reproduce. You can replace the url in my demo to play it, and then use my own seek to see if it can reproduce the problem.


   if let url = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8") {
            objects.append(KSPlayerResource(url: url, options: KSOptions(), name: "m3u8视频"))
        }

Using your internal seek, the issue is black screen and audio still playing.

It is intermittent though, so sometimes works ok and others not.

kingslay commented 4 years ago

you can download 131956.mkv to local and play it. So that you can check if it's a network problem

UnknownCoder807 commented 4 years ago

you can download 131956.mkv to local and play it. So that you can check if it's a network problem

I downloaded 131956.mkv and loaded it locally. The manual seek seems to work ok.

UnknownCoder807 commented 4 years ago

After more extensive testing I found that playing the file locally is generally working, but sometimes the video will freeze (audio still plays) but it recovers after a few seconds.

UnknownCoder807 commented 4 years ago

@kingslay any more thoughts on how we can resolve this issue please?

kingslay commented 4 years ago

@snappycode1 i update the code e0fc6272df369063587a8a4af3e5b10aa0a87c3d. please try again. thank you

UnknownCoder807 commented 4 years ago

@snappycode1 i update the code e0fc627. please try again. thank you

Thanks. I have tested a load of videos on ipad and apple tv and they are all so far, playing perfectly. I'll keep testing and report back if I have any issues with seek still.

UnknownCoder807 commented 4 years ago

It's been a few days since the last code update for this issue and so far I have not had 1 problem. so for me at least, this issue is resolved.