搞了一个晚上没结果,来救助 -- ffmpeg 向srs推流rtmp

百灵工作室 2016-03-22 03:17:52
rtmp用虚拟机搭建SRS,
./srs -c conf/hls.conf
./nginx

....

代码片段,不太好贴,贴出关键部分
。。。。。。

int ret = 0;
if (!memcmp(filename, "rtmp", 4)) {
ret = avformat_alloc_output_context2(&m_pFormatCtx, NULL, "flv", filename);
//m_pFormatCtx->oformat->name = "flv";
//m_pFormatCtx->oformat->extensions = "flv";
//m_pFormatCtx->oformat->mime_type = "application/flv";
m_pFormatCtx->oformat->video_codec = AV_CODEC_ID_H264;
m_pFormatCtx->oformat->audio_codec = AV_CODEC_ID_AAC;
} else {
ret = avformat_alloc_output_context2(&m_pFormatCtx, NULL, "f4v", filename);
}

if ((ret < 0) || (m_pFormatCtx == NULL))
{
//TODO: print messages for errors
return false;
}
//Add video stream
add_stream(m_pFormatCtx->oformat->video_codec);
//Add audio stream
add_stream(m_pFormatCtx->oformat->audio_codec);

//Open codec
if (bNeedEncoder)
{
open_video(m_VideoStream.st->codec->codec, m_videoOptions);
open_audio(m_AudioStream.st->codec->codec, m_audioOptions);
}

if (!(m_pFormatCtx->oformat->flags & AVFMT_NOFILE)) {
ret = avio_open(&m_pFormatCtx->pb, filename, AVIO_FLAG_WRITE);
if (ret < 0) {
fprintf(stderr, "Could not open output file '%s'", filename);
CleanUp();
return false;
}
}

av_dump_format(m_pFormatCtx, 0, filename, 1);

/* Write the stream header, if any. */
ret = avformat_write_header(m_pFormatCtx, &m_fmtOptions);
if (ret < 0) {
CleanUp();
return false;
}

m_isOpened = true;
return true;
。。。。。。

如果ret = avformat_alloc_output_context2(&m_pFormatCtx, NULL, "flv", filename);
此处使用f4v,则ret = avformat_write_header(m_pFormatCtx, &m_fmtOptions);
始终返回-22
如果使用flv,则ret = avformat_write_header(m_pFormatCtx, &m_fmtOptions);
返回0,ok,但srs服务器日志显示如下



----------------------------------------------------------------------------------------------------

[2016-03-22 15:13:53.990][trace][3545][119] RTMP client ip=192.168.177.1
[2016-03-22 15:13:53.991][trace][3545][119] simple handshake success.
[2016-03-22 15:13:53.991][trace][3545][119] connect app, tcUrl=rtmp://192.168.177.128:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, args=null
[2016-03-22 15:13:53.991][trace][3545][119] out chunk size to 60000
[2016-03-22 15:13:54.040][trace][3545][119] client identified, type=fmle-publish, stream_name=stream2, duration=-1.00
[2016-03-22 15:13:54.040][trace][3545][119] source url=/live/stream2, ip=192.168.177.1, cache=1, is_edge=0, source_id=-1[-1]
[2016-03-22 15:13:54.090][trace][3545][119] hls: win=60.00, frag=10.00, prefix=, path=./objs/nginx/html, m3u8=[app]/[stream].m3u8, ts=[app]/[stream]-[seq].ts, aof=2.00, floor=0, clean=1, waitk=1, dispose=0
[2016-03-22 15:13:54.102][trace][3545][119] start publish mr=0/350, p1stpt=20000, pnt=20000, tcp_nodelay=0, rtcid=120
[2016-03-22 15:13:54.142][trace][3545][119] got metadata, width=640, height=480, vcodec=7, acodec=10
[2016-03-22 15:13:54.142][error][3545][119][11] avc decode sequenc header failed. ret=3001(Resource temporarily unavailable)
[2016-03-22 15:13:54.142][error][3545][119][11] source codec demux video failed. ret=3001(Resource temporarily unavailable)
[2016-03-22 15:13:54.142][error][3545][119][11] source process video message failed. ret=3001(Resource temporarily unavailable)
[2016-03-22 15:13:54.142][error][3545][119][11] fmle process publish message failed. ret=3001(Resource temporarily unavailable)
[2016-03-22 15:13:54.142][error][3545][119][11] thread process message failed. ret=3001(Resource temporarily unavailable)

[2016-03-22 15:13:54.142][warn][3545][119][11] thread recv cycle failed, ignored and retry, ret=3001
[2016-03-22 15:13:54.142][error][3545][119][11] recv thread failed. ret=3001(Resource temporarily unavailable)
[2016-03-22 15:13:54.142][trace][3545][119] unpublish drop ts segment, sequence_no=0, uri=stream2-0.ts, duration=0.00, start=193273480080
[2016-03-22 15:13:54.142][trace][3545][119] cleanup when unpublish
[2016-03-22 15:13:54.142][error][3545][119][11] stream service cycle failed. ret=3001(Resource temporarily unavailable)


------------------------------
使用ffmpeg推流是正常的

命令如下
D:\temp\ffmpeg\bin>ffmpeg -re -rtbufsize 8000000 -thread_queue_size 32 -f dshow -i video="HD WebCam" -f dshow -sample_rate 44100 -i aud
io="麦克风 (Realtek High Definition Audio)" -pix_fmt yuv420p -profile main -tune zerolatency -preset ultrafast -vcodec libx264 -r 25 -s
640x480 -vb 512k -acodec libvo_aacenc -ab 256k -f flv -y rtmp://192.168.177.128:1935/live/stream2

