ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.79k stars 5.28k forks source link

Support FFmpeg timecode, fix AMF0 parsing failed. #3803

Closed winlinvip closed 9 months ago

winlinvip commented 9 months ago

See Error submitting a packet to the muxer: Broken pipe, Error muxing a packet

Test using the file timecode.mp4.zip or below:

https://github.com/ossrs/srs/assets/2777660/d50947a7-996a-4364-9593-3fb559b8e740

Use this FFmpeg command:

ffmpeg -re -i timecode.mp4 -map 0 -c copy -f flv rtmp://localhost/live/livestream

SRS will fail with this error:

[2023-09-18 11:25:37.576][ERROR][79462][910ul5n0][4] serve error code=2003(Amf0Decode)(Decode AMF0 message failed) : service cycle : rtmp: stream service : rtmp: receive thread : handle publish message : rtmp: consume message : rtmp: decode message : decode message : decode command name : String invalid marker=0
thread [79462][910ul5n0]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:263][errno=4]
thread [79462][910ul5n0]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:457][errno=4]
thread [79462][910ul5n0]: do_publishing() [./src/app/srs_app_rtmp_conn.cpp:1030][errno=35]
thread [79462][910ul5n0]: consume() [./src/app/srs_app_recv_thread.cpp:380][errno=35]
thread [79462][910ul5n0]: handle_publish_message() [./src/app/srs_app_rtmp_conn.cpp:1185][errno=35]
thread [79462][910ul5n0]: process_publish_message() [./src/app/srs_app_rtmp_conn.cpp:1230][errno=35]
thread [79462][910ul5n0]: decode_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:384][errno=35]
thread [79462][910ul5n0]: do_decode_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:607][errno=35]
thread [79462][910ul5n0]: srs_amf0_read_string() [./src/protocol/srs_protocol_amf0.cpp:1513][errno=35](Interrupted system call)

Here's the pcap file:

rtmp-amf0-invalid.pcapng.zip

winlinvip commented 9 months ago

Examine the pcap file, where FFmpeg sends AMF0 data, but it doesn't begin with the AMF0 string:

Packet #72:
04 00 00 64 00 00 04 12 01 00 00 00

Packet #74:
00 01 a5 e0

(lldb) p *msg
(SrsCommonMessage) $0 = {
  header = {
    timestamp_delta = 100
    payload_length = 4
    message_type = '\x12' 18 '\x12'
    stream_id = 1
    timestamp = 100
    perfer_cid = 4
  }
  size = 4
  payload = 0x0000602000003570 ""
}
(lldb) x/4xb msg->payload
0x602000003570: 0x00 0x01 0xa5 0xe0

SRS should be able to handle this message by simply ignoring it:

[2023-09-18 11:38:45.099][WARN][91322][148t53jz][35] Ignore FFmpeg timecode, data=[00 01 a5 e0]

image