vlc文件服务器,用vlc搭建简单流媒体服务器(UDP和TCP方式)(示例代码)

这段时间用到了流媒体数据传输的TCP和UDP方式,感觉vlc可以做这方面的demo,这里总结下,也方便我以后查阅。

简介

VLC不仅仅是个播放器,也可以作为流媒体服务器使用。这个网上有相关的资料,我就不多说了。

声明下本文用的VLC版本:2.0.3

用VLC搭建基于UDP的流媒体服务器

流媒体服务器大多数是基于UDP的,这个在VLC中也有好几种实现,我这里只列出我用到的几个。

1、UDP(legacy)传统模式

服务端操作

打开“媒体——流”选项,如图所示:

e26056282e55438a9041fb6709fdb799.jpg

点击“添加”按钮选择流媒体文件,然后点击“串流”按钮

32f564fd13144691b921aa786eaba56c.jpg

点击“下一个”后,在“目标设置”界面选择“UDP (legacy)”,然后点击添加按钮

fcd1d418441f40fbbbe991590a31a59e.jpg

填上目标ip地址,并在“转码选项”中选择相应的编码类型

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、 编译安装VLC 使用vlc-1.0.5.tar.bz2 + live555-2010.01.tar.gz export MYDIR=/root/lf 将live555-2010.01.tar.gz和vlc-1.0.5.tar.bz2放置在$MYDIR下 cd $MYDIR (一) 编译liveMedia tar xvfz live555-2010.01.tar.gz cd live ./genMakefiles linux make (二) 安装libdvbpsi rpm -hiv libdvbpsi-0.1.7-1.el4.rf.i386.rpm rpm -hiv libdvbpsi-devel-0.1.7-1.el4.rf.i386.rpm 需要什么rpm可到http://apt.sw.be/redhat/el4/en/i386/rpmforge/RPMS/中下载 (三) 编译VLC 1. configure ./configure --prefix=/usr --enable-debug --disable-avcodec --disable-hal --disable-avformat --disable-swscale --disable-a52 --disable-x11 --disable-sdl --disable-fribidi --disable-dbus --disable-libgcrypt --disable-gnutls --disable-remoteosd --disable-skins2 --disable-qt4 --disable-libxml2 --disable-lua --disable-xcb --disable-alsa --disable-v4l2 --disable-qt --enable-run-as-root --enable-live555 --with-live555-tree=$MYDIR/live --disable-mad --disable-postproc --enable-dvbpsi --enable-x264 2. make 3. 出现错误error: syntax error before "vlc_spinlock_t": ../include/vlc_threads.h:240: error: syntax error before "vlc_spinlock_t" …… make[4]: *** [control/libvlc_la-vlm.lo] Error 1 make[4]: Leaving directory `/root/lf/vlc-1.0.5/src' make[3]: *** [all-recursive] Error 1 make[3]: Leaving directory `/root/lf/vlc-1.0.5/src' make[2]: *** [all] Error 2 make[2]: Leaving directory `/root/lf/vlc-1.0.5/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/root/lf/vlc-1.0.5' make: *** [all] Error 2 通过以下命令解决: sed -e 's/define\s*_POSIX_SPIN_LOCKS\s*/define _POSIX_SPIN_LOCKS -1 \/\/ wrong: /g' -i /usr/include/bits/posix_opt.h 4. 重试make出现error: `AFS_SUPER_MAGIC' undeclared: file.c:52:28: linux/magic.h: No such file or directory file.c: In function `IsRemote': file.c:141: error: `AFS_SUPER_MAGIC' undeclared (first use in this function) file.c:141: error: (Each undeclared identifier is reported only once file.c:141: error: for each function it appears in.) file.c:142: error: `CODA_SUPER_MAGIC' undeclared (first use in this function) file.c:143: error: `NCP_SUPER_MAGIC' undeclared (first use in this function) file.c:144: error: `NFS_SUPER_MAGIC' undeclared (first use in this function) file.c:145: error: `SMB_SUPER_MAGIC' undeclared (first use in this function) make[5]: *** [libaccess_file_plugin_la-file.lo] Error 1 make[5]: Leaving directory `/root/lf/vlc-1.0.5/modules/access' make[4]: *** [all-recursive] Error 1 make[4]: Leaving directory `/root/lf/vlc-1.0.5/modules/access' make[3]: *** [all] Error 2 make[3]: Leaving directory `/root/lf/vlc-1.0.5/modules/access' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/root/lf/vlc-1.0.5/modules' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/root/lf/vlc-1.0.5' make: *** [all] Error 2 将下面的magic.h文件复制到/usr/include/linux/目录下 5. make install 6. 检查 vlc -l | grep access_output access_output_udp UDP stream output access_output_http HTTP stream output access_output_file File stream output access_output_dummy Dummy stream output access_output_rtmp RTMP stream output vlc -l | grep dvbpsi mux_ts TS muxer (libdvbpsi) (四) 进行RTSP To TS转码:  不经视音频重编码的直接转码: vlc rtsp://172.17.0.219:8554/1 --sout '#standard{access=http, mux=ts, dst=172.17.0.100:1234}' 注:黑体部分为本机IP和端口,不能是127.0.0.1 vlc rtsp://172.17.0.219:8554/1 --sout '#duplicate{dst="std{access=udp, mux=ts, dst=172.17.1.116:1234}"}' vlc rtsp://172.17.0.219:8554/1 --sout '#duplicate{dst="std{access=http, mux=ts, dst=172.17.0.100:1234}"}' 二、 视音频重编码的VLC编译安装 (一) 需要编译安装ffmpeg ./configure --prefix=/usr --enable-libfaac --enable-libx264 --enable-pthreads --disable-ffserver --disable-ffplay --enable-gpl --enable-nonfree [root@localhost ffmpeg-0.6.7]# make common.mak:28: *** unterminated call to function `foreach': missing `)'. Stop. 出现上面错误需要更新Make版本,使用make-3.81.tar.gz ./configure --prefix=/usr;make;make install In file included from libavdevice/v4l.c:33: /usr/include/linux/videodev.h:56: error: syntax error before "ulong" /usr/include/linux/videodev.h:72: error: syntax error before '}' token 编辑/usr/include/linux/videodev.h第56行,把ulong改为 unsigned long (二) 编译VLC ./configure --prefix=/usr --enable-debug --enable-avcodec --disable-hal --disable-avformat --disable-swscale --disable-a52 --disable-x11 --disable-sdl --disable-fribidi --disable-dbus --disable-libgcrypt --disable-gnutls --disable-remoteosd --disable-skins2 --disable-qt4 --disable-libxml2 --disable-lua --disable-xcb --disable-alsa --disable-v4l2 --disable-qt --enable-run-as-root --enable-live555 --with-live555-tree=$MYDIR/live --disable-mad --disable-postproc --enable-dvbpsi --enable-x264 没有--enable-avcodec运行VLC转码会出现"cannot find video decoder"的错误。 (三) 进行RTSP To TS转码: vlc tcp://172.17.0.199:7799 --sout '#duplicate{dst="transcode{venc=x264{profile=baseline},vcodec=h264,acodec=mpga,vb=644,ab=56}:std{access=udp,mux=ts,dst=172.17.0.219:1234}"}' 使用VLC转时,不要激活转码 可正常工作的选项: :sout=#http{mux=ts,dst=:8080/1} :sout-keep :sout=#udp{mux=ts,dst=172.17.1.116:1234} :sout-keep http://www.videolan.org/doc/videolan-howto/en/ch09.html ffmpeg -i "rtsp://172.17.0.219:8554/1" -acodec libfaac -vcodec libx264 -vpre default -f mpegts -async 1 udp://127.0.0.1:3344 ./configure --prefix=/usr --enable-libfaac --enable-libx264 --enable-pthreads --disable-ffserver --disable-ffplay --enable-gpl --enable-nonfree 转码 ffmpeg -i "rtsp://172.17.0.219:8080/1" -acodec libfaac -vcodec libx264 -vpre default -f mpegts -async 1 udp://172.17.0.219:3344
openrtxp是一个小型的rtsp/rtmp协议的rtxpserver, ANSI C语言开发,方便移植到嵌入式系统如IPCam. 功能list: (1)支持H264 + AAC编码格式封包成RTSP/RTMP,可以使用VLC/VLC网页控件播放,RTMP可以用VLC/flash player/kmplayer播放. 支持RTP over TCP/UDP. (2)RTSP/RTMP的URL可配置,缺省URL如下: VOD点播(文件回放):rtsp://192.168.2.62/playback/test.mp4 直播:rtsp://192.168.2.62/stream/0 RTMP的url和RTSP一致,只需要把"rtsp"修改为"rtmp" 图像延迟在250ms左右. (4)同时支持基于UDP/TCP的TS流直播. (5)移植很方便,只需要编写约7个直播流获取Audio/Video的函数即可. (6)支持DVR功能,通过简单的调用,即可实现把直播流保存到硬盘中(支持.mp4/.ts格式) (7)所有代码为纯C代码,可移植性强。 移植很方便,只需要编写约7个直播流获取Audio/Video的函数即可. int liveInit(); int liveUninit(); void* liveCreate(char* filename,void* prv,double* duration,unsigned int* video_codec,unsigned int* video_width,unsigned int* video_height,unsigned int* video_fps,unsigned int* video_bps,unsigned int* audio_codec,unsigned int* audio_samplerate,unsigned int* audio_channels,unsigned int* audio_bps); int liveGetHeaderPacket(void* hdl,int data_type,char* buf); int liveGetVideoPacket(void* hdl,char* buf,double* pts,int* sync); int liveGetAudioPacket(void* hdl,char* buf,double* pts); int liveDestroy(void* hdl); FAQ: 1.为什么要用ffmpeg和ssl? 答:ssl是rtmp协议要用到。ts流,mp4文件都是由ffmpeg中的方法来实现的。如果去掉这两个lib,就支持不了rtmp,.ts,.mp4等功能。 libssl和libcrypto则是rtmp要使用的,修改configs.h 和Makefile就可以很容易地去掉。 playback/DVR/TS功能要用到ffmpeg lib的支持,修改configs.h和Makefile也很容易去掉ffmpeg,但这三项功能就实现不了。 去掉openssl和ffmpeg后,编译出来的image size在83KB左右。 2.如何支持底层的多通道?比如一个是1080P ch,一个是CIF ch. 答:通过live->idx = idx=atoi(filename);来区分不同的hw path。 3.如何支持多session或多个client连接? 答:来一个session,就调用liveCreate()来生成一个live实体。 liveCreate()的时候每次都是malloc()一个新的instance,那个instance包含一个h264enc指针和一个rd。 h264enc指针内部有一个wr,也就是说所有的流都共享一个h264enc指针,但每个流的rd是独立的。 第二次liveCreate()的时候,h264enc指针已经有了,就不需要再次建立h264enc指针了,直接引用就可以了(因此h264enc内部要做引用计数) 每多调用一次liveCreate(),h264enc->ref++。 每调用一次liveDestroy(),就h264enc->ref--,==0的时候就真正destroy h264enc。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值