How to record Video with Audio from a puppeteer instance from a docker container
Asked Answered
I

0

7

I'm trying to build a simple server that basically:

  • opens a webpage with a puppeteer instance.
  • records the webpage and save the video file.

I was able to implement this with puppeteer-stream and it works perfectly locally.

While trying to put this in a docker instance deployed to AWS Elasticbeanstalk, I ran into an issue where I couldn't spin up the chrome browser from the docker container but that was fixed with the help of xvfb - now it launches a fake UI for the chrome tabs and records that inside.

At this point, I can record video perfectly but it has NO audio. I tried setting up PulseAudio as a virtual audio driver but it doesn't work either.

Another issue with PulseAudio is that it's going to record the entire process instead of a chrome tab so it's going to be chaotic if we decide to record multiple web pages concurrently.

Here's what my Dockerfile looks like at the moment:

FROM node:12

# Install dependencies
RUN apt-get update &&\
  apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
  libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
  libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
  libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
  ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \
  xvfb pulseaudio x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps

# Cd into /app
WORKDIR /app

# Copy package.json into the app folder
COPY package.json /app

# Install dependencies
RUN npm config set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD false
RUN npm config set ignore-scripts false

RUN npm install

COPY . /app

# Start server on port 80
EXPOSE 80

# Creating Display
ENV DISPLAY :99

# Start script on Xvfb
CMD Xvfb :99 -screen 0 1920x1080x24 & pulseaudio --daemonize & yarn start

I also tried a solution where you have to create a new usergroup & give them audio and video access but it doesn't work either:

RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser ./node_modules

I also checked this Node puppeteer stream not recording audio out but that’s not my case.

Is there any way I can achieve building a server that can record audio AND video on multiple webpages in a Docker container?

REMINDER - it works locally without docker (locally). It just doesn't work inside docker and we need to use Docker for it to work on aws.

Appreciate the help!

Isopiestic answered 17/4, 2021 at 19:9 Comment(3)
If you're trying to simulate both video and audio devices, and you need to launch multiple daemons to run the process plus also the recording tool, would a virtual machine be a better match? If you configured it using a system-automation tool like Salt Stack, Ansible, or Chef then you could replay this same configuration against your EC2 instance.Miller
did you solved the issue? i am countering same problem now.Untidy
@MuratCemYALIN yes I did. Don't use Puppeteer's default chromium browser. Install google-chrome-stable. Check out my full dockerfile.Isopiestic

© 2022 - 2024 — McMap. All rights reserved.