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

Feature/cli (#1) #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build, Run and Publish binary

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
strategy:
matrix:
platform: ["linux/amd64", "linux/arm64"]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Save platform as a new variable
id: save_platform
run: echo "::set-output name=platform::$(echo ${{ matrix.platform }} | tr '/' '-')"

- name: Create and use builder
run: |
docker buildx create --name captions-builder --use
docker buildx inspect --bootstrap

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}/captions-${{ steps.save_platform.outputs.platform }}
cache-from: type=gha, scope=${{ steps.save_platform.outputs.platform }}
cache-to: type=gha, scope=${{ steps.save_platform.outputs.platform }}, mode=max
platforms: ${{ matrix.platform }}

- name: Run the Docker image
run: mkdir -p ./${{ matrix.platform }} && docker run --platform=${{ matrix.platform }} -v ./${{ matrix.platform }}:/app/out ghcr.io/${{ github.repository }}/captions-${{ steps.save_platform.outputs.platform }}

- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ steps.save_platform.outputs.platform }}
path: ./${{ matrix.platform }}/captions

release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download amd64 artifact
uses: actions/download-artifact@v2
with:
name: linux-amd64
path: ./linux/amd64/

- name: Download arm64 artifact
uses: actions/download-artifact@v2
with:
name: linux-arm64
path: ./linux/arm64/
- name: Get commit SHA
id: get_sha
run: |
SHA=$(git rev-parse --short HEAD)
echo "SHA: $SHA"
echo "::set-output name=sha_short::$SHA"

- name: Calculate arm64 binary checksum
id: arm64_checksum
run: echo "::set-output name=sha256::$(sha256sum ./linux/arm64/captions | awk '{print $1}')"

- name: Calculate amd64 binary checksum
id: amd64_checksum
run: echo "::set-output name=sha256::$(sha256sum ./linux/amd64/captions | awk '{print $1}')"

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_sha.outputs.sha_short }}
release_name: Release ${{ steps.get_sha.outputs.sha_short }}
body: |
Commit SHA: ${{ steps.get_sha.outputs.sha_short }}
Binary SHA256 checksum (linux/amd64): ${{ steps.amd64_checksum.outputs.sha256 }}
Binary SHA256 checksum (linux/arm64): ${{ steps.arm64_checksum.outputs.sha256 }}
draft: false
prerelease: false
- name: Upload Release Asset for linux/amd64
id: upload-release-asset-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linux/amd64/captions
asset_name: captions-linux-amd64
asset_content_type: application/octet-stream

- name: Upload Release Asset for linux/arm64
id: upload-release-asset-arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linux/arm64/captions
asset_name: captions-linux-arm64
asset_content_type: application/octet-stream
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.vscode/
.vscode/
output/
scripts/fixtures/
captions
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
_This was built on a mac m1: for various machines, changes may have to be made._
_Dockerfile was built to work on Google Cloud Run_

## Compile

```
sh ./scripts/compile
```
Binaries for different platforms can be built using `docker buildx` and specifying a --platform directive. Tested platforms are `linux/amd64` and `linux/arm64`.

## Run Server
```bash
docker buildx create --name captions-builder --use
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64 -t captions .
docker run --platform=linux/amd64 -v .:/app/out captions

```
./main
./captions
```

## Trigger Job

Use PostMan to send a request to `http://localhost:8080` send a raw body that looks something like this
## Run command

```bash
./captions \
--input input.mp4 \
--segments segments.json \
--output output.mp4 \
--font "Montserrat ExtraBold 56" \
--highlighter true \
--text_color "#f6be0e"
```
{
"video_filename": "https://storage.googleapis.com/ai-video-maker/clop1ciqu0007vynmu65snejx_edited.mp4",
"json_url": "https://storage.googleapis.com/ai-video-maker/transcription_clop1ciqu0007vynmu65snejx.json",
"output_name": "lol",
"font": "Montserrat ExtraBold 56",
"highlighter": false,
"text_color": "#f6be0e"
}

or with hosted assets...

```bash
./captions \
--input https://example.com/input.mp4 \
--segments https://example.com/segments.json \
--output output.mp4 \
--font "Montserrat ExtraBold 56" \
--highlighter true \
--text_color "#f6be0e"
```
4 changes: 0 additions & 4 deletions cloudbuild.yaml

This file was deleted.

68 changes: 27 additions & 41 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,44 @@
# Use a base image with a C++ compiler
FROM gcc:11-bullseye AS build
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
# Set the working directory
WORKDIR /app

# Install the necessary libraries
RUN apt-get update && \
apt-get install -y libboost-system-dev libboost-thread-dev libasio-dev libcairo2-dev libpango1.0-dev libglib2.0-dev libcurl4-openssl-dev nlohmann-json3-dev pkg-config curl ffmpeg
apt-get install -y \
g++ \
libboost-system-dev \
libboost-thread-dev \
libasio-dev \
libcairo2-dev \
libpango1.0-dev \
libglib2.0-dev \
libcurl4-openssl-dev \
nlohmann-json3-dev \
pkg-config \
curl \
ffmpeg

# Copy the source file
COPY . .

RUN mkdir -p out

# Compile the application
RUN g++ -std=c++17 \
CMD g++ -std=c++17 \
`pkg-config --cflags --libs cairo pango pangocairo`\
src/captions.cpp \
src/main.cpp \
src/parallel_pngs/parallel_generate_pngs.cpp \
src/create_intermediate/create_intermediate_videos.cpp \
src/concatenate_videos/concatenate_videos.cpp \
-o captions-over \
-lboost_system \
-lcurl


# Use the same base image for the runtime
FROM gcc:11-bullseye

# Set the working directory
WORKDIR /app

# Set the Google Cloud credentials environment variable
ENV GOOGLE_APPLICATION_CREDENTIALS=./google-credentials.json

# Install the Google Cloud SDK and ffmpeg
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
apt-get update -y && apt-get install google-cloud-sdk ffmpeg -y

# Copy the binary from the build stage
COPY --from=build /app/captions-over .

# Copy the service account key file from the build stage
COPY --from=build /app/google-credentials.json ./google-credentials.json

# Install the runtime dependencies
RUN apt-get update && apt-get install -y libcairo2 libpango1.0-0 libpangocairo-1.0-0 libglib2.0-0 libboost-system1.74.0 libcurl4 && \
rm -rf /var/lib/apt/lists/*

COPY ./fonts/OpenSans-Bold.ttf ./
RUN mkdir -p /usr/share/fonts/truetype/
RUN install -m644 OpenSans-Bold.ttf /usr/share/fonts/truetype/
RUN rm ./OpenSans-Bold.ttf
RUN fc-cache -f -v
RUN fc-list | grep 'OpenSans'

# Set the command to run your program
CMD ["./captions-over"]
-o out/captions \
-lboost_system \
-lcurl \
-lpthread \
-lcairo \
-lpango-1.0 \
-lgobject-2.0 \
-lpangocairo-1.0
2 changes: 0 additions & 2 deletions file_list.txt

This file was deleted.

1 change: 0 additions & 1 deletion google-credentials.json

This file was deleted.

Loading