Raspberry Pi 2 でWebcamの映像音声を録画する

前回の続きで、映像だけでなく音声も一緒にmp4ファイルに録画するようにしました。

#!/bin/sh

if [ $# -ne 1 ]; then
  echo "Usage: " $0 " output_file" 1>&2
  echo "Hit ^C to stop." 1>&2
  exit 1
fi
output_file=$1

gst-launch-1.0 -e \
  v4l2src  ! "video/x-raw,width=640,height=480,framerate=30/1" ! \
    omxh264enc target-bitrate=1000000 control-rate=variable ! \
    video/x-h264,profile=high ! h264parse ! queue ! \
    mp4mux name=mux \
  alsasrc device=hw:1 ! audioresample ! audio/x-raw,rate=48000 ! \
    queue ! voaacenc bitrate=32000 ! queue ! mux. \
  mux. ! filesink location=$output_file

使用しているWebcamLogicool c270でその内蔵マイクはモノラルです。
録画したファイルのffprobeの結果。

$ ffprobe out3.mp4 
ffprobe version 2.7.2 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x13abfb0] Invalid timestamps stream=0, pts=-421387831, dts=0, size=5601
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2015-10-12 02:57:00
  Duration: 00:00:19.83, start: -140462.610333, bitrate: 1031 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 992 kb/s, 29.81 fps, 29.97 tbr, 3k tbn, 6k tbc (default)
    Metadata:
      creation_time   : 2015-10-12 02:57:00
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
    Metadata:
      creation_time   : 2015-10-12 02:57:00
      handler_name    : SoundHandler

参考にしたページ
Streaming with nginx-rtmp-module: GStreamer and Raspberry Pi