Prathamesh Sarjerao Vaidya commited on
Commit
484e5b0
·
1 Parent(s): 9b8ca8e

made changes

Browse files
Dockerfile CHANGED
@@ -1,8 +1,7 @@
1
  # Optimized Dockerfile for Dance Movement Analyzer
2
- # Fixes MediaPipe model permission issues
3
 
4
- # FROM python:3.10-slim
5
- FROM python:3.10
6
 
7
  # Set environment variables
8
  ENV PYTHONUNBUFFERED=1 \
@@ -11,31 +10,21 @@ ENV PYTHONUNBUFFERED=1 \
11
  PIP_DISABLE_PIP_VERSION_CHECK=1 \
12
  DEBIAN_FRONTEND=noninteractive
13
 
14
- # Install system dependencies
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
- mesa-utils \
17
  libgl1 \
18
- # libgl1-mesa-glx \
19
  libglib2.0-0 \
20
  libsm6 \
21
  libxext6 \
22
  libxrender-dev \
23
  libgomp1 \
24
  ffmpeg \
 
25
  curl \
26
- tar \
27
- xz-utils \
28
  && rm -rf /var/lib/apt/lists/*
29
 
30
- # Install static ffmpeg build (includes libx264)
31
- RUN echo "Installing static ffmpeg..." \
32
- && curl -L -o /tmp/ffmpeg.tar.xz "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" \
33
- && tar -xJf /tmp/ffmpeg.tar.xz -C /tmp \
34
- && cp /tmp/ffmpeg-*-static/ffmpeg /usr/local/bin/ffmpeg \
35
- && cp /tmp/ffmpeg-*-static/ffprobe /usr/local/bin/ffprobe \
36
- && chmod +x /usr/local/bin/ffmpeg /usr/local/bin/ffprobe \
37
- && rm -rf /tmp/ffmpeg* \
38
- && ffmpeg -version
39
 
40
  # Create app directory
41
  WORKDIR /app
 
1
  # Optimized Dockerfile for Dance Movement Analyzer
2
+ # Fixes MediaPipe models and FFmpeg H.264 encoder issues
3
 
4
+ FROM python:3.10-slim
 
5
 
6
  # Set environment variables
7
  ENV PYTHONUNBUFFERED=1 \
 
10
  PIP_DISABLE_PIP_VERSION_CHECK=1 \
11
  DEBIAN_FRONTEND=noninteractive
12
 
13
+ # Install system dependencies including FFmpeg with H.264 support
14
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
15
  libgl1 \
 
16
  libglib2.0-0 \
17
  libsm6 \
18
  libxext6 \
19
  libxrender-dev \
20
  libgomp1 \
21
  ffmpeg \
22
+ libavcodec-extra \
23
  curl \
 
 
24
  && rm -rf /var/lib/apt/lists/*
25
 
26
+ # Verify FFmpeg has H.264 encoder
27
+ RUN ffmpeg -codecs | grep h264 || echo "Warning: H.264 encoder may not be available"
 
 
 
 
 
 
 
28
 
29
  # Create app directory
30
  WORKDIR /app
backend/app/config.py CHANGED
@@ -78,8 +78,8 @@ class Config:
78
  BATCH_SIZE: int = int(os.getenv("BATCH_SIZE", 30)) # Frames per batch
79
 
80
  # Output settings
81
- # OUTPUT_VIDEO_CODEC: str = os.getenv("OUTPUT_VIDEO_CODEC", "mp4v")
82
- OUTPUT_VIDEO_CODEC: str = os.getenv("OUTPUT_VIDEO_CODEC", "avc1")
83
  OUTPUT_VIDEO_FPS: int = int(os.getenv("OUTPUT_VIDEO_FPS", 30))
84
  OUTPUT_VIDEO_QUALITY: int = int(os.getenv("OUTPUT_VIDEO_QUALITY", 90))
85
 
 
78
  BATCH_SIZE: int = int(os.getenv("BATCH_SIZE", 30)) # Frames per batch
79
 
80
  # Output settings
81
+ OUTPUT_VIDEO_CODEC: str = os.getenv("OUTPUT_VIDEO_CODEC", "mp4v")
82
+ # OUTPUT_VIDEO_CODEC: str = os.getenv("OUTPUT_VIDEO_CODEC", "avc1")
83
  OUTPUT_VIDEO_FPS: int = int(os.getenv("OUTPUT_VIDEO_FPS", 30))
84
  OUTPUT_VIDEO_QUALITY: int = int(os.getenv("OUTPUT_VIDEO_QUALITY", 90))
85
 
backend/app/video_processor.py CHANGED
@@ -113,17 +113,58 @@ class VideoProcessor:
113
  cap = cv2.VideoCapture(str(video_path))
114
 
115
  # Setup video writer
116
- # fourcc = cv2.VideoWriter_fourcc(*'mp4v')
117
- fourcc = cv2.VideoWriter_fourcc(*Config.OUTPUT_VIDEO_CODEC)
118
- out = cv2.VideoWriter(
119
- str(output_path),
120
- fourcc,
121
- video_info['fps'],
122
- (video_info['width'], video_info['height'])
123
- )
124
-
125
- if not out.isOpened():
126
- raise ValueError(f"Cannot create output video: {output_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
  frame_number = 0
129
  processed_frames = 0
 
113
  cap = cv2.VideoCapture(str(video_path))
114
 
115
  # Setup video writer
116
+ # # fourcc = cv2.VideoWriter_fourcc(*'mp4v')
117
+ # fourcc = cv2.VideoWriter_fourcc(*Config.OUTPUT_VIDEO_CODEC)
118
+ # out = cv2.VideoWriter(
119
+ # str(output_path),
120
+ # fourcc,
121
+ # video_info['fps'],
122
+ # (video_info['width'], video_info['height'])
123
+ # )
124
+
125
+ # if not out.isOpened():
126
+ # raise ValueError(f"Cannot create output video: {output_path}")
127
+
128
+ # Setup video writer with codec fallback
129
+ codecs_to_try = [
130
+ ('mp4v', 'MPEG-4'), # Best compatibility
131
+ ('avc1', 'H.264'), # High quality (if available)
132
+ ('XVID', 'Xvid'), # Fallback option
133
+ ('MJPG', 'Motion JPEG') # Last resort
134
+ ]
135
+
136
+ out = None
137
+ last_error = None
138
+
139
+ for codec_code, codec_name in codecs_to_try:
140
+ try:
141
+ logger.info(f"Trying codec: {codec_name} ({codec_code})")
142
+ fourcc = cv2.VideoWriter_fourcc(*codec_code)
143
+ out = cv2.VideoWriter(
144
+ str(output_path),
145
+ fourcc,
146
+ video_info['fps'],
147
+ (video_info['width'], video_info['height'])
148
+ )
149
+
150
+ if out.isOpened():
151
+ logger.info(f"✅ Successfully initialized VideoWriter with {codec_name} codec")
152
+ break
153
+ else:
154
+ logger.warning(f"Failed to open VideoWriter with {codec_name}")
155
+ out.release()
156
+ out = None
157
+ except Exception as e:
158
+ logger.warning(f"Error with {codec_name} codec: {e}")
159
+ last_error = e
160
+ if out:
161
+ out.release()
162
+ out = None
163
+
164
+ if out is None or not out.isOpened():
165
+ error_msg = f"Cannot create output video with any codec. Last error: {last_error}"
166
+ logger.error(error_msg)
167
+ raise ValueError(error_msg)
168
 
169
  frame_number = 0
170
  processed_frames = 0