RTMP playback fails when using videotoolbox
Operating System: macOS 10.13.6
VLC Version 3.0.3 and vlc-3.0.4-20180805-0710 nightly
Hardware: MacBook Pro 15-inch, 2017
Logs are attached in file upload, logs created from command line output with -vvv switch.
Repro step:
VLC displays only a single frame when playing back an RTMP stream encoded with Apple's VideoToolbox framework. Audio works fine.
For a server, I'm using nginx with the RTMP plugin from https://github.com/arut/nginx-rtmp-module. It can be installed with Docker (https://hub.docker.com/r/jasonrivers/nginx-rtmp/) if containers are your thing. I have not tried other servers, but can confirm other stream providers work with this setup, so I don't think the server is of consequence.
The stream is generated using HaishinKit (https://github.com/shogo4405/HaishinKit.swift). The HaishinKit repo provides a sample project you can use on iOS. The destination of the stream can be quickly set in Examples/iOS/Preference.swift (https://github.com/shogo4405/HaishinKit.swift/blob/master/Examples/iOS/Preference.swift). When the sample project is started, there are two blue buttons in the lower right of the window. The one with a white cicle starts the stream.
With HashinKit streaming I open a connection in VLC using File -> Open Network... and using rtmp://ipaddress/live/steamname
. The -vvv console output is attached. The thing that stands out to me in the console output is:
[00007fc397666800] main decoder error: Timestamp conversion failed (delay 1000000, buffering 100000, bound 9000000)
[00007fc397666800] main decoder error: Could not convert timestamp 30545801958 for videotoolbox
RTMP includes some timestamp delta in the headers, but, as far as I can tell the error message VLC is producing in the console relates to a timestamp in the encoded video. As mentioned above HaishinKit is using Apple's VideoToolbox to encode the video. The relevant code is in https://github.com/shogo4405/HaishinKit.swift/blob/master/Sources/Codec/H264Encoder.swift. The encoder calls VTCompressionSessionEncodeFrame
around line 250. The VTCompressionSessionEncodeFrame
call requires a CMTime value as the third parameter. This seems to be the timestamp that's appearing in the console output. I've fiddled around with the VTCompressionSession
parameters but haven't had any luck getting playback working in VLC.
I'm pretty sure the root of the problem is somewhere in vlc/modules/codec/videotoolbox.m. A stream created with HaishinKit will playback fine on VLC 2.x for macOS which, as far as I can tell, does not include the videotoolbox module. The stream will also playback fine on a VLC 3.0.3 install on Linux, which also does not have access to videotoolbox.
Other notes:
I've tried using OBS (https://obsproject.com) to stream and it works fine. I believe OBS is using ffmpeg to encode the video, and it decodes fine using the VLC videotoolbox module. I used tcpdump to log the network traffic and did notice that OBS sends some config information in the @setDataFrame() call as an array, where HaishinKit, and the RTMP ‘spec’ say it should be a Javascrip object.
I thought there may have been an issue with the audio and video timestamps being out of sync from the source of the stream, but commenting out the lines to send audio has the same result.
This does happen every time.
Please let me know if there is any other information I can provide that would be helpful.