Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

panic! when I use ffmpeg as rtsp publisher to forward Cam's rtsp stream #18

Open
falconray0704 opened this issue Mar 13, 2018 · 2 comments

Comments

@falconray0704
Copy link

  1. build and run rtsp server
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ go build -o rtspServer main.go
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ ll
    total 56912
    drwxrwxr-x 9 ray ray 4096 Mar 13 15:11 ./
    drwxrwxr-x 4 ray ray 4096 Jun 27 2017 ../
    drwxrwxr-x 2 ray ray 4096 Jun 27 2017 auth/
    -rw-rw-r-- 1 ray ray 29 Jun 27 2017 AUTHORS
    drwxrwxr-x 2 ray ray 4096 Jun 27 2017 examples/
    drwxrwxr-x 8 ray ray 4096 Mar 13 14:01 .git/
    -rw-rw-r-- 1 ray ray 7 Nov 12 10:29 .gitignore
    drwxrwxr-x 2 ray ray 4096 Jun 27 2017 groupsock/
    -rw-rw-r-- 1 ray ray 26461 Jun 27 2017 LICENSE
    drwxrwxr-x 2 ray ray 4096 Nov 12 10:29 livemedia/
    -rw-rw-r-- 1 ray ray 1510 Nov 12 10:29 main.go
    -rwxrwxr-x 1 ray ray 63 Jun 27 2017 makefile*
    -rwxrwxr-x 1 ray ray 293 Jun 27 2017 make.sh*
    -rw-rw-r-- 1 ray ray 1859 Jun 27 2017 README.md
    drwxrwxr-x 2 ray ray 4096 Jun 27 2017 rtspclient/
    drwxrwxr-x 2 ray ray 4096 Jun 27 2017 rtspserver/
    -rwxrwxr-x 1 ray ray 10575626 Mar 13 15:11 rtspServer*
    -rw-r--r-- 1 ray ray 47605074 Mar 13 14:26 testVideo.h264
    -rw-rw-r-- 1 ray ray 57 Jun 27 2017 .travis.yml
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ ./rtspServer
    We use port 80 for optional RTSP-over-HTTP tunneling, or for HTTP live streaming (for indexed Transport Stream files only).
    This server's URL: rtsp://192.168.223.1:8554/.
    2018/03/13 15:12:05 [I] Received 91 new bytes of request data.
    2018/03/13 15:12:05 [I] Received a complete OPTIONS request:
    OPTIONS rtsp://192.168.223.1:8554/live.sdp RTSP/1.0
    CSeq: 1
    User-Agent: Lavf56.40.101

2018/03/13 15:12:05 [I] send response:
RTSP/1.0 200 OK
CSeq: 1
Date: 2018-03-13 15:12:05.295121783 +0800 CST m=+7.931249137
Public: [OPTIONS DESCRIBE SETUP TEARDOWN PLAY PAUSE RECORD GET_PARAMETER SET_PARAMETER]

2018/03/13 15:12:05 [I] Received 144 new bytes of request data.
panic: runtime error: slice bounds out of range

