10000 Add devcontainer.json and Dockerfile · sdk21/ffmpeg-python@99c3dad · GitHub
[go: up one dir, main page]

Skip to content

Commit 99c3dad

Browse files
committed
Add devcontainer.json and Dockerfile
1 parent df129c7 commit 99c3dad

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "ffmpeg-python-dev-container",
3+
"dockerFile": "Dockerfile",
4+
"settings": {
5+
"terminal.integrated.shell.linux": "/bin/bash"
6+
},
7+
"extensions": [
8+
"ms-python.python"
9+
],
10+
"forwardPorts": [],
11+
"postCreateCommand": "echo 'Welcome to your ffmpeg-python dev container!'"
12+
}
13+

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Use the official Python base image
2+
FROM python:3.9-slim
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Install FFmpeg
8+
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
9+
10+
# Clone the ffmpeg-python repository
11+
RUN apt-get update && apt-get install -y --no-install-recommends git && git clone https://github.com/kkroening/ffmpeg-python.git /app/ffmpeg-python && rm -rf /var/lib/apt/lists/*
12+
13+
# Install the required dependencies
14+
RUN pip install --no-cache-dir -r /app/ffmpeg-python/requirements.txt
15+
16+
# Optional: Set the entrypoint for the container
17+
ENTRYPOINT ["python"]
18+

sample_script.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
import requests
3+
import ffmpeg
4+
import tempfile
5+
6+
# Download a video file from the internet
7+
video_url = 'https://download.samplelib.com/mp4/sample-5s.mp4'
8+
9+
response = requests.get(video_url, stream=True)
10+
response.raise_for_status()
11+
12+
# Save the video to a temporary file
13+
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_video_file:
14+
for chunk in response.iter_content(chunk_size=8192):
15+
temp_video_file.write(chunk)
16+
temp_video_file.flush()
17+
18+
# Process the video using ffmpeg-python
19+
input_video = ffmpeg.input(temp_video_file.name)
20+
output_video = input_video.filter('scale', 320, 240).output('output_video.mp4')
21+
output_video.run()
22+
23+
print("Video processing completed. The output video is saved as output_video.mp4.")

0 commit comments

Comments
 (0)
0