Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run puppeteer and ffmpeg inside docker container #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

roosnic1
Copy link
Collaborator

@roosnic1 roosnic1 commented Aug 6, 2024

No description provided.

🔧 (nvmrc): add .nvmrc file with Node.js version 20.16.0

✨ (index.js): use environment variables for SITE_TO_STREAM and STREAM_DEST

🔧 (package.json): add dotenv as a dev dependency and configure it in start script
✨ (docker-compose.yml): add docker-compose.yml for multi-container setup
🔧 (index.js): add '--disable-extensions' argument to puppeteer launch options
Copy link
Member

@devnoname120 devnoname120 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments but LGTM in general 👍

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
RUN npm ci

# Install ffmpeg
#RUN apt-get update && apt-get install -y ffmpeg libnss3 libatk1.0-0 libatk-bridge-2.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#RUN apt-get update && apt-get install -y ffmpeg libnss3 libatk1.0-0 libatk-bridge-2.0

Dockerfile Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
- STREAM_DEST=udp://127.0.0.1:1234?pkt_size=1316
ports:
- "1234:1234"
network_mode: host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why host for the network?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here! (There isn't a good emoji to express this sentiment on GitHub 😆)

Dockerfile Show resolved Hide resolved
…r build context

⬆️ (Dockerfile): update base image to node:lts-iron for improved stability
♻️ (Dockerfile): replace `npm ci` with `npm clean-install` for cleaner dependency installation
Copy link
Member

@devnoname120 devnoname120 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Copy link

@RudolfSchreier RudolfSchreier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only small suggestions and longer-term questions about stability.
Happy to get your feedback :)

Dockerfile Outdated
lsb-release \
wget \
xdg-utils \
--no-install-recommends

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You covered 2/3 of the recommendations the Docker gives about the usage of apt-get.

Could you add && rm -rf /var/lib/apt/lists/* at the end as well?
It should do nothing except reduce image size.

@@ -36,17 +36,13 @@ const { spawn } = require('child_process');
'-f', 'image2pipe',
'-r', '30',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are specifying 30 fps as a target frame rate both here and on line 73 - but on line 73, it is very implicitly encoded as the result of 1000/30.

Could you define a constant and reuse it everywhere? I am sorry if this causes weird floating point issues.
This does look very easy to overlook if the next programmer just does a "CTRL-F" for "30".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed that part of the code already and will ask for a review in another PR.

'-f', 'mpegts',
'udp://127.0.0.1:1234?pkt_size=1316'
//'srt://listener_ip:port?pkt_size=1316' // Replace with your SRT listener details
process.env.STREAM_DEST
]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This regards line 73, which GitHub won't let me select :()

  1. Have you considered using setInterval?
  2. Either way, it would be safest/cleanest to also save the result of setTimeout or setInterval in a variable which is then cleared when the function exits - otherwise I am not sure if this doesn't cause captureFrame to continuously execute even after the ffmpeg process has exited.
  3. Also - I am not really that familiar with the logic of what happens if frame delays start piling up.
    If this becomes an issue at any point, it might make sense to use a more specific method like lodash's debounce/throttle or requestAnimationFrame , but I leave this to your judgement.

Refactored the frame capture method from using setTimeout to setInterval for improved consistency. Also, added a console log to track the interval ID. Enhanced Dockerfile to remove apt lists after installation, reducing image size.
@RudolfSchreier
Copy link

@roosnic1 Just a short update since I am going on vacation for a longer period: My comments are non-blocking, and feel free to address them in a follow-up PR and override my review should you need to merge this ASAP 🙂.

🗽😎

@swisstxtsokol
Copy link

@roosnic1 Is this PR still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants