在Raspberry Pi上使用gstreamer从h264流中捕获jpeg [英] Capturing jpegs from an h264 stream with gstreamer on a Raspberry Pi

查看:468
本文介绍了在Raspberry Pi上使用gstreamer从h264流中捕获jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Raspberry Pi的新相机附件.它尚不支持video4linux,但附带一个小程序,可播放1080p h264流.我已经验证了这项工作,并通过以下方式将视频推送到标准输出:

I have one of the new camera add-ons for a Raspberry Pi. It doesn't yet have video4linux support but comes with a small program that spits out a 1080p h264 stream. I have verified this works and got it pushing the video to stdout with:

raspivid -n -t 1000000 -vf -b 2000000 -fps 25 -o -

我想处理此流,以便最终获得每秒拍摄一次的视频快照.

I would like to process this stream such that I end up with a snapshot of the video taken once a second.

因为它是1080p,所以我需要使用rpi的硬件支持H264编码.我相信gstreamer是唯一支持此功能的应用程序,因此使用ffmpeg或avconv的解决方案将不起作用.我在 http://www.trans-omni中使用了构建脚本.co.uk/pi/GStreamer-1.0/build_gstreamer 来制作gstreamer和用于硬件H264编码的插件,它似乎可以正常工作:

Since it's 1080p I will need to use the rpi's hardware support for H264 encoding. I believe gstreamer is the only app to support this so solutions using ffmpeg or avconv won't work. I've used the build script at http://www.trans-omni.co.uk/pi/GStreamer-1.0/build_gstreamer to make gstreamer and the plugin for hardware H264 encoding and it appears to work:

root@raspberrypi:~/streamtest# GST_OMX_CONFIG_DIR=/etc/gst gst-inspect-1.0 | grep 264
...
omx:  omxh264enc: OpenMAX H.264 Video Encoder
omx:  omxh264dec: OpenMAX H.264 Video Decoder

因此,我需要构建一个gst-launch管道,该管道在stdin上接收视频,并每秒发出一个新的jpeg.我知道我可以使用gstreamer的"multifilesink"接收器来执行此操作,因此想出了以下简短脚本来启动它:

So I need to construct a gst-launch pipeline that takes video on stdin and spits out a fresh jpeg once a second. I know I can use gstreamer's 'multifilesink' sink to do this so have come up with the following short script to launch it:

root@raspberrypi:~/streamtest# cat test.sh
#!/bin/bash

export GST_OMX_CONFIG_DIR=/etc/gst

raspivid -n -t 1000000 -vf -b 2000000 -fps 25 -o - |  \
gst-launch-1.0 fdsrc fd=0 ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! jpegenc ! multifilesink location=img_%03d.jpeg

问题是它不起作用:gstreamer永远处于预卷状态,从不吐出我宝贵的jpeg.

Trouble is it doesn't work: gstreamer just sits forever in the prerolling state and never spits out my precious jpegs.

root@raspberrypi:~/streamtest# ./test.sh
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
[waits forever]

如果设置了gstreamer的-v标志的有用输出位于 http://pastebin.com/q4WySu4L

In case it's helpful output with gstreamer's -v flag set is at http://pastebin.com/q4WySu4L

任何人都可以解释我在做什么错吗?

Can anyone explain what I'm doing wrong?

推荐答案

我们终于找到了解决方案.我的gstreamer管道基本上是正确的,但是有两个问题使它停止工作:

We finally found a solution to this. My gstreamer pipeline was mostly right but two problems combined to stop it working:

  • raspivid不会为其生成的h264帧添加时间戳
  • gstreamer的最新版本存在一个错误,该错误会阻止其处理未加时间戳的帧

运行1.0版本的gstreamer(请确保从头开始构建并删除先前尝试的所有痕迹),问题就消失了.

Run a 1.0 build of gstreamer (be sure to build from scratch & remove all traces of previous attempts) and the problem goes away.

请参见 http://gstreamer-devel.966125.n4.nabble.com/Capturing-jpegs-from-an-h264-stream-tt4660254.html 用于邮件列表线程.

See http://gstreamer-devel.966125.n4.nabble.com/Capturing-jpegs-from-an-h264-stream-tt4660254.html for the mailing list thread.

这篇关于在Raspberry Pi上使用gstreamer从h264流中捕获jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