goroutine 34 [running]:
github.com/djwackey/dorsvr/livemedia.ParseRTSPRequestString(0xc420182240, 0x90, 0x90, 0x1, 0x1)
/md/gows/src/github.com/djwackey/dorsvr/livemedia/common.go:161 +0xc27
github.com/djwackey/dorsvr/rtspserver.(*RTSPClientConnection).handleRequestBytes(0xc420154100, 0xc420170000, 0x2710, 0x2710, 0x90, 0x0, 0x0)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/connection.go:88 +0x148
github.com/djwackey/dorsvr/rtspserver.(*RTSPClientConnection).incomingRequestHandler(0xc420154100)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/connection.go:57 +0x2e0
github.com/djwackey/dorsvr/rtspserver.(*RTSPServer).newClientConnection(0xc42013c100, 0xaa2e20, 0xc420158010)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/server.go:131 +0x5c
created by github.com/djwackey/dorsvr/rtspserver.(*RTSPServer).incomingConnectionHandler
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/server.go:124 +0x139
ray@TF:/md/gows/src/github.com/djwackey/dorsvr$

  1. forward Cam's rtsp stream with ffmpeg
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ ffmpeg -i rtsp://yt:[email protected]:554/h264/ch1/main/av_stream -c:v libx264 -c:a aac -strict -2 -f rtsp -rtsp_transport tcp rtsp://192.168.223.1:8554/live.sdp
    ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
    built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
    configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
    libavutil 54. 31.100 / 54. 31.100
    libavcodec 56. 60.100 / 56. 60.100
    libavformat 56. 40.101 / 56. 40.101
    libavdevice 56. 4.100 / 56. 4.100
    libavfilter 5. 40.101 / 5. 40.101
    libavresample 2. 1. 0 / 2. 1. 0
    libswscale 3. 1.101 / 3. 1.101
    libswresample 1. 2.101 / 1. 2.101
    libpostproc 53. 3.100 / 53. 3.100
    Invalid UE golomb code
    Last message repeated 3 times
    [h264 @ 0x1ae6bc0] RTP: missed 2 packets
    [h264 @ 0x1ae6bc0] RTP: missed 4 packets
    [pcm_alaw @ 0x1ae7a20] RTP: missed 1 packets
    Guessed Channel Layout for Input Stream #0.1 : mono
    Input #0, rtsp, from 'rtsp://yt:[email protected]:554/h264/ch1/main/av_stream':
    Metadata:
    title : Media Presentation
    Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709), 1920x1080, 25 fps, 25 tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s
    No pixel format specified, yuvj420p for H.264 encoding chosen.
    Use -pix_fmt yuv420p for compatibility with outdated media players.
    [libx264 @ 0x1d3ee20] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0x1d3ee20] profile High, level 4.0
    [libx264 @ 0x1d3ee20] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    [aac @ 0x1c4a540] Too many bits per frame requested, clamping to max
    Output #0, rtsp, to 'rtsp://192.168.223.1:8554/live.sdp':
    Metadata:
    title : Media Presentation
    encoder : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264), yuvj420p(pc), 1920x1080, q=-1--1, 25 fps, 25 tbn, 25 tbc
    Metadata:
    encoder : Lavc56.60.100 libx264
    Stream #0:1: Audio: aac, 8000 Hz, mono, fltp, 48 kb/s
    Metadata:
    encoder : Lavc56.60.100 aac
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Stream #0:1 -> #0:1 (pcm_alaw (native) -> aac (native))
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$
@falconray0704
Copy link
Author

try another publish case:

  1. rtsp server
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ ./rtspServer
    We use port 80 for optional RTSP-over-HTTP tunneling, or for HTTP live streaming (for indexed Transport Stream files only).
    This server's URL: rtsp://192.168.223.1:8554/.
    2018/03/13 15:32:09 [I] Received 87 new bytes of request data.
    2018/03/13 15:32:09 [I] Received a complete OPTIONS request:
    OPTIONS rtsp://192.168.223.1:8554/live RTSP/1.0
    CSeq: 1
    User-Agent: Lavf56.40.101

2018/03/13 15:32:09 [I] send response:
RTSP/1.0 200 OK
CSeq: 1
Date: 2018-03-13 15:32:09.607583822 +0800 CST m=+16.769782397
Public: [OPTIONS DESCRIBE SETUP TEARDOWN PLAY PAUSE RECORD GET_PARAMETER SET_PARAMETER]

2018/03/13 15:32:09 [I] Received 140 new bytes of request data.
panic: runtime error: slice bounds out of range

