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, support subtitles.
GNU General Public License v3.0
887 stars 184 forks source link

Wrong startTime in MEPlayerItem #653

Closed romanyczn1 closed 7 months ago

romanyczn1 commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Set KSOptions.firstPlayerType = KSMEPlayer.self KSOptions.secondPlayerType = KSMEPlayer.self
  2. Set video url "https://playertest.longtailvideo.com/adaptive/customIV/prog_index.m3u8"
  3. The startTime and duration in MEPlayerItem are incorrect, the startTime is 9.956011, and duration also calculated incorrectly baset on startTime

or

  1. Pass url "https://playertest.longtailvideo.com/adaptive/customIV/prog_index.m3u8" to SwiftUI demo
  2. Video duration calculated incorrectly

Expected behavior The startTime is zero, and duration is correct

charsdavy commented 7 months ago

https://playertest.longtailvideo.com/adaptive/customIV/prog_index.m3u8 使用这条链接地址,在IINA上播放,可以拉进度条,且能及时响应显示画面。但是在 KSPlayer 上,拉进度条后,画面黑屏,声音依旧还在。这个问题应该是没有很好的解决。

kingslay commented 7 months ago

在Mac上是会有这个问题,你双击全屏下,就不会黑屏了。

charsdavy commented 7 months ago

Mac 播放本地.m3u8 也是有黑屏问题。但是按照你所说,全屏一下后,再次进行拉进度条,就不会黑屏。这是为什么呢?一定要操做一下全屏?问题能修复吗?

kingslay commented 7 months ago

这个问题很奇怪,我也还没找到解决的bug。

charsdavy commented 7 months ago

warning KSPlayer: MEPlayerItem.swift:129 MEPlayerItem | vt decoder cb: output image buffer is null: -12909 error KSPlayer: MEPlayerItem.swift:129 MEPlayerItem | hardware accelerator failed to decode picture 黑屏的错误信息是这两条。看看有帮助没。

charsdavy commented 7 months ago

FFmpegDecode.swift中如下改动,可以解决该问题。这样的改法是否有其他影响,麻烦看一下

func doFlushCodec() {
        bestEffortTimestamp = Int64(0)
        if firstSeek {
            firstSeek = false
        } else {
//            if codecContext != nil {
//                avcodec_flush_buffers(codecContext)
//            }
        }
    }
kingslay commented 7 months ago

文档里面说seek的时候需要调用这个。可以先不用调用这个。然后看下多次seek之后。会不会有内存泄漏的情况

charsdavy commented 7 months ago

firstSeek = true 时也没有调用 avcodec_flush_buffers 方法,如果有内存泄漏,那不是早就有了。