Chinaunix首页 | 论坛 | 博客
  • 博客访问: 184950
  • 博文数量: 40
  • 博客积分: 2036
  • 博客等级: 大尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-12 22:39
文章分类

全部博文(40)

文章存档

2013年(3)

2012年(1)

2011年(18)

2010年(18)

分类: C/C++

2011-02-23 21:51:43

问题:tee分出媒体流后,用x264enc后保存到mkv文件中出现freezed问题。
比如下面代码接收udp发过来的h264 rtp包数据:
gst-launch -vvv  \
   gstrtpbin name=rtpbin latency=1000   \
    udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, ssrc=(uint)3167758928, payload=(int)96, clock-base=(uint)661091733, seqnum-base=(uint)34778" \
  port=5000 ! queue ! rtpbin.recv_rtp_sink_0  rtpbin. ! rtph264depay ! queue ! ffdec_h264 ! queue ! timeoverlay ! clockoverlay ! textoverlay text="test" ! queue ! tee name=teevideo teevideo. ! queue leaky=1 !  xvimagesink sync = false \
    udpsrc port=5001 ! queue ! rtpbin.recv_rtcp_sink_0   \
    rtpbin.send_rtcp_src_0 ! queue ! udpsink port=5005  sync=true async=false\
 teevideo. ! queue leaky=1 ! ffmpegcolorspace ! gdkpixbufsink \
 teevideo. ! queue ! ffmpegcolorspace ! videoscale ! x264enc quantizer=25 threads=2 pass=qual me=2 subme=6 ref=6 b-pyramid=true weightb=true ! matroskamux name=mux ! filesink location=test.mkv
解决方法:
google了好久才找到问题的解决方法。
没时间详细写了,主要是给tee后的queue设置属性leaky=1或2都可以。
注意,非x264enc的分支都需要设置leaky属性。

把原文贴在这:

Back in August 2010 I ran a brief experiment . You may have noticed that it was using Theora encoder while most of my used H.264 encoder in MPEG-TS container. The reason for this was that I could not make x264enc work in the pipeline used for the video switcher.

To summarize the problem, this pipeline works:

gst-launch -e videotestsrc ! tee name="splitter" ! \
   queue ! xvimagesink sync=false \
   splitter. ! queue ! theoraenc ! oggmux ! filesink location=test.ogg

while this one will freeze right after start:

gst-launch -e videotestsrc ! tee name="splitter" ! \
   queue ! xvimagesink sync=false \
   splitter. ! queue ! x264enc ! mpegtsmux ! filesink location=test.ts

I was quite sure it was due to x264enc because I could use any compatible muxer including no muxer at all, even try to save raw H.264 directly to file. It would freeze in all cases when running on Ubuntu 10.04 or 10.10, but not on Ubuntu 9.10. Since I am using GStreamer from PPA, the only difference between the 9.10 and the 10.x machines are libx264 version.

Today I learned how to fix it and make x264enc work in this pipeline, thanks to an email on the GStreamer-devel mailing list . In his email Senthil writes that "The queue will block the supplier when there is no more space in it. ... Since x264enc may take more time to consume, setting leaky property (as suggested in the doc) on the queue before xvimagesink might help" – and indeed it does!

gst-launch -e videotestsrc ! tee name="splitter" ! \
   queue leaky=1 ! xvimagesink sync=false \
   splitter. ! queue ! x264enc ! mpegtsmux ! filesink location=test.ts

works like a charm. I tried both the leaky=1 (upstream) and leaky=2 (downstream) options and both work. The default is leaky=0 (not leaky).

You can now expect an update of the script as well as better integration with the rest of the package.

原文链接:


阅读(2794) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~