因此,我可以观看实时视频:
/usr/local/bin/capture -d /dev/video0 -c 100000 -o | \
gst-launch-1.0 -e filesrc location=/dev/fd/0 \
! h264parse \
! decodebin\
! xvimagesink sync=false
...或者将流记录为原始的h264文件:
/usr/local/bin/capture -d /dev/video0 -c 100000 -o | \
gst-launch-0.10 -e filesrc location=/dev/fd/0 \
! h264parse \
! mp4mux \
! filesink location=/tmp/video.mp4
但我怎么也想不出如何同时做到这两点。有时,在录制时在屏幕上显示实时反馈可能会很有用,所以我希望能够实现这一点。
我花了好几个小时寻找一种同时抓取和屏幕录制的方法,但是没有成功。即使尝试了许多tee
和queue
,也没有帮助。
如果能够将ALSA音频(hw:2,0)添加进来,那就更好了,但是我可以用一种丑陋的方式解决它。例如,在Audacity或者arecord中,hw:2,0是有效的输入:
Recording open error on device 'hw:2,0': No such file or directory
Recording open error on device 'plughw:2,0': No such file or directory
重新概括一下:我希望能将这两个视频片段合并,如果音频也可以一起工作那就更好了。我感觉自己像个新手。
非常感谢您所提供的任何帮助。
编辑:无法工作的代码:
/usr/local/bin/capture -d /dev/video1 -c 100000 -o | \
gst-launch-1.0 -e filesrc location=/dev/fd/0 ! tee name=myvid ! h264parse ! decodebin \
! xvimagesink sync=false myvid. ! queue ! mux. alsasrc device=plughw:2,0 ! \
audio/x-raw,rate=44100,channels=1,depth=24 ! audioconvert ! queue ! mux. mp4mux \
name=mux ! filesink location=/tmp/out.mp4
...leads to this:
WARNING: erroneous pipeline: could not link queue1 to mux
编辑:尝试了umlaeute的建议,得到了一个几乎为空的视频文件和一个静止的实时视频帧。在修复启用音频的代码中的两个小错误(双引号错别字,未将音频编码为任何与MP4兼容的东西)后,无论是否有音频都没有影响。在audioconvert
之后添加avenc_aac
就解决了这个问题。错误输出:
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstAudioSrcClock
Redistribute latency...
ERROR: from element /GstPipeline:pipeline0/GstMP4Mux:mux: Could not multiplex stream.
Additional debug info:
gstqtmux.c(2530): gst_qt_mux_add_buffer (): /GstPipeline:pipeline0/GstMP4Mux:mux:
DTS method failed to re-order timestamps.
EOS on shutdown enabled -- waiting for EOS after Error
Waiting for EOS...
ERROR: from element /GstPipeline:pipeline0/GstFileSrc:filesrc0: Internal data flow error.
Additional debug info:
gstbasesrc.c(2809): gst_base_src_loop (): /GstPipeline:pipeline0/GstFileSrc:filesrc0:
streaming task paused, reason error (-5)
编辑: 好的,umlaeute的修正代码完美地运行了,但只有在我使用v4l2src而非convert工具时才有效。目前,这意味着抓取MJPEG流而不是H264流。虽然这对我来说没有影响,但我想我更喜欢一个更现代化的工作流程。所以无论如何,这里是实际有效的内容,输出一个MJPEG视频文件和一个实时“取景器”。并不十分优美,但非常可行。感谢您的所有帮助!
gst-launch-1.0 -e v4l2src device=/dev/video1 ! videorate ! 'image/jpeg, width=1280, height=720, framerate=24/1' ! tee name=myvid \
! queue ! decodebin ! xvimagesink sync=false \
myvid. ! queue ! mux.video_0 \
alsasrc device="plughw:2,0" ! "audio/x-raw,rate=44100,channels=1,depth=24" ! audioconvert ! lamemp3enc ! queue ! mux.audio_0 \
avimux name=mux ! filesink location=/tmp/out.avi
tee
应该可以正常工作,请发布一个不起作用的管道。 - umläute