YANO's digital garage

Copyright ©YANO All rights reserved. https://www.bravotouring.com/~yano/

Last-modified: 2024-04-10 (水)


[一語一絵/IT系]

GstreamerとVAAPI / 2017-01-18 (水)

宿題を残したQSVハードウェアエンコード環境。

[External]Intel VAAPI h264 encoding: gstreamer vs ffmpeg\avconvなどによるとVAAPI対応の選択肢としてGStreamerもあるようなので、試してみた。

yano@haswell:~/gst-test$ sudo apt-get install gstreamer1.0-vaapi*
yano@haswell:~/gst-test$ gst-inspect-1.0 vaapi
Plugin Details:
  Name                     vaapi
  Description              VA-API based elements
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstvaapi.so
  Version                  0.5.7
  License                  LGPL
  Source module            gstreamer-vaapi
  Binary package           gstreamer-vaapi
  Origin URL               gwenole.beauchesne@intel.com

  vaapidecode: VA-API decoder
  vaapipostproc: VA-API video postprocessing
  vaapisink: VA-API sink

  3 features:
  +-- 3 elements

yano@haswell:~/gst-test$
との事。[External]GStreamer VA-API Plugins 1.0 Plugins Reference Manualを見る限り「VA-API based H.264 video encoder」がありそうなのだが、どうやらubuntu 14.04の公式パッケージはデコーダ未対応の旧版な雰囲気だ。

というわけで、必然的に最新版をソースコードからbuildする方向にハンドルを切るわけだが、その前にGstreamerの独特な作法に馴染むべく、取り敢えずx264で試行錯誤してmp4のファイル出力にトライ。

yano@haswell:~/gst-test$ ffmpeg -i ~/20161210_2313_28_GRhd.ts -map 0:0 -map 0:1 \
  -vcodec copy -acodec copy ./input.ts
yano@haswell:~/gst-test$ gst-launch-1.0 \
  filesrc location=./input.ts ! progressreport ! tsdemux name=demuxer demuxer. ! queue ! \
  aacparse ! avdec_aac ! audioresample ! audioconvert dithering=0 ! voaacenc bitrate=25800 ! mux. \
  mp4mux name=mux ! filesink location=./gst-x264-`date +%Y%m%d_%H%M`.mp4 demuxer. ! queue ! mpegvideoparse ! mpeg2dec ! \
  videoconvert ! x264enc pass=quant ! video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mux.
Got EOS from element "pipeline0".
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
Redistribute latency...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
progressreport0 (00:00:05): 4869200 / 250449088 bytes ( 1.9 %)
progressreport0 (00:00:10): 8648000 / 250449088 bytes ( 3.5 %)
~中略~
progressreport0 (00:04:15): 241937200 / 250449088 bytes (96.6 %)
progressreport0 (00:04:20): 246054400 / 250449088 bytes (98.2 %)
Execution ended after 0:04:27.257661620
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
yano@haswell:~/gst-test$
ちなみに生のTSをそのまま喰わせると
ERROR: from element /GstPipeline:pipeline0/GstTSDemux:demuxer: Internal data stream error.
と言われるので、ffmpegでVideo/Audio Streamをそれぞれ1つずつ分離しているのだが、変換元が「20161215_0012_28_GRhd.ts」だと2段目の"Redistribute latency..."が出ずにダンマリになってしまうので、まだちょっと怪しい。

【参照】
●Qiita http://qiita.com/
GStreamer というマルチメディアフレームワーク 2016年12月3日
●ククログ http://www.clear-code.com/blog/
GStreamerのエレメントをつないでパイプラインを組み立てるには 2014年7月22日
●あしたのオープンソース研究所 http://oss.infoscience.co.jp/
GStreamer アプリケーション開発マニュアル 日本語訳 (0.10.25.1)
●GStreamer https://gstreamer.freedesktop.org/
vaapi: GStreamer VA-API Plugins 1.0 Plugins Reference Manual
●Gears on Gallium http://www.gearsongallium.com/
Intel VAAPI h264 encoding: gstreamer vs ffmpeg\avconv 2016年5月16日
●FFmpeg https://ffmpeg.org/
CompilationGuide/Ubuntu
●Wikipedia http://ja.wikipedia.org/wiki/
LGA1150
Haswellマイクロアーキテクチャ
Broadwellマイクロアーキテクチャ
LGA1151
Skylakeマイクロアーキテクチャ