【问题标题】:AVPlayer won't play audio files from FFMPEGAVPlayer 不会播放来自 FFMPEG 的音频文件
【发布时间】:2021-04-21 05:33:11
【问题描述】:

在请求音频数据之前,AVPlayer 向 FFMPEG 请求字节范围 0-1。

FFMPEG 给出 200 响应,但 AVPlayer 需要 206 响应。

这会导致请求失败,无法播放音频。

预期行为: 通过 ffmpeg 流式传输时播放曲目

当前行为:尝试使用 ffmpeg 进行流式传输时,我们得到“操作已停止”

FFMPEG 命令示例:

ffmpeg -i "/path/to/audio/track.mp3" -vn -strict -2 -acodec pcm_u8 -f wav -listen 1 -seekable 1 http://localhost:8090/restream.wav

玩家日志:

Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x600003bcc4b0 {Error Domain=NSOSStatusErrorDomain Code=-12939 "(null)"}}
!av_interleaved_write_frame(): Broken pipe

!Connection to tcp://localhost:8090 failed: Connection refused

!Connection to tcp://localhost:8090 failed: Connection refused

!Connection to tcp://localhost:8090 failed: Connection refused

!Error writing trailer of http://localhost:8090/restream.wav: Broken pipe

这个错误是defined by Apple as:

+"The HTTP server sending the media resource is not configured as expected. This might mean that the server does not support byte range requests."

在this StackOverflow post中总结得很好:

when AVPlayerItem receive a video URL , it do the following task:

    Send a bytes request HTTP Request, and range = 0 -1
    If the response code is 206 and return 1 bytes data, It do the 3th task, if not, AVErrorServerIncorrectlyConfigured error occurred.
    continue send other HTTP Request, to download segment of All duration. and the response of VideoData code must be 206

In my situation , when send range[0-1] HTTP request, the server side give me a 200 OK response, So error occurred.

网络日志:

GET /file.wav HTTP/1.1
Host: localhost:1234
X-Playback-Session-Id: F72F1139-6F4C-4A22-B334-407672045A86
Range: bytes=0-1
Accept: */*
User-Agent: AppleCoreMedia/1.0.0.18C61 (iPhone; U; CPU OS 14_3 like Mac OS X; en_us)
Accept-Language: en-us
Accept-Encoding: identity
Connection: keep-alive

HTTP/1.1 200 OK
Content-Type: application/octet-stream
Transfer-Encoding: chunked

转载using this sample app:

这也可以使用标准 ffmpeg 复制并将 URL 添加到本地或远程 ffmpeg URL

我们可以通过更改 FFMPEG 或 AVPlayer 来解决这个问题吗?

【问题讨论】:

  • 尝试从远程资源加载文件
  • 而不是本地主机?

标签: ios ffmpeg avplayer


【解决方案1】:

我在 ffmpeg 邮件列表上问过这个问题,似乎不可能:

如果我正确理解您的要求,您并不是在要求 更改返回类型(您可能自己也可以这样做),但对于 字节范围请求的实现。我不认为这是 FFmpeg 完全可以实现。

同样不可能让 AVPlayer 忽略字节范围请求:

媒体提供者需要支持 http 1.1 是苹果标准 带有范围标题(查看 iTunes 商店指南 例如播客),所以我不会很快期待它

所以问:Is there a way to stop the avplayer sending a range http header field

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    相关资源
    最近更新 更多