问题
I try to save RTSP h.264 stream to HLS mp4 files:
gst-launch-1.0 rtspsrc location="rtsp://....." ! rtph264depay ! h264parse ! matroskamux ! hlssink max-files=0 playlist-length=0 location="/home/user/ch%05d.mp4" playlist-location="/home/user/list.m3u8" target-duration=15
As a result - there is only one file ch00000.mp4, which includes the whole videostream (3min instead of 15sec in "target-duration").
If I save to mpegtsmux / ts files - all is ok for the same command.
What is wrong? Thanks in advance.
回答1:
HLS consists of MPEG transport stream segments. So first: matroskamux
does not make sense here. You will need mpegtsmux
instead. To indicate what it really is you normally would name the files with a .ts
extension. It may still work for GStreamer as it is just a file name - players may reject playing it because the expect another sort of file format.
E.g.
gst-launch-1.0 rtspsrc location="rtsp://....." ! rtph264depay ! h264parse ! \
mpegtsmux ! hlssink max-files=0 playlist-length=0 location="/home/user/ch%05d.ts" \
playlist-location="/home/user/list.m3u8" target-duration=15
回答2:
Do you have to use gstreamer? Otherwise I believe this ffmpeg command does what you want.
ffmpeg -i rtsp://... -c copy -hls_list_size 10 -hls_segment_type fmp4 output.m3u8
来源:https://stackoverflow.com/questions/55163360/gstreamer-rtsp-to-hls-mp4