sergey-dryabzhinsky / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
1.02k stars 215 forks source link

rtmp works but hls sometimes does not work #263

Open dodolzg opened 6 years ago

dodolzg commented 6 years ago

Here is my config

application dev_hls_camera { live on; hls on; hls_path /static/cdn/dev/hls; hls_nested on; hls_fragment 3s; hls_max_fragment 6s; hls_playlist_length 360000s; hls_cleanup off; drop_idle_publisher 10s; }

Video is recorded by chrome H5 API MediaRecorder with "video/webm\;codecs=h264"

ffprobe version 3.3.2 Copyright (c) 2007-2017 the FFmpeg developers built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-9) configuration: --extra-cflags=-I/usr/local/ffmpeg/include --extra-ldflags=-L/usr/local/ffmpeg/lib --pkg-config-flags=--static --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-libvpx --enable-libx264 --prefix=/usr/local/ffmpeg --extra-libs=-ldl libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 Input #0, matroska,webm, from '1.webm': Metadata: encoder : Chrome Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default) Stream #0:1(eng): Video: h264 (Constrained Baseline), yuv420p(progressive), 1360x768, SAR 1:1 DAR 85:48, 16.67 tbr, 1k tbn, 2k tbc (default)

Case 1:

/usr/local/ffmpeg/bin/ffmpeg -re -i 1.webm -acodec aac -vcodec copy -f flv rtmp://localhost:1935/dev_hls_camera/test1

rtmp works, hls works about previous 10 seconds, but there is no video after 10s (only audio).

Case 2:

/usr/local/ffmpeg/bin/ffmpeg -re -i 1.webm -acodec aac -vcodec libx264 -f flv rtmp://localhost:1935/dev_hls_camera/test2

rtmp works, hls works.

Does nginx-rtmp support "h264 (Constrained Baseline)", Or only support "libx264"?

Frames detail Video url

dodolzg commented 6 years ago

Maybe there is same problem NALU

dodolzg commented 6 years ago

I found that it is composed of SPS+PPS+IDR after analysised the h264stream. There is no AUD NAL unit at the beginning of each PES packet. And I rechecked the spec ——

"Access Unit Delimiter (AUD). An AUD is an optional NALU that can be use to delimit frames in an elementary stream. It is not required (unless otherwise stated by the container/protocol, like TS), and is often not included in order to save space, but it can be useful to finds the start of a frame without having to fully parse each NALU."

Can nginx-rtmp-module support this case?

dodolzg commented 6 years ago

libx264 vs copy libx264-1.ts is sliced by libx264 rtmp stream(-vcodec libx264), and there are SPS+PPS+IDR_SLICE frames copy-1.ts is sliced by libx264 rtmp stream(-vcodec copy), and there are no SPS+PPS+IDR_SLICE frames

ffprobe -i copy-1.ts shows error info

[h264 @ 0x3fd7600] decode_slice_header error [h264 @ 0x3fd7600] no frame! [h264 @ 0x3fd7600] non-existing PPS 1 referenced Last message repeated 1 times

portokala123 commented 6 years ago

Hi, did you try to add -bsf:v h264_mp4toannexb to your command?

dodolzg commented 6 years ago

@portokala123 same with case1, hls works about previous 10 seconds, but there is no video after 10s (only audio).

/usr/local/ffmpeg/bin/ffmpeg -re -i 1.webm -acodec aac -vcodec copy -bsf:v h264_mp4toannexb -f flv rtmp://localhost:1935/dev_hls_camera/test3