Skip to content

Commit

Permalink
Merge pull request #11 from stephengpope/feature/caption-video
Browse files Browse the repository at this point in the history
Feature/caption video
  • Loading branch information
stephengpope authored Sep 19, 2024
2 parents 8d7ad03 + ac688e9 commit 585b7de
Show file tree
Hide file tree
Showing 68 changed files with 406 additions and 6 deletions.
114 changes: 111 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,119 @@
# Base image
FROM python:3.9-slim

# Install system dependencies
# Install system dependencies, build tools, and libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
ca-certificates \
wget \
tar \
xz-utils \
fonts-liberation \
fontconfig \
build-essential \
yasm \
cmake \
meson \
ninja-build \
nasm \
libssl-dev \
libvpx-dev \
libx264-dev \
libx265-dev \
libnuma-dev \
libmp3lame-dev \
libopus-dev \
libvorbis-dev \
libtheora-dev \
libspeex-dev \
libass-dev \
libfreetype6-dev \
libfontconfig1-dev \
libgnutls28-dev \
libaom-dev \
libdav1d-dev \
librav1e-dev \
libsvtav1-dev \
libzimg-dev \
libwebp-dev \
git \
pkg-config \
autoconf \
automake \
libtool \
&& rm -rf /var/lib/apt/lists/*

# Install SRT from source (latest version using cmake)
RUN git clone https://github.com/Haivision/srt.git && \
cd srt && \
mkdir build && cd build && \
cmake .. && \
make -j$(nproc) && \
make install && \
cd ../.. && rm -rf srt

# Install SVT-AV1 from source
RUN git clone https://gitlab.com/AOMediaCodec/SVT-AV1.git && \
cd SVT-AV1 && \
git checkout v0.9.0 && \
cd Build && \
cmake .. && \
make -j$(nproc) && \
make install && \
cd ../.. && rm -rf SVT-AV1

# Install libvmaf from source
RUN git clone https://github.com/Netflix/vmaf.git && \
cd vmaf/libvmaf && \
meson build --buildtype release && \
ninja -C build && \
ninja -C build install && \
cd ../.. && rm -rf vmaf && \
ldconfig # Update the dynamic linker cache

# Manually build and install fdk-aac (since it is not available via apt-get)
RUN git clone https://github.com/mstorsjo/fdk-aac && \
cd fdk-aac && \
autoreconf -fiv && \
./configure && \
make -j$(nproc) && \
make install && \
cd .. && rm -rf fdk-aac

# Build and install FFmpeg with all required features (without macOS-specific options)
RUN git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg && \
cd ffmpeg && \
git checkout n7.0.2 && \
./configure --prefix=/usr/local \
--enable-gpl \
--enable-pthreads \
--enable-neon \
--enable-libaom \
--enable-libdav1d \
--enable-librav1e \
--enable-libsvtav1 \
--enable-libvmaf \
--enable-libzimg \
--enable-libx264 \
--enable-libx265 \
--enable-libvpx \
--enable-libwebp \
--enable-libmp3lame \
--enable-libopus \
--enable-libvorbis \
--enable-libtheora \
--enable-libspeex \
--enable-libass \
--enable-libfreetype \
--enable-fontconfig \
--enable-libsrt \
--enable-gnutls && \
make -j$(nproc) && \
make install && \
cd .. && rm -rf ffmpeg

# Add /usr/local/bin to PATH (if not already included)
ENV PATH="/usr/local/bin:${PATH}"

# Set work directory
WORKDIR /app

Expand Down Expand Up @@ -38,4 +146,4 @@ ENV PYTHONUNBUFFERED=1
EXPOSE 8080

# Run the application with Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "300", "app:app"]
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "300", "app:app"]
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from routes.audio_mixing import audio_mixing_bp
from routes.gdrive_upload import gdrive_upload_bp
from routes.authentication import auth_bp # Import the auth_bp blueprint
from routes.caption_video import caption_bp

app = Flask(__name__)

Expand All @@ -15,6 +16,7 @@
app.register_blueprint(audio_mixing_bp)
app.register_blueprint(gdrive_upload_bp)
app.register_blueprint(auth_bp) # Register the auth_bp blueprint
app.register_blueprint(caption_bp)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
Binary file added fonts/ARIALBD 1.TTF
Binary file not shown.
Binary file added fonts/ARIALBD.TTF
Binary file not shown.
Binary file added fonts/ARIALBI 1.TTF
Binary file not shown.
Binary file added fonts/ARIALBI.TTF
Binary file not shown.
Binary file added fonts/ARIALBLACKITALIC.TTF
Binary file not shown.
Binary file added fonts/ARIALI 1.TTF
Binary file not shown.
Binary file added fonts/ARIALI.TTF
Binary file not shown.
Binary file added fonts/ARIALLGT.TTF
Binary file not shown.
Binary file added fonts/ARIALLGTITL.TTF
Binary file not shown.
Binary file added fonts/ARIALN.TTF
Binary file not shown.
Binary file added fonts/ARIALNB.TTF
Binary file not shown.
Binary file added fonts/ARIALNBI.TTF
Binary file not shown.
Binary file added fonts/ARIALNI.TTF
Binary file not shown.
Binary file added fonts/ARIBLK.TTF
Binary file not shown.
Binary file added fonts/Arial.ttf
Binary file not shown.
Binary file added fonts/ArialCE.ttf
Binary file not shown.
Binary file added fonts/ArialCEBoldItalic.ttf
Binary file not shown.
Binary file added fonts/ArialCEItalic.ttf
Binary file not shown.
Binary file added fonts/ArialCEMTBlack.ttf
Binary file not shown.
Binary file added fonts/ArialMdm.ttf
Binary file not shown.
Binary file added fonts/ArialMdmItl.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-Bold.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-BoldItalic.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-Italic.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-Light.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-LightItalic.ttf
Binary file not shown.
Binary file added fonts/ComicNeue-Regular.ttf
Binary file not shown.
Binary file added fonts/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file added fonts/DejaVuSans-BoldOblique.ttf
Binary file not shown.
Binary file added fonts/DejaVuSans-ExtraLight.ttf
Binary file not shown.
Binary file added fonts/DejaVuSans-Oblique.ttf
Binary file not shown.
Binary file added fonts/DejaVuSans.ttf
Binary file not shown.
Binary file added fonts/DejaVuSansCondensed-Bold.ttf
Binary file not shown.
Binary file added fonts/DejaVuSansCondensed-BoldOblique.ttf
Binary file not shown.
Binary file added fonts/DejaVuSansCondensed-Oblique.ttf
Binary file not shown.
Binary file added fonts/DejaVuSansCondensed.ttf
Binary file not shown.
Binary file added fonts/FrederickatheGreat-Regular.ttf
Binary file not shown.
Binary file added fonts/LibreBaskerville-Bold.ttf
Binary file not shown.
Binary file added fonts/LibreBaskerville-Italic.ttf
Binary file not shown.
Binary file added fonts/LibreBaskerville-Regular.ttf
Binary file not shown.
Binary file added fonts/LuckiestGuy-Regular.ttf
Binary file not shown.
Binary file added fonts/NanumPenScript-Regular.ttf
Binary file not shown.
Binary file added fonts/Nunito-Italic-VariableFont_wght.ttf
Binary file not shown.
Binary file added fonts/Nunito-VariableFont_wght.ttf
Binary file not shown.
Binary file added fonts/Oswald-VariableFont_wght.ttf
Binary file not shown.
Binary file added fonts/Pacifico-Regular.ttf
Binary file not shown.
Binary file added fonts/PermanentMarker-Regular.ttf
Binary file not shown.
Binary file added fonts/Roboto-Black.ttf
Binary file not shown.
Binary file added fonts/Roboto-BlackItalic.ttf
Binary file not shown.
Binary file added fonts/Roboto-Bold.ttf
Binary file not shown.
Binary file added fonts/Roboto-BoldItalic.ttf
Binary file not shown.
Binary file added fonts/Roboto-Italic.ttf
Binary file not shown.
Binary file added fonts/Roboto-Light.ttf
Binary file not shown.
Binary file added fonts/Roboto-LightItalic.ttf
Binary file not shown.
Binary file added fonts/Roboto-Medium.ttf
Binary file not shown.
Binary file added fonts/Roboto-MediumItalic.ttf
Binary file not shown.
Binary file added fonts/Roboto-Regular.ttf
Binary file not shown.
Binary file added fonts/Roboto-Thin.ttf
Binary file not shown.
Binary file added fonts/Roboto-ThinItalic.ttf
Binary file not shown.
Binary file added fonts/Shrikhand-Regular.ttf
Binary file not shown.
Binary file added fonts/arialceb.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ google-auth-oauthlib
google-auth-httplib2
google-api-python-client
google-cloud-storage

psutil
10 changes: 10 additions & 0 deletions routes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .combine_videos import combine_bp
from .gdrive_upload import gdrive_upload_bp
from .media_to_mp3 import convert_bp
from .caption_video import caption_bp # Add this line

def register_blueprints(app):
app.register_blueprint(combine_bp)
app.register_blueprint(gdrive_upload_bp)
app.register_blueprint(convert_bp)
app.register_blueprint(caption_bp) # Add this line
87 changes: 87 additions & 0 deletions routes/caption_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from flask import Blueprint, request, jsonify
import uuid
import threading
import logging
from services.caption_video import process_captioning
from services.authentication import authenticate

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

caption_bp = Blueprint('caption', __name__)

def process_job(data, job_id):
try:
logger.info(f"Job {job_id}: Starting captioning process")
file_url = data['video_url']
caption_srt = data['srt']
options = data.get('options', {})

output_filename = process_captioning(file_url, caption_srt, options, job_id)

if 'webhook_url' in data:
send_webhook(data['webhook_url'], {
"endpoint": "/caption-video",
"code": 200,
"id": data.get("id"),
"job_id": job_id,
"response": output_filename,
"message": "success"
})

logger.info(f"Job {job_id}: Captioning process completed successfully")
return output_filename

except Exception as e:
logger.error(f"Job {job_id}: Error during processing - {e}")
if 'webhook_url' in data:
send_webhook(data['webhook_url'], {
"endpoint": "/caption-video",
"code": 500,
"id": data.get("id"),
"job_id": job_id,
"response": None,
"message": str(e),
})
else:
raise

@caption_bp.route('/caption-video', methods=['POST'])
@authenticate
def caption_video():
data = request.json

if 'X-API-Key' not in request.headers:
logger.error("Missing X-API-Key header")
return jsonify({"message": "Missing X-API-Key header"}), 400

if not all(k in data for k in ('video_url', 'srt')):
logger.error("video_url and srt are required")
return jsonify({"message": "video_url and srt are required"}), 400

job_id = str(uuid.uuid4())
logger.info(f"Processing Job ID: {job_id}")

if 'webhook_url' in data:
threading.Thread(target=process_job, args=(data, job_id)).start()
return jsonify({
"code": 202,
"id": data.get("id"),
"job_id": job_id,
"message": "processing"
}), 202
else:
try:
output_filename = process_job(data, job_id)
return jsonify({
"code": 200,
"response": output_filename,
"message": "success"
}), 200
except Exception as e:
logger.error(f"Job {job_id}: Error during synchronous processing - {e}")
return jsonify({
"code": 500,
"message": str(e)
}), 500
7 changes: 5 additions & 2 deletions services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from .audio_mixing import process_audio_mixing
from .authentication import authenticate
from .ffmpeg_toolkit import process_conversion, process_video_combination
from .audio_mixing import process_audio_mixing # Correct import
from .file_management import delete_old_files
from .file_management import download_file
from .gcp_toolkit import upload_to_gcs
from .transcription import process_transcription
from .caption_video import process_captioning # Add this line
Loading

0 comments on commit 585b7de

Please sign in to comment.