怎么把监控实时TS流转换成ffmpeg rtmp ts流

匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。FFMpeg处理RTMP流的总结 - 推酷
FFMpeg处理RTMP流的总结
FFMpeg处理RTMP流有两种方式:
& 一个是使用自带的RTMP代码功能;
& 一个是使用第三方库librtmp;
下面就这两种方式的一些使用和差异做了个总结;
一、自带RTMP代码功能
FFmpeg自带的RTMP代码只支持RTMP协议,不支持rtmpt,rtmpe,rtmpte和rtmps协议;
命令行设置如下:
1. 将RTMP流原样保存成文件
# ./ffmpeg -i rtmp://192.168.1.11:1935/live/teststream -acodec copy -vcodec copy -f flv -y test.flv
2. 将RTMP流转码保存成文件
# ./ffmpeg -i rtmp://192.168.1.11:1935/live/teststream -acodec ... -vcodec ... -f mp4 -y test.mp4
3. 将RTMP流转码后再以RTMP流的方式推送到RTMP流服务器
# ./ffmpeg -i rtmp://192.168.1.11:1935/live/teststream -acodec ... -vcodec ... -f flv rtmp://10.2.11.111/live/newstream
FFMpeg自带RTMP代码只支持RTMP流格式如:
rtmp://server:port/app/stream_name (eg: rtmp://192.168.1.11:80/live/test)
不支持RTMP流格式如:
rtmp://192.168.1.11:80/live/app/test
要想支持这种格式的RTMP流,就需要更专业和强大的每三方库&
二、第三方库librtmp
如何让FFMpeg链接该库可以参见文章:
http://blog.csdn.net/fireroll/article/details/8607955
这样FFMpeg就可以支持rtmp://, rtmpt://, rtmpe://, rtmpte://,以及 rtmps://协议了。
链接了librtmp的FFMpeg接受一个字符串的输入方式,
如:&rtmp://server:port/app/playpath/stream_name live=1 playpath=xxx ...&
NOTE:引号是必须的;
1. 保存RTMP直播流原样保存成文件:
# ./ffmpeg -i &rtmp:///live/newcetv1 live=1& -vcodec copy -acodec copy -y cetv1.flv &&
2. 将RTMP流转码后再以RTMP流的方式推送到RTMP流服务器
# ./ffmpeg -i &rtmp://192.168.1.11:1935/live/app/teststream live=1& -acodec ... -vcodec ... -f flv rtmp://10.2.11.111/live/newstream
3. 用ffplay播放RTMP直播流:
ffplay &rtmp:///live/newcetv1 live=1&&
4. 在使用FFMPEG类库进行编程的时候,也是一样的,
只需要将字符串传递给avformat_open_input()就行了,形如:
ffplay &rtmp:///live/newcetv1 live=1& &
char url[]=&rtmp://live.hkstv./live/hks live=1&; &
avformat_open_input(&pFormatCtx,url,NULL,&avdic) &
三、librtmp支持的参数:
http://rtmpdump.mplayerhq.hu/librtmp.3.html
librtmp RTMPDump Real-Time Messaging Protocol API
2. LIBRARY
RTMPDump RTMP (librtmp, -lrtmp)
3. SYNOPSIS
#include &librtmp/rtmp.h&
4. DESCRIPTION
The Real-Time Messaging Protocol (RTMP) is used for streaming multimedia content across a TCP/IP network.&
This API provides most client functions and a few server functions needed to support RTMP, RTMP tunneled in HTTP (RTMPT),&
encrypted RTMP (RTMPE), RTMP over SSL/TLS (RTMPS) and tunneled variants of these encrypted types (RTMPTE, RTMPTS).&
The basic RTMP specification has been published by Adobe but this API was reverse-engineered without use of the Adobe specification.&
As such, it may deviate from any published specifications but it usually duplicates the actual behavior of the original Adobe clients.
The RTMPDump software package includes a basic client utility program in rtmpdump(1), some sample servers,&
and a library used to provide programmatic access to the RTMP protocol. This man page gives an overview of the RTMP library routines.&
These routines are found in the -lrtmp library. Many other routines are also available, but they are not documented yet.
The basic interaction is as follows. A session handle is created using RTMP_Alloc() and initialized using RTMP_Init().&
All session parameters are provided using RTMP_SetupURL(). The network connection is established using RTMP_Connect(),&
and then the RTMP session is established using RTMP_ConnectStream(). The stream is read using RTMP_Read().&
A client can publish a stream by calling RTMP_EnableWrite() before the RTMP_Connect() call,&
and then using RTMP_Write() after the session is established. While a stream is playing it may be paused and unpaused&
using RTMP_Pause(). The stream playback position can be moved using RTMP_Seek(). When RTMP_Read() returns 0 bytes,&
the stream is complete and may be closed using RTMP_Close(). The session handle is freed using RTMP_Free().
All data is transferred using FLV format. The basic session requires an RTMP URL. The RTMP URL format is of the form
& rtmp[t][e|s]://hostname[:port][/app[/playpath]]
Plain rtmp, as well as tunneled and encrypted sessions are supported.
Additional options may be specified by appending space-separated key=value pairs to the URL.&
Special characters in values may need to be escaped to prevent misinterpretation by the option parser.&
The escape encoding uses a backslash followed by two hexadecimal digits representing the ASCII value of the character.&
E.g., spaces must be escaped as \20 and backslashes must be escaped as \5c.
5. OPTIONS
5.1 Network Parameters
These options define how to connect to the media server.
& socks=host:port
Use the specified SOCKS4 proxy.
5.2 Connection Parameters
These options define the content of the RTMP Connect request packet.&
If correct values are not provided, the media server will reject the connection attempt.
& app=name
& & & Name of application to connect to on the RTMP server. Overrides the app in the RTMP URL.&
& & & Sometimes the librtmp URL parser cannot determine the app name automatically,&
& & & so it must be given explicitly using this option.
& tcUrl=url
& & & URL of the target stream. Defaults to rtmp[t][e|s]://host[:port]/app.
& pageUrl=url
& & & URL of the web page in which the media was embedded. By default no value will be sent.
& swfUrl=url
& & & URL of the SWF player for the media. By default no value will be sent.
& flashVer=version
& & & Version of the Flash plugin used to run the SWF player. The default is &LNX 10,0,32,18&.
& conn=type:data
& & & Append arbitrary AMF data to the Connect message.&
& & & The type must be B for Boolean, N for number, S for string, O for object, or Z for null.&
& & & For Booleans the data must be either 0 or 1 for FALSE or TRUE, respectively.&
& & & Likewise for Objects the data must be 0 or 1 to end or begin an object, respectively.&
& & & Data items in subobjects may be named, by prefixing the type with 'N' and specifying the name before the value,&
& & & e.g. NB:myFlag:1. This option may be used multiple times to construct arbitrary AMF sequences. E.g.
& & & & conn=B:1 conn=S:authMe conn=O:1 conn=NN:code:1.23 conn=NS:flag:ok conn=O:0
5.3 Session Parameters
These options take effect after the Connect request has succeeded.
& playpath=path
& & &Overrides the playpath parsed from the RTMP URL.&
& & &Sometimes the rtmpdump URL parser cannot determine the correct playpath automatically,&
& & &so it must be given explicitly using this option.
& playlist=0|1
& & If the value is 1 or TRUE, issue a set_playlist command before sending the play command.&
& & The playlist will just contain the current playpath. If the value is 0 or FALSE, the set_playlist command will not be sent.&
& & The default is FALSE.
& live=0|1
& & Specify that the media is a live stream. No resuming or seeking in live streams is possible.
& subscribe=path
& & Name of live stream to subscribe to. Defaults to playpath.
& start=num
& & Start at num seconds into the stream. Not valid for live streams.
& stop=num
& & Stop at num seconds into the stream.
& buffer=num
& & Set buffer time to num milliseconds. The default is 30000.
& timeout=num
& & Timeout the session after num seconds without receiving any data from the server. The default is 120.
5.4 Security Parameters
These options handle additional authentication requests from the server.
& token=key
& & Key for SecureToken response, used if the server requires SecureToken authentication.
& jtv=JSON
& & JSON token used by legacy Justin.tv servers. Invokes NetStream.Authenticate.UsherToken
& swfVfy=0|1
& & If the value is 1 or TRUE, the SWF player is retrieved from the specified swfUrl for performing SWF Verification.&
& & The SWF hash and size (used in the verification step) are computed automatically.&
& & Also the SWF information is cached in a .swfinfo file in the user's home directory,&
& & so that it doesn't need to be retrieved and recalculated every time. The .swfinfo file records the SWF URL,&
& & the time it was fetched, the modification timestamp of the SWF file, its size, and its hash.&
& & By default, the cached info will be used for 30 days before re-checking.
& swfAge=days
& & Specify how many days to use the cached SWF info before re-checking.&
& & Use 0 to always check the SWF URL. Note that if the check shows that the SWF file has the same modification timestamp as before,&
& & it will not be retrieved again.
5.5 EXAMPLES
An example character string suitable for use with RTMP_SetupURL():
& &rtmp://flashserver:1935/ondemand/thefile swfUrl=http://flashserver/player.swf swfVfy=1&
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致zabbix 监控nginx-rtmp流媒体直播流
时间: 19:21:40
&&&& 阅读:68
&&&& 评论:
&&&& 收藏:0
标签:nginx-rtmp开启stats
# nginx(--add-module=nginx-rtmp-module-master)
nginx.conf:
listen 81;
location /stat {
定义item key
userparameter_live.conf
  UserParameter=live.stream[*],/usr/local/zabbix-agent/scripts/stream.py $1
#!/usr/bin/python
# -*- coding: utf-8 -*-
# author pdd
curl的直播流状态值写入本地CACHE文件 后续具体的直播频道流值从该文件获取 CACHE文件根据ctime一分钟更新一次
import sys
import time
import urllib2
class Live(object):
def __init__(self,url,CACHETTL,CACHE,STREAM):
self.url = url
self.CACHETTL = CACHETTL
self.CACHE = CACHE
self.STREAM = STREAM
def generate_cache(self):
TIMENOW = int(time.time())
if os.path.isfile(self.CACHE) and os.path.getsize(self.CACHE) & 0:
TIMECACHE = int(os.path.getctime(self.CACHE))
TIMECACHE = 0
if (TIMENOW - TIMECACHE) & self.CACHETTL:
r = urllib2.urlopen(self.url,timeout=1)
with open(self.CACHE,‘w‘) as f:
f.write(r.read())
except urllib2.URLError, e:
# 给zabbix触发直播流down报警的值
# 退出程序 不让从CACHE文件获取值
def get_status(self):
self.generate_cache()
with open(self.CACHE,‘r‘) as f:
r = f.read()
name = re.findall(r‘&name&(.*_sd)&/name&‘,r)
flow = re.findall(r‘&bw_in&(.*)&/bw_in&‘,r)[1:]
stream = dict(zip(name,flow))
print(stream[self.STREAM])
if __name__ == "__main__":
url = "http://127.0.0.1:81/stat"
# 直播频道流状态值url
CACHETTL = 60
# 本地CACHE文件更新时间间隔
CACHE = "/tmp/nginx-rtmp-status.cache"
# 本地CACHE文件绝对路径
STREAM = sys.argv[1]
# 某个具体直播频道
status = Live(url,CACHETTL,CACHE,STREAM)
status.get_status()
重启客户端使key生效
客户端测试
ps: 完整的ansible安装脚本
  /fantast-dd/ansible/tree/master/roles/zabbix_stream标签:
&&国之画&&&& &&
版权所有 京ICP备号-2
迷上了代码!1558人阅读
开头:把文件转成m3u8 方法(原样拷贝)
ffmpeg -re -i /root/video.mpg -codec copy -map 0 -f segment -segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts
读取rtmp流 的方式:
ffmpeg -v verbose -i rtmp://192.168.1.10:1935/live/stream &-c:v libx264 -c:a aac -ac 1 -strict -2 -crf 20 -profile:v main -maxrate 800k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -start_number 1 -f segment
-segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts
主要参数解释:
-hls_time n: 设置每片的长度,默认值为2。单位为秒
-hls_list_size n:设置m3u8文件播放列表保存的最多条目,设置为0会保存有所片信息,默认值为5,一般用于直播流,点播文件建议设置成0,即全部保存。
-hls_wrap n:设置多少片之后开始覆盖,如果设置为0则不会覆盖,默认值为0.这个选项能够避免在磁盘上存储过多的片,而且能够限制写入磁盘的最多的片的数量
-ac channels & & & &set number of audio channels &
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:117833次
积分:3047
积分:3047
排名:第10164名
原创:191篇
转载:29篇
(2)(5)(3)(1)(10)(8)(2)(3)(2)(4)(7)(8)(3)(1)(1)(2)(1)(1)(2)(3)(1)(1)(2)(2)(1)(3)(3)(5)(136)

我要回帖

更多关于 ffmpeg播放rtmp实时流 的文章

 

随机推荐