如何在GStreamer中录制音频和视频

4

我对gstreamer还不熟悉,我想录制音频和视频并将其保存为.mp4格式。使用网络摄像头录制视频,使用麦克风录制音频。这是我的管道:

gst-launch-1.0 -e v4l2src ! queue ! x264enc ! h264parse ! queue ! qtmux0. alsasrc ! 'audio/x-raw,rate=44100,depth=24' ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux ! filesink location=test.mp4

当我执行它时,视频只录制了10秒,而音频甚至没有录制。它会显示以下信息:

WARNING: from element /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Can't record audio fast enough Additional debug info: gstaudiobasesrc.c(866): gst_audio_base_src_create (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Dropped 425565 samples. This is most likely because downstream can't keep up and is consuming samples too slowly.

请帮助我解决这个问题,非常感谢。

3个回答

5

尝试使用以下管道将音频和视频录制到一个文件中。

gst-launch-1.0 -e v4l2src device="/dev/video0" ! videoconvert ! queue ! x264enc tune=zerolatency ! mux. alsasrc device="hw:2" ! queue ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux name=mux ! filesink location=test.mp4 sync=false

0

现在已经获取到了流,音频和视频都被完美地记录下来了

这是管道:

gst-launch-1.0 -e v4l2src ! 'video/x-raw,width=960,height=720,framerate=30/1' ! queue ! x264enc tune=zerolatency ! mux. alsasrc ! audio/x-raw,width=16,depth=16,rate=44100,channel=1 ! queue ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux name=mux ! filesink location=test.mp4 sync=false

如果管道中仍有任何错误,请告诉我。


0

我最终使用了这个命令(从网上随机回复中改编而来,抱歉我丢失了来源)

raspivid -t 0 --vflip --hflip -w 1920 -h 1080 -fps 30 --bitrate 14000000 --profile baseline -3d sbs --intra 30 --inline --flush --awb auto --exposure auto --sharpness 0 --contrast -15 --digitalgain 0.0 -o - | gst-launch-1.0 -ve fdsrc num-buffers=-1 ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! smux.video alsasrc device=hw:2,0 ! audio/x-raw,format=S32LE,rate=48000,channel=2 ! audioconvert ! avenc_aac ! aacparse ! queue ! smux.audio_0 splitmuxsink name=smux location=video.mp4 muxer=mpegtsmux

请注意,这是用于捕获立体图像的,您可以删除“-3d sds”并调整单个摄像头的宽度。您还可以安全地删除-ve,这仅对调试有用,并将音频设备硬件更改为您的捕获卡的编号($ arecord -l 查找您的卡的ID)。

我更喜欢使用qtmux,但由于raspivid生成的h264流中缺少PTS信息,因此它失败了。不过,mpegtsmux很高兴。

目前为止,生成的MPEG文件已经损坏了一半,不能被所有播放器读取(QuickTime失败,而VLC很高兴)。使用ffmpeg重新编码: ffmpeg-vcodec mpeg4-b:v 7561k-qscale:v 2-acodec aac-ac 2-async 1-strict experimental ./video2.mp4-threads 0-i video.mp4 修复了该文件。

希望这对某人有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接