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

查看:179
本文介绍了在树莓派上使用 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 有一个错误,导致它无法处理未加时间戳的帧

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

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.

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

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