srs正常,日志如下:

[2016-03-22 15:07:36.822][trace][3545][105] RTMP client ip=192.168.177.1
[2016-03-22 15:07:36.822][trace][3545][105] srand initialized the random.
[2016-03-22 15:07:36.822][trace][3545][105] srand initialized the random.
[2016-03-22 15:07:36.822][trace][3545][105] simple handshake success.
[2016-03-22 15:07:36.822][trace][3545][105] connect app, tcUrl=rtmp://192.168.177.128:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, args=null
[2016-03-22 15:07:36.822][trace][3545][105] out chunk size to 60000
[2016-03-22 15:07:36.875][trace][3545][105] client identified, type=fmle-publish, stream_name=stream2, duration=-1.00
[2016-03-22 15:07:36.898][trace][3545][105] source url=/live/stream2, ip=192.168.177.1, cache=1, is_edge=0, source_id=-1[-1]
[2016-03-22 15:07:36.936][trace][3545][105] hls: win=60.00, frag=10.00, prefix=, path=./objs/nginx/html, m3u8=[app]/[stream].m3u8, ts=[app]/[stream]-[seq].ts, aof=2.00, floor=0, clean=1, waitk=1, dispose=0
[2016-03-22 15:07:36.947][trace][3545][105] start publish mr=0/350, p1stpt=20000, pnt=20000, tcp_nodelay=0, rtcid=108
[2016-03-22 15:07:37.046][trace][3545][105] got metadata, width=640, height=480, vcodec=7, acodec=10
[2016-03-22 15:07:37.046][trace][3545][105] 43B video sh, codec(7, profile=Baseline, level=3, 768x640, 0kbps, 0fps, 0s)
[2016-03-22 15:07:37.046][trace][3545][105] 4B audio sh, codec(10, profile=LC, 2channels, 0kbps, 44100HZ), flv(16bits, 2channels, 44100HZ)
[2016-03-22 15:07:40.092][trace][3545][105] unpublish drop ts segment, sequence_no=0, uri=stream2-0.ts, duration=2147483.53, start=0
[2016-03-22 15:07:40.092][trace][3545][105] cleanup when unpublish
[2016-03-22 15:07:40.092][trace][3545][105] control message(unpublish) accept, retry stream service.
[2016-03-22 15:07:40.092][warn][3545][105][32] client disconnect peer. ret=1004
[2016-03-22 15:08:16.958][trace][3545][110] RTMP client ip=192.168.177.1

求高手给个思路,昨晚搞一晚上,没搞定,特求教
...全文
7161 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zpz_123123 2019-12-10
  • 打赏
  • 举报
回复
咋不把解决方案贴出来
zpz_123123 2019-12-10
  • 打赏
  • 举报
回复
只知索取,不知回报
qq_37664344 2017-10-25
  • 打赏
  • 举报
回复
可以详细说说你的解决方法吗?我也遇到和你一样的问题了,很急。谢谢
百灵工作室 2016-03-29
  • 打赏
  • 举报
回复
感谢各位,已经结贴,时候global_header的设置问题,设置上就好了
rightorwrong 2016-03-29
  • 打赏
  • 举报
回复
抓包看看命令通信
百灵工作室 2016-03-28
  • 打赏
  • 举报
回复
引用 6 楼 twtldn 的回复:
看样子是srs解析flv头信息的时候失败了,你在给formatcontext添加stream的时候是不是少设置了什么东西?timebase fps之类的
目前,时候怀疑设置少了东西,但是还不知道在哪个地方的设置少了东西,暂时没有解决,感谢您顶贴,稍后试一下您的方法
twtldn 2016-03-25
  • 打赏
  • 举报
回复
看样子是srs解析flv头信息的时候失败了,你在给formatcontext添加stream的时候是不是少设置了什么东西?timebase fps之类的
百灵工作室 2016-03-25
  • 打赏
  • 举报
回复
引用 4 楼 sawyerxy 的回复:
帮顶,很有技术含量,srs 用命令行基本是没问题的
多谢顶贴,板块稍显冷清了
sawyerxy 2016-03-25
  • 打赏
  • 举报
回复
帮顶,很有技术含量,srs 用命令行基本是没问题的
百灵工作室 2016-03-22
  • 打赏
  • 举报
回复
引用 2 楼 OExpress 的回复:
虚拟机搭建SRS是不是有问题呢,网络IP地址什么的可以PING同吧
首先,感谢您的回复,板块挺冷清的,有回复的就很感激 虚拟机搭建的SRS应该是没有问题的,基本可以肯定,因为搭建虚拟机,在宿主机windows下使用ffmpeg命令方式推流成功,并通过ffplay拉流出视频了,并且在SRS的日志中也得到了证实,相互均可以ping通的
CyberLogix 2016-03-22
  • 打赏
  • 举报
回复
虚拟机搭建SRS是不是有问题呢,网络IP地址什么的可以PING同吧
百灵工作室 2016-03-22
  • 打赏
  • 举报
回复
补充一句,向本机的ADOBE FMS服务器推流可以正常工作,用的flv格式,不过要修改一下 m_pFormatCtx->oformat->video_codec = AV_CODEC_ID_H264; m_pFormatCtx->oformat->audio_codec = AV_CODEC_ID_AAC; 这里 向srs推流却不行了,坐等大神,分不够可以加

2,541

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