AVPlayer throwing : "Internal error: restarting too far ahead"
Asked Answered
K

3

8

I am observing KVO AVPlayerItemNewErrorLogEntryNotification of the AVPlayer and I find the following error:

  • errorStatusCode:-12645 errorDomain :CoreMediaErrorDomain errorComment:Internal error: restarting too far ahead (-1.4084s)

I am unable to understand what the below line really means.

"Internal error: restarting too far ahead"

Can anyone help me to find the root cause of this issue.

Krystin answered 7/3, 2016 at 23:33 Comment(4)
You might want to post the code that's generating the error along with the error.Trifle
@AdrianB, I am playing a live video and I find this error logs for some videos .I believe there is no issue with the code , want to know whether this is an issue with the video that I am playing . Just want to know what the error really means.Krystin
Could you post a feed that helps replicate the error?Smolt
@xvan, I can't post it as it is DRM and the streams are encrypted .Krystin
A
5

According to an Apple employee this error message means that:

The player is complaining that it was trying to restart a live stream, but only had 1.4 seconds of material available. How many segments are in your live playlist? These days we recommend that you always have at least six segments in the playlist. I believe the only effect is to delay palyback until it has enough data.

Source: https://forums.developer.apple.com/thread/40791


The cause of the error most probably originates from the m3u8 itself.

When streaming a live program (e.g. any TV channel) there is a delay between the availability of event data and the encoder creating media segments (.ts) that are then appended to the playlist.

I could imagine that these types of errors are generated if the playerItem playhead's position is at the very edge of the buffer and new media segments are not made available fast enough on the server.


Should these errors be prevented or handled on the client's side:

Since these errors are reported as internal and AVPlayer apparently recovers from it, it is safe to assume that they are being handled internally. They could therefore be understood as simple error reporting and one could choose to ignore them.

If one wanted to prevent them, the only way to do this might be to manually set the live buffer's edge back in time a few seconds.

Apeman answered 3/6, 2016 at 9:15 Comment(2)
manually set the live buffer edge back in time a few seconds. What does this mean exactly? I assume this isn't a client-side modification (taking the first paragraph into account).Gallon
it means that you shouldn't let your live stream run truly live (i.e. have your buffer point to the very edge of the m3u8 -- the last .ts available), but rather with an offset to allow for possible delays in the updates written to the m3u8. I realised I answered the question assuming the OP used a buffer for their live stream within which one could seek forwards or backwards. This is product specific. In case your product doesn't use a buffer replace manually set the live buffer edge back in time a few seconds with manually set your playhead back in time a few secondsApeman
H
12

If long .ts video file respons with: -12645.

There is no documentation for error status codes returned by MPMediaPlayer in MPMovieErrorLogEvent class. But some of them are:

HTTP status - errorStatusCode - errorDomain - errorComment

400     -12666  CoreMediaErrorDomain    unrecognized http response 400  
401     -12937  CoreMediaErrorDomain    Authentication Error    
402     -12666  CoreMediaErrorDomain    unrecognized http response 402  
403     -12660  CoreMediaErrorDomain    HTTP 403: Forbidden     
404     -12938  CoreMediaErrorDomain    HTTP 404: File not found    
405     -12666  CoreMediaErrorDomain    unrecognized http response 405  
406     -12666  CoreMediaErrorDomain    unrecognized http response 406  
407     -12937  CoreMediaErrorDomain    Authentication Error    
409     -12666  CoreMediaErrorDomain    unrecognized http response 409  
...                 
415     -12666  CoreMediaErrorDomain    unrecognized http response 415  

500     -12666  CoreMediaErrorDomain    unrecognized http response 500  
501     -12666  CoreMediaErrorDomain    unrecognized http response 501  
502     -12666  CoreMediaErrorDomain    unrecognized http response 502  
503     -12661  CoreMediaErrorDomain    HTTP 503: Unavailable   
504     -12666  CoreMediaErrorDomain    unrecognized http response 504  
505     -12666  CoreMediaErrorDomain    unrecognized http response 505  

if long .ts video file respons  -12645  CoreMediaErrorDomain    No response for media file in 10 s  

video .ts file bitrate differ from m3u8 declaration     -12318  CoreMediaErrorDomain    Segment exceeds specified bandwidth for variant     

for live stream.playlist m3u8 did not change too long   -12642  CoreMediaErrorDomain    Playlist File unchanged for 2 consecutive reads     

if wrong host ip    -1004   kCFErrorDomainCFNetwork     -   

if wrong dns host name  -1003   kCFErrorDomainCFNetwork     -   

if bad formatted URL    -1000   kCFErrorDomainCFNetwork     -   

if invalid https/ssl request    -1202   kCFErrorDomainCFNetwork     -
Haemin answered 17/3, 2016 at 20:34 Comment(2)
Thanks for replying , can you let me know from which source u got the information about "If long .ts video file respons with"Krystin
Do you know about CoreMediaErrorDomain error -12155 ?Endogenous
A
5

According to an Apple employee this error message means that:

The player is complaining that it was trying to restart a live stream, but only had 1.4 seconds of material available. How many segments are in your live playlist? These days we recommend that you always have at least six segments in the playlist. I believe the only effect is to delay palyback until it has enough data.

