TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
一. 用ffmpeg播放
ffserver
它有两个参数需要注意
-d --> enalbe debug mode
-f --> 指定配置文件的路径,如果没有-f参数则默认是/etc/ffserver.conf
1. ffmpeg编译完成后会生成
ffserver
ffmpeg
ffplay
ffserver.conf文件(ffmpeg源码下的doc目录中有ffserver.conf里面有详细解析)
HTTPPort 8091
HTTPBindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
<Feed feed1.ffm>
file /tmp/feed1.ffm -->缓冲文件的路径是/tmp/feed1.ffm
FileMaxSize 10M -->缓冲文件最大是10M
</Feed>
<Stream feed1.mjpeg>
Feed feed1.ffm
Format mjpeg
VideoSize 640x480
VideoFrameRate 10
VideoBitRate 2000
VideoQMin 1
VideoQMax 10
</Stream>
2. 运行结果
2.1 首先运行server端
cong@msi:/work/ffmpeg/out/bin$ ./ffserver -d -f ./ffserver.conf
ffserver version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --enable-shared --prefix=../out
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
./ffserver.conf:19: Setting default value for video bit rate tolerance = 500000. Use NoDefaults to disable it.
./ffserver.conf:19: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
./ffserver.conf:19: Setting default value for video max rate = 4000000. Use NoDefaults to disable it.
./ffserver.conf:19: Setting default value for video buffer size = 4000000. Use NoDefaults to disable it.
./ffserver.conf:50: Setting default value for video bit rate tolerance = 75000. Use NoDefaults to disable it.
./ffserver.conf:50: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
./ffserver.conf:50: Setting default value for video max rate = 600000. Use NoDefaults to disable it.
./ffserver.conf:50: Setting default value for video buffer size = 600000. Use NoDefaults to disable it.
Mon Sep 14 18:18:38 2015 Deleting feed file "/tmp/feed1.ffm" as stream counts differ (3 != 2)
Mon Sep 14 18:18:38 2015 FFserver started.
Mon Sep 14 18:18:51 2015 127.0.0.1 - - New connection: POST /feed1.ffm
Mon Sep 14 18:18:53 2015 127.0.0.1 - - [POST] "/feed1.ffm HTTP/1.1" 200 671744
2.2 然后在另一个终端运行ffmpeg
ffmpeg用来把本地摄像头中的数据转为feed1.ffm缓存起来
cong@msi:/work/ffmpeg/out/bin$ ./ffmpeg -v verbose -r 5 -s 640x480 -f video4linux2 -i /dev/video0 http://localhost:8091/feed1.ffm
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --enable-shared --prefix=../out
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
[video4linux2,v4l2 @ 0x115f180] fd:3 capabilities:84000001
Input #0, video4linux2,v4l2, from "/dev/video0":
Duration: N/A, start: 30290.856550, bitrate: 24576 kb/s
Stream #0:0: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 640x480, 24576 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
[tcp @ 0x11641e0] Connection to tcp://localhost:8091 failed (Connection refused), trying next address
[tcp @ 0x116c6a0] Connection to tcp://localhost:8091 failed (Connection refused), trying next address
[graph 0 input from stream 0:0 @ 0x1154680] w:640 h:480 pixfmt:yuyv422 tb:1/5 fr:5/1 sar:0/1 sws_param:flags=2
[scaler for output stream 0:0 @ 0x1165b60] w:640 h:480 flags:"0x4" interl:0
[graph 0 input from stream 0:0 @ 0x1154680] TB:0.200000 FRAME_RATE:5.000000 SAMPLE_RATE:nan
[swscaler @ 0x1141040] deprecated pixel format used, make sure you did set range correctly
[scaler for output stream 0:0 @ 0x1165b60] w:640 h:480 fmt:yuyv422 sar:0/1 -> w:640 h:480 fmt:yuvj422p sar:0/1 flags:0x4
[graph 1 input from stream 0:0 @ 0x1156a80] w:640 h:480 pixfmt:yuyv422 tb:1/5 fr:5/1 sar:0/1 sws_param:flags=2
[scaler for output stream 0:1 @ 0x1157b00] w:640 h:480 flags:"0x4" interl:0
[graph 1 input from stream 0:0 @ 0x1156a80] TB:0.200000 FRAME_RATE:5.000000 SAMPLE_RATE:nan
[scaler for output stream 0:1 @ 0x1157b00] w:640 h:480 fmt:yuyv422 sar:0/1 -> w:640 h:480 fmt:yuv420p sar:0/1 flags:0x4
Output #0, ffm, to "http://localhost:8091/feed1.ffm":
Metadata:
creation_time : now
encoder : Lavf56.36.100
Stream #0:0: Video: mjpeg, 1 reference frame, yuvj422p(pc), 640x480, q=1-10, 2000 kb/s, 5 fps, 1000k tbn, 10 tbc
Metadata:
encoder : Lavc56.41.100 mjpeg
Stream #0:1: Video: mpeg4, 1 reference frame, yuv420p, 640x480, q=2-51, 300 kb/s, 5 fps, 1000k tbn, 24 tbc
Metadata:
encoder : Lavc56.41.100 mpeg4
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Stream #0:0 -> #0:1 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
*** 1
*** 4
*** 1
*** 4
*** 1
*** 4
frame= 6 fps=0.0 q=1.6 Lq=12.8 size= 216kB time=00:00:00.62 bitrate=2831.2kbits/s dup=15 drop=0
video:210kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.969670%
Input file #0 (/dev/video0):
Input stream #0:0 (video): 3 packets read (1843200 bytes); 3 frames decoded;
Total: 3 packets (1843200 bytes) demuxed
Output file #0 (http://localhost:8091/feed1.ffm):
Output stream #0:0 (video): 6 frames encoded; 6 packets muxed (181221 bytes);
Output stream #0:1 (video): 15 frames encoded; 15 packets muxed (33584 bytes);
Total: 21 packets (214805 bytes) muxed
Received signal 2: terminating.
2.3 查看
这样在/tmp目录下就会生与一个feed1.ffm作为缓冲文件
cong@msi:/work/ffmpeg/out/bin$ ls -l /tmp/feed1.ffm
-rw-rw-r-- 1 cong cong 888832 Sep 14 18:24 /tmp/feed1.ffm
二. 实时流媒体的播放rtsp
1. 修改ffserver的配置ffserver.conf
HTTPPort 8091
RTSPPort 5454 -->这儿添加了rtsp的port
HTTPBindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
<Feed feed1.ffm>
file /tmp/feed1.ffm
FileMaxSize 10M
</Feed>
<Stream feed1.mjpeg>
Feed feed1.ffm
Format mjpeg
VideoSize 640x480
VideoFrameRate 10
VideoBitRate 2000
VideoQMin 1
VideoQMax 10
</Stream>
<Stream live.h264> -->rtsp的配置
Format rtp
Feed feed1.ffm
#VideoCodec libx264
VideoFrameRate 24
VideoBitRate 300
#VideoSize 480x272
VideoSize 640x480
#AVPresetVideo default
#AVPresetVideo superfast
AVOptionVideo flags +global_header
PixelFormat yuv420p
AVOptionVideo me_range 4
AVOptionVideo qdiff 4
AVOptionVideo qmin 2
AVOptionVideo qmax 51
#MulticastAddress 224.124.0.1
#MulticastPort 5000
#MulticastTTL 1
NoAudio
#AudioCodec libfaac
#AudioBitRate 32
#AudioChannels 2
#AudioSampleRate 22050
#AVOptionAudio flags +global_header
</Stream>
2. 运行
a.开启server
cong@msi:/work/ffmpeg/out/bin$ ./ffserver -d -f ./ffserver.conf
b.开启ffmpeg
cong@msi:/work/ffmpeg/out/bin$ ./ffmpeg -v verbose -r 5 -s 640x480 -f video4linux2 -i /dev/video0 http://localhost:8091/feed1.ffm
c.本地用ffplay播放
cong@msi:/work/ffmpeg/out/bin$ ./ffplay rtsp://localhost:5454/live.h264
如果没有问题,则ffplay就会播放出摄像头的影像。
三.顺序流媒体的播放
上面的RTSP是实时的,类似于网络视频聊天,而这个顺序流媒体即看网络电影
3.1 ffserver.conf
<Stream test.mpg> --> 这个针对于mpg格式
File /tmp/minzu.mpg --> ffmpeg源码目录下的doc/ffserver.conf中对Format参数的说明:
Format mpeg --> mpeg: MPEG-1 multiplexed video and audio
</Stream>
<Stream test.avi> -->这个针对于avi格式
File /tmp/minzu.avi
Format avi -->avi: AVI format (MPEG-4 video, MPEG audio sound)
</Stream>
完整的ffserver.conf如下:
cong@msi:/work/ffmpeg/ffmpeg-2.7.2$ cat ffserver.conf
HTTPPort 8091
HTTPBindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
<Stream test.mpg>
File /tmp/minzu.mpg
Format mpeg
</Stream>
<Stream test.avi>
File /tmp/minzu.avi
Format avi
</Stream>
3.2 视频文件的格式
cong@msi:/work/ffmpeg/ffmpeg-2.7.2$ ./ffplay /tmp/minzu.mpg
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 640x360 [SAR 1:1 DAR 16:9], max. 2516 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, stereo, s16p, 224 kb/s
cong@msi:/work/ffmpeg/ffmpeg-2.7.2$ ./ffplay /tmp/minzu.avi
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1511 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 224 kb/s
3.3 播放测试
cong@msi:/work/ffmpeg/ffmpeg-2.7.2$ ./ffplay http://192.168.4.11:8091/test.mpg
cong@msi:/work/ffmpeg/ffmpeg-2.7.2$ ./ffplay http://192.168.4.11:8091/test.avi
上面两个播放分别都可以看到视频并听到声音
注意:
ffserver.conf中的配置一定要与要播放的视频格式相对应
参考文章
How To : Stream A Webcam From The Raspberry Pi
http://sirlagz.net/2012/08/04/how-to-stream-a-webcam-from-the-raspberry-pi/
ffmpeg+ffserver搭建流媒体服务器
http://blog.chinaunix.net/uid-9688646-id-3399113.HTML
基于ffmpeg的流媒体服务器
http://www.cnblogs.com/lidabo/p/3701071.html
|
|