Skip to content

Commit

Permalink
Major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
omartrigui committed Jun 21, 2020
1 parent ec7176b commit 18ef127
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 65 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM ubuntu:xenial

ADD https://github.com/just-containers/s6-overlay/releases/download/v2.0.0.1/s6-overlay-amd64.tar.gz /tmp/
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / --exclude='./bin' && tar xzf /tmp/s6-overlay-amd64.tar.gz -C /usr ./bin
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / && \
rm /tmp/s6-overlay-amd64.tar.gz

RUN useradd apps

Expand All @@ -17,7 +18,7 @@ RUN apt-get update && \
RUN add-apt-repository ppa:mc3man/xerus-media && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list

RUN apt-get update && \
apt-get install -yqq \
Expand All @@ -35,13 +36,12 @@ WORKDIR /app/
RUN npm install && \
npm audit fix


COPY . /app/


RUN apt-get purge curl -y && \
apt-get clean -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/init"]
CMD ["/app/entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Omar Trigui

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
### Boilerplate & repository setup {{{1

SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

IMAGE := omartrigui/url-to-video
IMAGE := cipheredbytes/url-to-video

.PHONY: docker.build
docker.build:
docker build -t "${IMAGE}" .
docker images | grep "${IMAGE}"
docker image inspect "${IMAGE}" --format='{{.Size}}' | numfmt --to=iec-i --format='%10f'


.PHONY: format.js
Expand All @@ -22,16 +20,16 @@ format.js:
.PHONY: docker.run
docker.run:
docker run --rm \
-v "/tmp:/output" \
-e URL=https://www.youtube.com/watch?v=PBYKqvDK8d8 \
-e DURATION=20 \
-e OUTPUT_FILENAME=forever_tracey.mp4 \
"${IMAGE}"
-v /tmp:/recordings/ \
-e URL=https://www.youtube.com/watch?v=PBYKqvDK8d8 \
-e DURATION=20 \
-e OUTPUT_FILENAME=forever_tracey.mp4 \
"${IMAGE}"

.PHONY: docker.push
docker.push:
docker push "${IMAGE}"

.PHONY: kubectl.run
kubectl.run:
kubectl create -f k8s/job.yaml
.PHONY: k8s.run
k8s.run:
kubectl create -f ./k8s/job.yaml
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
## Url-to-Video

## Overview
url-to-video generator allows you to create a video from html source.
Url-to-Video generator allows you to create a video from html source.

## Features

* Full **Docker** integration (Docker based).
* K8s Job deployment.
* **Xvfb** in-memory display server for UNIX-like operating system that enables you to run graphical applications without a display..
* Full **Docker** integration (based on [s6-overlay](https://github.com/just-containers/s6-overlay) hypervisor).
* **Xvfb** in-memory display server for UNIX-like operating system that enables you to run graphical applications without a display.
* **Ffmpeg** a complete, cross-platform solution to record, convert and stream audio and video.
* **Google chrome** a cross-platform web browser
* **Node.js®** is a JavaScript runtime built on Chrome's V8 JavaScript engine.
* **Node.js®** is a JavaScript runtime built on Chrome's V8 JavaScript engine.
* **Google chrome** a cross-platform web browser.
* **Node.js®** a JavaScript runtime built on Chrome's V8 JavaScript engine.
* **Pulseaudio** a sound server that provides a number of features on top of the low-level audio interface ALSA on Linux.

## Comparison with the existing solutions
Most of the existing open source solution render web pages badly and they mainly lack audio support.
This solution rised to mitigate these issues.

## How to test it

```bash
docker run --rm \
-v /tmp/:/recordings/ \
-e URL=https://www.youtube.com/watch?v=PBYKqvDK8d8 \
-e DURATION=20 \
-e OUTPUT_FILENAME=forever_tracey.mp4 \
cipheredbytes/url-to-video
```

## How to test it
You will notice a new file created in the following destination [/tmp/forever_tracey.mp4](https://github.com/OmarTrigui/url-to-video/raw/master/samples/forever_tracey.mp4).

Go to the directory where you want to create your project and run:
## Development

Go to the project directory and run the following command:

```bash
git https://github.com/OmarTrigui/url-to-video.git && cd url-to-video/
make docker.build docker.run
```

You will notice a new file created in the following destination `/tmp/forever_tracey.mp4`


## TODO list

- [ ] Support pub/sub pattern (SQS queue)
- [ ] Add K8s deployments / docker compose
- [ ] Add E2E tests
- [ ] Tweak recording performance
- [ ] Add Pub/Sub support (either [SQS](https://aws.amazon.com/sqs/) or [Kafka](https://kafka.apache.org/))


## Calling all contributors!
Are you eager to use your skills to do good and aid humanity? We are building a very ambitious software and your contribution could make a huge difference.
## Contributing
Contributions are always welcome, whether adding/suggesting new features, bug fixes,
documenting new file formats or simply editing some grammar.
4 changes: 4 additions & 0 deletions contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contributors to html-to-video
Includes all git commit authors. Aliases are GitHub user names.

* OmarTrigui
4 changes: 0 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ launch_xvfb() {
fi
fi

# Set defaults if the user did not specify envs.
export DISPLAY=${XVFB_DISPLAY:-:1}
local screen=${XVFB_SCREEN:-0}
local resolution=${XVFB_RESOLUTION:-1280x720x24}
local timeout=${XVFB_TIMEOUT:-5}

# Start and wait for either Xvfb to be fully up or we hit the timeout.
Xvfb "${DISPLAY}" -screen "${screen}" "${resolution}" &
local loopCount=0
until xdpyinfo -display "${DISPLAY}" > /dev/null 2>&1
Expand All @@ -45,12 +43,10 @@ launch_pulseaudio(){
pulseaudio -D --exit-idle-time=-1 &
}


log_i() {
log "[INFO] ${@}"
}


log_e() {
log "[ERROR] ${@}"
}
Expand Down
15 changes: 11 additions & 4 deletions k8s/job.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
apiVersion: batch/v1
kind: Job
metadata:
name: url2video
name: url-to-video
spec:
template:
spec:
containers:
- name: url2video
image: omartrigui/url-to-video
- name: url-to-video
image: cipheredbytes/url-to-video
volumeMounts:
- name: recordings
mountPath: /recordings/
env:
- name: URL
value: "https://www.youtube.com/watch?v=PBYKqvDK8d8"
Expand All @@ -16,4 +19,8 @@ spec:
- name: OUTPUT_FILENAME
value: "forever_tracey.mp4"
restartPolicy: Never
backoffLimit: 2aa
volumes:
- name: recordings
persistentVolumeClaim:
claimName: recordings-pv-claim
backoffLimit: 2
49 changes: 26 additions & 23 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,41 @@ function getStartRecordingCommand () {
'-strict -2 ' +
'-ar 44100 ' +
`-t ${process.env.DURATION} ` +
`/output/${process.env.OUTPUT_FILENAME}`
`/recordings/${process.env.OUTPUT_FILENAME}`
}

async function init () {
let client
try {
exec(getStartChromeCommand())
async function startChrome () {
exec(getStartChromeCommand())

await waitOn(opts)
await waitOn(opts)

client = await CDP()
const client = await CDP()

const {
Network,
Page
} = client
const { Network, Page } = client

Network.requestWillBeSent((params) => {
console.log(params.request.url)
})
Network.requestWillBeSent((params) => {
console.log(`Requested URL: ${params.request.url}`)
})

await Network.enable()
await Page.enable()
await Page.navigate({
url: process.env.URL
})
await Page.loadEventFired()
await Network.enable()
await Page.enable()
await Page.navigate({
url: process.env.URL
})
await Page.loadEventFired()

console.log('All assets are loaded')
await exec(getStartRecordingCommand())
console.log('Recording is completed')
console.log('All assets are loaded')
}

async function fireRecorder () {
await exec(getStartRecordingCommand())
console.log('Recording completed')
}

async function init () {
try {
await startChrome()
await fireRecorder()
} catch (err) {
console.error(err)
} finally {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"author": "Omar Trigui",
"license": "MIT",
"dependencies": {
"chrome-remote-interface": "^0.28.2",
"wait-on": "^5.0.1"
Expand Down
Binary file added samples/forever_tracey.mp4
Binary file not shown.

0 comments on commit 18ef127

Please sign in to comment.