goroutine 18 [running]:
github.com/djwackey/dorsvr/livemedia.ParseRTSPRequestString(0xc42018e120, 0x8c, 0x8c, 0x1, 0x1)
/md/gows/src/github.com/djwackey/dorsvr/livemedia/common.go:161 +0xc27
github.com/djwackey/dorsvr/rtspserver.(*RTSPClientConnection).handleRequestBytes(0xc420164080, 0xc420174000, 0x2710, 0x2710, 0x8c, 0x0, 0x0)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/connection.go:88 +0x148
github.com/djwackey/dorsvr/rtspserver.(*RTSPClientConnection).incomingRequestHandler(0xc420164080)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/connection.go:57 +0x2e0
github.com/djwackey/dorsvr/rtspserver.(*RTSPServer).newClientConnection(0xc420128100, 0xaa2e20, 0xc420168000)
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/server.go:131 +0x5c
created by github.com/djwackey/dorsvr/rtspserver.(*RTSPServer).incomingConnectionHandler
/md/gows/src/github.com/djwackey/dorsvr/rtspserver/server.go:124 +0x139
ray@TF:/md/gows/src/github.com/djwackey/dorsvr$

  1. ffmpeg publish:
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$ ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://yt:[email protected]:554/h264/ch1/main/av_stream -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a copy -strict experimental -f rtsp -rtsp_transport tcp rtsp://192.168.223.1:8554/live
    ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
    built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
    configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
    libavutil 54. 31.100 / 54. 31.100
    libavcodec 56. 60.100 / 56. 60.100
    libavformat 56. 40.101 / 56. 40.101
    libavdevice 56. 4.100 / 56. 4.100
    libavfilter 5. 40.101 / 5. 40.101
    libavresample 2. 1. 0 / 2. 1. 0
    libswscale 3. 1.101 / 3. 1.101
    libswresample 1. 2.101 / 1. 2.101
    libpostproc 53. 3.100 / 53. 3.100
    Input #0, lavfi, from 'anullsrc':
    Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #0:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
    Invalid UE golomb code
    Last message repeated 1 times
    Guessed Channel Layout for Input Stream ANNOUNCE Method Not Allowed #1.1 : mono
    Input ANNOUNCE Method Not Allowed #1, rtsp, from 'rtsp://yt:[email protected]:554/h264/ch1/main/av_stream':
    Metadata:
    title : Media Presentation
    Duration: N/A, start: 0.000000, bitrate: N/A
    Stream ANNOUNCE Method Not Allowed #1:0: Video: h264 (Main), yuvj420p(pc, bt709), 1920x1080, 25 fps, 25 tbr, 90k tbn, 180k tbc
    Stream ANNOUNCE Method Not Allowed #1:1: Audio: pcm_alaw, 8000 Hz, 1 channels, s16, 64 kb/s
    [rtsp @ 0x24540e0] Codec for stream 0 does not use global headers but container format requires global headers
    [rtsp @ 0x24540e0] Codec for stream 1 does not use global headers but container format requires global headers
    Output #0, rtsp, to 'rtsp://192.168.223.1:8554/live':
    Metadata:
    encoder : Lavf56.40.101
    Stream #0:0: Video: h264, yuvj420p, 1920x1080, q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
    Stream #0:1: Audio: pcm_u8, 44100 Hz, stereo, 705 kb/s
    Stream mapping:
    Stream ANNOUNCE Method Not Allowed #1:0 -> #0:0 (copy)
    Stream #0:0 -> #0:1 (copy)
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
    ray@TF:/md/gows/src/github.com/djwackey/dorsvr$

@porjo
Copy link

porjo commented Aug 15, 2018

The panic is due to a bug in the string handling in livemedia/common.go line 161

if n, _ := fmt.Sscanf(reqStr[j:j+15], "%d", &reqInfo.ContentLength); n == 1 {

Probably should be fmt.Sscanf(reqStr[j:],... but then handling strings like this is pretty ugly - rtsp protocol header should be parsed out into a map instead.

With that fixed, sending a stream from ffmpeg results in error: [rtsp @ 0x55e34be02180] method ANNOUNCE failed: 405 Method Not Allowed...it would appear this isn't supported

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants