2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Puppeteerの動画再生には形式に注意が必要

Posted at

ヘッドレスブラウザのPuppeteerを使いWebRTCを通して、Videoタグの動画を相手に送るというのを行おうとしていたが、はじめうまく動作しなかった。
結果として、動画の形式(codec)が悪かったという話

動く動画形式

簡単に言うと、PuppeteerのデフォルトブラウザはChromiumで、Chromiumで動く動画・音声形式は以下ですよ、という感じらしい。
https://www.chromium.org/audio-video

Container formats

  • MP4 (QuickTime/ MOV / MPEG4)
  • Ogg
  • WebM
  • WAV

Codec formats (Decode Only)

Audio

  • FLAC
  • MP3
  • Opus
  • PCM 8-bit unsigned integer
  • PCM 16-bit signed integer little endian
  • PCM 32-bit float little endian
  • Vorbis
  • AAC [Main, LC, HE profiles only, xHE-AAC on Android P+] [Google Chrome only]
  • AMR-NB [Google Chrome OS only]
  • AMR-WB [Google Chrome OS only]
  • PCM μ-law [Google Chrome OS only]
  • GSM [Google Chrome OS Only]

Video

  • VP8
  • VP9
  • AV1 [Only Chrome OS, Linux, macOS, and Windows X86 at present]
  • Theora [Except on Android variants]
  • H.264 [Google Chrome only]
  • MPEG-4 [Google Chrome OS only]

で、適当な動画を再生しようとしたらH.264で、Google Chromeなら動くらしいが素のChromiumでは残念ながら動かないので、puppeteerでも動かなかった。
音声は対応形式だったので流れてた模様

というのでcodecを変えて、試しに
WebMコンテナで、Audio:VorbisVideo:VP8でエンコードしたところ再生されました。

資料とそれ以外の方法

実はここに書いてあって、音声・動画系はうまく行かない時があるよとのこと。
https://github.com/puppeteer/puppeteer

You may find that Puppeteer does not behave as expected when controlling pages that incorporate audio and video. (For example, video playback/screenshots is likely to fail.)

これとは別に回避方法としては、Chromeをインストールしてそれを使う方法もあるようです

const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});

この場合はpuppeteerではなくpuppeteer-coreで良いようです

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?