Skip to content
Snippets Groups Projects
Unverified Commit 0d1c49f0 authored by Ahmet Oner's avatar Ahmet Oner Committed by GitHub
Browse files

Merge pull request #194 from ahmetoner/compile-ffmpeg

Add FFmpeg compiling Docker stage
parents be0beb0a b4d3f03a
Branches
No related tags found
No related merge requests found
...@@ -154,7 +154,7 @@ Unreleased ...@@ -154,7 +154,7 @@ Unreleased
- Fastapi init in #3 - Fastapi init in #3
- Avoid temp file in #4 - Avoid temp file in #4
- Translate init in #5 - Translate init in #5
- mp3 support by using ffmpeg instead of librosa in #8 - mp3 support by using FFmpeg instead of librosa in #8
- add language detection endpoint in #9 - add language detection endpoint in #9
[1.2.4]: https://github.com/ahmetoner/whisper-asr-webservice/releases/tag/v1.2.4 [1.2.4]: https://github.com/ahmetoner/whisper-asr-webservice/releases/tag/v1.2.4
......
FROM swaggerapi/swagger-ui:v5.9.1 AS swagger-ui FROM debian:bookworm-slim AS ffmpeg
FROM python:3.10-slim
ENV POETRY_VENV=/app/.venv
RUN export DEBIAN_FRONTEND=noninteractive \ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qq update \ && apt-get -qq update \
&& apt-get -qq install --no-install-recommends \ && apt-get -qq install --no-install-recommends \
ffmpeg \ build-essential \
git \
pkg-config \
yasm \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch n6.1.1 --single-branch /FFmpeg-6.1.1
WORKDIR /FFmpeg-6.1.1
RUN PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--bindir="$HOME/bin" \
--disable-doc \
--disable-htmlpages \
--disable-podpages \
--disable-txtpages \
--disable-network \
--disable-autodetect \
--disable-hwaccels \
--disable-ffprobe \
--disable-ffplay \
--enable-filter=copy \
--enable-protocol=file \
--enable-small && \
PATH="$HOME/bin:$PATH" make -j$(nproc) && \
make install && \
hash -r
FROM swaggerapi/swagger-ui:v5.9.1 AS swagger-ui
FROM python:3.10-bookworm
ENV POETRY_VENV=/app/.venv
RUN python3 -m venv $POETRY_VENV \ RUN python3 -m venv $POETRY_VENV \
&& $POETRY_VENV/bin/pip install -U pip setuptools \ && $POETRY_VENV/bin/pip install -U pip setuptools \
&& $POETRY_VENV/bin/pip install poetry==1.6.1 && $POETRY_VENV/bin/pip install poetry==1.6.1
...@@ -18,6 +53,8 @@ ENV PATH="${PATH}:${POETRY_VENV}/bin" ...@@ -18,6 +53,8 @@ ENV PATH="${PATH}:${POETRY_VENV}/bin"
WORKDIR /app WORKDIR /app
COPY . /app COPY . /app
COPY --from=ffmpeg /FFmpeg-6.1.1 /FFmpeg-6.1.1
COPY --from=ffmpeg /root/bin/ffmpeg /usr/local/bin/ffmpeg
COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui.css swagger-ui-assets/swagger-ui.css COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui.css swagger-ui-assets/swagger-ui.css
COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js swagger-ui-assets/swagger-ui-bundle.js COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js swagger-ui-assets/swagger-ui-bundle.js
......
FROM debian:bookworm-slim AS ffmpeg
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qq update \
&& apt-get -qq install --no-install-recommends \
build-essential \
git \
pkg-config \
yasm \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch n6.1.1 --single-branch /FFmpeg-6.1.1
WORKDIR /FFmpeg-6.1.1
RUN PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--bindir="$HOME/bin" \
--disable-doc \
--disable-htmlpages \
--disable-podpages \
--disable-txtpages \
--disable-network \
--disable-autodetect \
--disable-hwaccels \
--disable-ffprobe \
--disable-ffplay \
--enable-filter=copy \
--enable-protocol=file \
--enable-small && \
PATH="$HOME/bin:$PATH" make -j$(nproc) && \
make install && \
hash -r
FROM swaggerapi/swagger-ui:v5.9.1 AS swagger-ui FROM swaggerapi/swagger-ui:v5.9.1 AS swagger-ui
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
ENV PYTHON_VERSION=3.10 ENV PYTHON_VERSION=3.10
...@@ -10,7 +51,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \ ...@@ -10,7 +51,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \
python${PYTHON_VERSION} \ python${PYTHON_VERSION} \
python${PYTHON_VERSION}-venv \ python${PYTHON_VERSION}-venv \
python3-pip \ python3-pip \
ffmpeg \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 && \ RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 && \
...@@ -31,6 +71,8 @@ RUN poetry config virtualenvs.in-project true ...@@ -31,6 +71,8 @@ RUN poetry config virtualenvs.in-project true
RUN poetry install --no-root RUN poetry install --no-root
COPY . . COPY . .
COPY --from=ffmpeg /FFmpeg-6.1.1 /FFmpeg-6.1.1
COPY --from=ffmpeg /root/bin/ffmpeg /usr/local/bin/ffmpeg
COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui.css swagger-ui-assets/swagger-ui.css COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui.css swagger-ui-assets/swagger-ui.css
COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js swagger-ui-assets/swagger-ui-bundle.js COPY --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js swagger-ui-assets/swagger-ui-bundle.js
......
...@@ -32,5 +32,9 @@ for more information: ...@@ -32,5 +32,9 @@ for more information:
- [Documentation/Run](https://ahmetoner.github.io/whisper-asr-webservice/run) - [Documentation/Run](https://ahmetoner.github.io/whisper-asr-webservice/run)
- [Docker Hub](https://hub.docker.com/r/onerahmet/openai-whisper-asr-webservice) - [Docker Hub](https://hub.docker.com/r/onerahmet/openai-whisper-asr-webservice)
# Documentation ## Documentation
Explore the documentation by clicking [here](https://ahmetoner.github.io/whisper-asr-webservice). Explore the documentation by clicking [here](https://ahmetoner.github.io/whisper-asr-webservice).
## Credits
- This software uses libraries from the [FFmpeg](http://ffmpeg.org) project under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)
...@@ -87,7 +87,7 @@ async def asr( ...@@ -87,7 +87,7 @@ async def asr(
@app.post("/detect-language", tags=["Endpoints"]) @app.post("/detect-language", tags=["Endpoints"])
async def detect_language( async def detect_language(
audio_file: UploadFile = File(...), audio_file: UploadFile = File(...),
encode: bool = Query(default=True, description="Encode audio first through ffmpeg") encode: bool = Query(default=True, description="Encode audio first through FFmpeg")
): ):
detected_lang_code = language_detection(load_audio(audio_file.file, encode)) detected_lang_code = language_detection(load_audio(audio_file.file, encode))
return {"detected_language": tokenizer.LANGUAGES[detected_lang_code], "language_code": detected_lang_code} return {"detected_language": tokenizer.LANGUAGES[detected_lang_code], "language_code": detected_lang_code}
......
...@@ -24,3 +24,7 @@ for more information: ...@@ -24,3 +24,7 @@ for more information:
- [Documentation/Run](https://ahmetoner.github.io/whisper-asr-webservice/run) - [Documentation/Run](https://ahmetoner.github.io/whisper-asr-webservice/run)
- [Docker Hub](https://hub.docker.com/r/onerahmet/openai-whisper-asr-webservice) - [Docker Hub](https://hub.docker.com/r/onerahmet/openai-whisper-asr-webservice)
## Credits
- This software uses libraries from the [FFmpeg](http://ffmpeg.org) project under the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment