为什么我可以将h264编码的视频从网络摄像头流传输到两个显示和文件中,而不是原始视频? [英] Why can I stream h264 encoded video from webcam to BOTH display and file, but NOT raw video?

查看:675
本文介绍了为什么我可以将h264编码的视频从网络摄像头流传输到两个显示和文件中,而不是原始视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Logitech C920网络摄像头流式传输原始视频,同时两者都显示并使用GStreamer 1.0将视频保存到文件中.

I want to stream raw video from a Logitech C920 webcam and while both displaying and saving the video to file using GStreamer 1.0.

如果我从摄像机流式传输h264编码的视频(摄像机提供了硬件编码的h264),则此方法有效,但是如果我从摄像机流式传输原始视频,则失败.但是,如果我仅显示或仅保存到文件,则流原始视频有效.

This works if I stream h264 encoded video from the camera (the camera provides hardware encoded h264), but it fails if I stream raw video from the camera. However, if I only display, or only save to file, streaming raw video works.

为什么它不能用于h264视频流,而不能用于原始视频流?

Why does it work with a h264 video stream but not with a raw video stream?

从摄像机到显示器和文件的h264编码视频流(WORKS):

h264 encoded video stream from camera to BOTH display and file (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-h264,width=640,height=480,framerate=15/1 ! tee name=t \
    t. ! queue ! h264parse ! avdec_h264 ! xvimagesink sync=false \
    t. ! queue ! h264parse ! matroskamux \
    ! filesink location='h264_dual.mkv' sync=false

从摄像机到仅显示(WORKS)的原始视频流:

raw video stream from camera to ONLY display (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! xvimagesink sync=false

从摄像机到唯一文件的原始视频流(WORKS):

raw video stream from camera to ONLY file (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! videoconvert ! x264enc ! matroskamux \
    ! filesink location='raw_single.mkv' sync=false

从摄像机到显示和文件的原始视频流(失败):

raw video stream from camera to BOTH display and file (FAILS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! tee name=t \
    t. ! queue ! xvimagesink sync=false \
    t. ! queue ! videoconvert ! x264enc ! h264parse ! matroskamux \
    ! filesink location='raw_dual.mkv' sync=false

最后一条命令(原始视频同时显示和显示)失败,没有任何警告或错误. gst-launch终端输出与仅写入文件时完全相同.出现xvimage窗口并显示来自相机的图像,但是图像没有改变(即被冻结).零字节文件也会出现.

The last command (raw video to both display and file) fails without any warnings or errors. The gst-launch terminal output is exactly the same as when only writing to file. The xvimage window appears and displays an image from the camera, but the image does not change (i.e. it is frozen). A zero bytes file appears too.

我已经尝试了上述命令的多个版本,但是我认为这些是可以重现该问题的最小命令.

I have tried multiple versions of the above commands, but I think those are the minimal commands that can reproduce the problem.

有人知道我在做什么错吗?

Does anyone understand what I am doing wrong?

推荐答案

可以将来自网络摄像头(非特定于C920)的原始视频流传输到显示文件和h.264编码文件. x264enc属性tune需要设置为zerolatency.

Streaming raw video from a webcam (not specific to C920) to both display and h.264 encoded file can be done. The x264enc property tune needs to be set to zerolatency.

h.264示例:

gst-launch-1.0 -v v4l2src device=/dev/video0 \ ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \ ! tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! x264enc tune=zerolatency ! h264parse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

gst-launch-1.0 -v v4l2src device=/dev/video0 \ ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \ ! tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! x264enc tune=zerolatency ! h264parse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

或者,可以完全跳过h.264并改为编码为theora或vp8.

Alternatively, one can skip h.264 altogether and encode to theora or vp8 instead.

theora示例:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! theoraenc ! theoraparse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! theoraenc ! theoraparse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

vp8示例:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! vp8enc ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! vp8enc ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

非常感谢Jan Spurny和Tim.

Thanks a lot to Jan Spurny and Tim.

这篇关于为什么我可以将h264编码的视频从网络摄像头流传输到两个显示和文件中,而不是原始视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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