Skip to content

Commit d978ffe

Browse files
committed
[fix] worked around the buggy option -map in FFmpeg (#245).
1 parent a13c92c commit d978ffe

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ngx_rtmp_receive.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s,
360360
ngx_rtmp_core_main_conf_t *cmcf;
361361
ngx_array_t *ch;
362362
ngx_rtmp_handler_pt *ph;
363+
ngx_chain_t *cl;
364+
ngx_int_t amf_len;
363365
size_t len, n;
364366

365367
static u_char func[128];
@@ -393,6 +395,31 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s,
393395

394396
cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module);
395397

398+
/*
399+
* work around the buggy option `-map` in FFmpeg, see:
400+
* https://trac.ffmpeg.org/ticket/10565
401+
*/
402+
if (in->buf->pos[0] == NGX_RTMP_AMF_NUMBER) {
403+
cl = in;
404+
amf_len = 0;
405+
406+
while (cl) {
407+
amf_len += cl->buf->last - cl->buf->pos;
408+
if (amf_len >= 8) {
409+
break;
410+
}
411+
412+
cl = cl->next;
413+
}
414+
415+
if (amf_len < 8) {
416+
ngx_log_error(NGX_LOG_WARN, s->connection->log, 0,
417+
"AMF malformed: type=%d, length=%D, ignored",
418+
NGX_RTMP_AMF_NUMBER, amf_len);
419+
return NGX_OK;
420+
}
421+
}
422+
396423
/* read AMF func name & transaction id */
397424
ngx_memzero(&act, sizeof(act));
398425
act.link = in;

0 commit comments

Comments
 (0)