Browse Source

docker linux use

master
gsd 8 months ago
parent
commit
4b2740ef89
  1. 2
      .dockerignore
  2. 5
      .gitignore
  3. 29
      Dockerfile
  4. 3
      convert.sh
  5. 3
      docker-compose.yaml
  6. 45
      ffmpeg.py

2
.dockerignore

@ -0,0 +1,2 @@
python-3.12.3-embed-win32
.git

5
.gitignore

@ -1 +1,4 @@
/python-3.12.3-embed-win32
/python-3.12.3-embed-win32
*.h264
*.h265
*.h265x

29
Dockerfile

@ -0,0 +1,29 @@
#https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-win32.zip
FROM ubuntu:22.04
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y ffmpeg wget unzip python3 \
&& mkdir -pm755 /etc/apt/keyrings \
&& wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key \
&& wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources \
&& apt-get update && apt-get install -y winehq-stable \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /opt/win32-python && cd /opt/win32-python \
&& wget https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-win32.zip \
&& unzip python-3.12.3-embed-win32.zip \
&& rm python-3.12.3-embed-win32.zip
RUN echo "wine test open python" \
&& cd /opt/win32-python \
&& wine python.exe --version
RUN mkdir /app
WORKDIR /app
COPY * ./
RUN wine /opt/win32-python/python.exe h264_converter.py --help
RUN python3 ffmpeg.py /dev/null --check-ffmpeg
ENTRYPOINT [ "tail", "-f", "/dev/null" ]

3
convert.sh

@ -0,0 +1,3 @@
#!/bin/bash
wine /opt/win32-python/python.exe h264_converter.py $1 && \
python3 ffmpeg.py "$1.avi" --out-format mp4

3
docker-compose.yaml

@ -0,0 +1,3 @@
services:
h264plus_converter:
build: ./

45
ffmpeg.py

@ -0,0 +1,45 @@
#this file to use only linux env's
from subprocess import call as sCall
from subprocess import DEVNULL
import os, sys
def check():
try:
if sCall(f"ffmpeg -version".split(), stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) != 0:
print("Cannot find ffmpeg, features must be disabled")
return False
else:
print("Enabled ffmpeg features!")
return True
except Exception as e:
print("cannot find ffmpeg", e)
return False
def convertAviToAny(source_file, out_format, print_statuses = False):
print(f"Start convertion to {out_format}")
sCall(f"ffmpeg -y -i {source_file} {source_file}.{out_format}".split(), stdin=None if print_statuses else DEVNULL, stdout=None if print_statuses else DEVNULL, stderr=None if print_statuses else DEVNULL)
if os.path.exists(f"{source_file}.{out_format}"):
print("convert to other format success")
os.remove(source_file)
else:
print("in process convert trubles convert")
sys.exit(2)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("file")
parser.add_argument("--out-format", type=str, default="avi", help = "output video file type")
parser.add_argument("--show-convertion", action="store_true", help = "show ffmpeg cenvertion statuses")
parser.add_argument("--check-ffmpeg", action="store_true")
args = parser.parse_args()
if args.check_ffmpeg:
sys.exit(0 if check() else 1)
if check():
convertAviToAny(args.file, args.out_format, args.show_convertion)
else:
print("ffmpeg is not installed")
sys.exit(1)
Loading…
Cancel
Save