0

我使用以下命令从我的网络摄像头录制音频和视频

gst-launch-0.10 v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=30/1 ! \
             tee name=t_vid ! queue ! videoflip method=horizontal-flip ! \
             xvimagesink sync=false t_vid. ! queue ! \
             videorate ! video/x-raw-yuv,framerate=30/1 ! queue ! mux. \
             autoaudiosrc ! audiorate ! audio/x-raw-int,rate=48000,channels=1,depth=16 ! queue ! \
             audioconvert ! queue ! mux. avimux name=mux ! \
             filesink location=video.avi

结果在流之间的同步性方面是正确的。但是 avi 文件非常大,因为那是未压缩的数据......你能告诉我如何减少记录的大小吗?请注意,我在录制后将音频和视频拆分为单独的文件进行处理。保持同步性至关重要。

* 编辑 *

我尝试使用 ffmpeg 使用以下命令压缩 avi 文件:

ffmpeg -i video.avi -vcodec msmpeg4v2 output.avi

但似乎比特率是无效的(因为它的原始数据不适用?)这是输出:

Input #0, avi, from 'video.avi':
Duration: 00:00:00.00, start: 0.000000, bitrate: -2147483 kb/s
  Stream #0.0: Video: rawvideo, yuv420p, 640x480, 30 tbr, 30 tbn, 30 tbc
  Stream #0.1: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
[buffer @ 0xef57e0] w:640 h:480 pixfmt:yuv420p
Incompatible sample format 's16' for codec 'ac3', auto-selecting format 'flt'
[ac3 @ 0xedece0] channel_layout not specified
[ac3 @ 0xedece0] No channel layout specified. The encoder will guess the layout, but it     might be incorrect.
[ac3 @ 0xedece0] invalid bit rate
Output #0, avi, to 'output.avi':
  Stream #0.0: Video: msmpeg4v2, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 30 tbc
  Stream #0.1: Audio: ac3, 48000 Hz, mono, flt, 200 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height

感谢您的帮助。

4

2 回答 2

1

这就是你可以做的:(比如 900k 视频和 64k 音频。由于你想要 48kHz 采样,你需要提供至少 64Kbits 比特率)

gst-launch-0.10 v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=30/1 ! \
         tee name=t_vid ! queue ! videoflip method=horizontal-flip ! \
         xvimagesink sync=false t_vid. ! queue ! \
         videorate ! video/x-raw-yuv,framerate=30/1 ! queue ! ffmpegcolorspace ! ffenc_mpeg4 bitrate=900000 ! mux. \
         autoaudiosrc ! audiorate ! audio/x-raw-int,rate=48000,channels=1,depth=16 ! queue ! \
         audioconvert ! lamemp3enc bitrate=64 target=1 ! queue !  mux. avimux name=mux ! \
         filesink location=video.avi

如果您希望获得更小的尺寸并且不介意 mp4,我建议将 ffenc_mp4 替换为 x264enc,将 avimux 替换为 mp4mux。如果您将 x264enc 与任何其他多路复用器 [不是 mp4mux] 一起使用,请记住还要为 x264enc 设置属性 byte-stream=1。

获取任何元素类型的属性 gst-inspect 所以 lamemp3enc 信息可以通过执行 gst-inspect lamemp3enc 来获取。

于 2012-10-13T14:57:25.057 回答
0

您可以将 lamemp3enc 插入音频分支,将 ffenc_mpeg4(或 ffenc_msmpeg4)插入视频分支。

于 2012-10-11T12:41:08.053 回答