我有一个 mp4 文件,我希望通过 RTSP 对其进行压缩、调整大小和流式传输。
我的 ffserver.conf 文件如下所示:
Port 9091
RTSPPort 5454
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
NoDaemon
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 500M
</Feed>
<Stream live.mpeg>
Format rtp
File "/tmp/rtp.mp4"
Feed feed1.ffm
VideoCodec mpeg2video
VideoFrameRate 15
VideoBitRate 200
VideoSize 400x320
#AudioCodec mp2
#AudioBitRate 32
#AudioChannels 2
#AudioSampleRate 22050
NoAudio
#Preroll 10
ACL allow 127.0.0.1
</Stream>
<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
据我了解,我不需要使用 ffmpeg 输入视频流,因为我正在使用 File 属性,所以 ffserver 为我工作?
当我尝试使用 totem 播放视频时(ffplay 只是超时),我收到以下错误:
$ totem rtsp://127.0.0.1:5454/live.mpeg
** Message: Error: Could not read from resource.
gstrtspsrc.c(4408): gst_rtspsrc_send (): /GstPlayBin2:play/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Got error response: 454 (Session Not Found).
ffserver 的日志是这样的:
$ ffserver -f /tmp/ffserver.conf
FFserver version 0.6-4:0.6-2ubuntu6, Copyright (c) 2000-2010 the FFmpeg developers
built on Oct 5 2010 22:36:53 with gcc 4.4.5
configuration: --extra-version=4:0.6-2ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
WARNING: library configuration mismatch
libavutil configuration: --extra-version=4:0.6-2ubuntu3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libdirac --enable-libgsm --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-libmp3lame --enable-gpl --enable-postproc --enable-x11grab --enable-libfaad --enable-libxvid --enable-libx264 --enable-librtmp --enable-libdc1394 --enable-shared --disable-static
libavcodec configuration: --extra-version=4:0.6-2ubuntu3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libdirac --enable-libgsm --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-libmp3lame --enable-gpl --enable-postproc --enable-x11grab --enable-libfaad --enable-libxvid --enable-libx264 --enable-librtmp --enable-libdc1394 --enable-shared --disable-static
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 0.11. 0 / 0.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
Sun Oct 10 12:37:20 2010 FFserver started.
Sun Oct 10 12:38:34 2010 127.0.0.1 - - [DESCRIBE] "rtsp://127.0.0.1:5454/live.mpeg RTSP/1.0" 200 166
Sun Oct 10 12:38:38 2010 127.0.0.1:51118 - - "PLAY live.mpeg/streamid=0 RTP/UDP"
Sun Oct 10 12:38:38 2010 127.0.0.1 - - [] " RTP/UDP" 200 0
Sun Oct 10 12:38:43 2010 127.0.0.1 - - [TEARDOWN] "rtsp://127.0.0.1:5454/live.mpeg RTSP/1.0" 200 819
Sun Oct 10 12:38:43 2010 127.0.0.1:0 - - "PLAY live.mpeg/streamid=0 RTP/TCP"
Sun Oct 10 12:38:43 2010 127.0.0.1 - - [] " RTP/TCP" 200 0
Sun Oct 10 12:38:54 2010 127.0.0.1 - - [PLAY] "rtsp://127.0.0.1:5454/live.mpeg RTSP/1.0" 200 621
我究竟做错了什么?
您可以使用 gstreamer 实现调整大小、重新编码为 mpeg2 和 RTSP 流,但我没有设法更改帧速率。如果这足够了,方法如下:
sudo apt-get install libgstrtspserver-0.10-dev
gcc -o test-launch $(pkg-config --cflags --libs gstreamer-0.10 gst-rtsp-server-0.10) test-launch.c
./test-launch "( filesrc location=/tmp/rtp.mp4 ! decodebin ! videoscale ! video/x-raw-yuv,width=400,height=320 ! ffenc_mpeg2video ! mpegtsmux ! rtpmp2tpay name=pay0 pt=96 )"
gst-launch-0.10 rtspsrc location=rtsp://127.0.0.1:8554/test ! decodebin ! xvimagesink
一些警告:
gst_rtsp_server_set_port(server, 9091);
在 test-launch.c 中的第 44 行和第 45 行之间添加一个调用