Source: https://forums.developer.apple.com/thread/40791


The cause of the error most probably originates from the m3u8 itself.

When streaming a live program (e.g. any TV channel) there is a delay between the availability of event data and the encoder creating media segments (.ts) that are then appended to the playlist.

I could imagine that these types of errors are generated if the playerItem playhead's position is at the very edge of the buffer and new media segments are not made available fast enough on the server.


Should these errors be prevented or handled on the client's side:

Since these errors are reported as internal and AVPlayer apparently recovers from it, it is safe to assume that they are being handled internally. They could therefore be understood as simple error reporting and one could choose to ignore them.

If one wanted to prevent them, the only way to do this might be to manually set the live buffer's edge back in time a few seconds.

Apeman answered 3/6, 2016 at 9:15 Comment(2)
manually set the live buffer edge back in time a few seconds. What does this mean exactly? I assume this isn't a client-side modification (taking the first paragraph into account).Gallon
it means that you shouldn't let your live stream run truly live (i.e. have your buffer point to the very edge of the m3u8 -- the last .ts available), but rather with an offset to allow for possible delays in the updates written to the m3u8. I realised I answered the question assuming the OP used a buffer for their live stream within which one could seek forwards or backwards. This is product specific. In case your product doesn't use a buffer replace manually set the live buffer edge back in time a few seconds with manually set your playhead back in time a few secondsApeman
C
0

Based on Benjamin's answer and also according to my experience with AVFoundation you can use the below code to convert the AVPlayeritem underlay error to CoreMediaError for most common situations.

public enum CoreMediaError:Error {
    
    static let domain = "CoreMediaErrorDomain"
    
    case unknown
    case notFound
    case unauthorized
    case authenticationError
    case forbidden
    case unavailable
    case mediaFileError
    case bandwidthExceeded
    case playlistUnchanged
    case decoderMalfunction
    case decoderTemporarilyUnavailable
    case wrongHostIP
    case wrongHostDNS
    case badURL
    case invalidRequest
    case unrecognizedHttpResponse
    
    init?(_ error:NSError){
        
        guard error.domain == CoreMediaError.domain else {return nil}
        
        switch error.code {
        case -12937:
            // HTTP: 401     -12937  CoreMediaErrorDomain    Authentication Error
            // HTTP: 407     -12937  CoreMediaErrorDomain    Authentication Error
            self = .authenticationError
        case -16840:
            self = .unauthorized
        case -12660:
            // HTTP: 403     -12660  CoreMediaErrorDomain    HTTP 403: Forbidden
            self = .forbidden
        case -12938:
            //HTTP: 404     -12938  CoreMediaErrorDomain    HTTP 404: File not found
            self = .notFound
        case -12661:
            //HTTP: 503     -12661  CoreMediaErrorDomain    HTTP 503: Unavailable
            self = .unavailable
        case -12645, -12889:
            //   if long .ts video file respons  -12645  CoreMediaErrorDomain    No response for media file in 10 s
            //   https://developer.apple.com/forums/thread/5589
            self = .mediaFileError
        case -12318:
            //  video .ts file bitrate differ from m3u8 declaration     -12318  CoreMediaErrorDomain    Segment exceeds specified bandwidth for variant
            self =  .bandwidthExceeded
        case -12642:
            //  for live stream.playlist m3u8 did not change too long   -12642  CoreMediaErrorDomain    Playlist File unchanged for 2 consecutive reads
            self =  .playlistUnchanged
        case -12911:
            self =  .decoderMalfunction
        case -12913:
            self =  .decoderTemporarilyUnavailable
        case -1004:
            //  if wrong host ip    -1004   kCFErrorDomainCFNetwork
            self =  .wrongHostIP
        case -1003:
            //   if wrong dns host name  -1003   kCFErrorDomainCFNetwork
            self =  .wrongHostDNS
        case -1000:
            //   if bad formatted URL    -1000   kCFErrorDomainCFNetwork
            self =  .badURL
        case -1202:
            //   if invalid https/ssl request    -1202   kCFErrorDomainCFNetwork
            self =  .invalidRequest
        case -12666:
            //400     -12666  CoreMediaErrorDomain    unrecognized http response 400
            //402     -12666  CoreMediaErrorDomain    unrecognized http response 402
            //405     -12666  CoreMediaErrorDomain    unrecognized http response 405
            //406     -12666  CoreMediaErrorDomain    unrecognized http response 406
            //409     -12666  CoreMediaErrorDomain    unrecognized http response 409
            //...
            //415     -12666  CoreMediaErrorDomain    unrecognized http response 415
            //500     -12666  CoreMediaErrorDomain    unrecognized http response 500
            //501     -12666  CoreMediaErrorDomain    unrecognized http response 501
            //502     -12666  CoreMediaErrorDomain    unrecognized http response 502
            //504     -12666  CoreMediaErrorDomain    unrecognized http response 504
            //505     -12666  CoreMediaErrorDomain    unrecognized http response 505
            self =  .unrecognizedHttpResponse
        default:
            self =  .unknown
        }
    }
}

You can also check this GitHub gist for more details

Conduct answered 15/8, 2023 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.