ghostsInTheMachine
commited on
Commit
•
1963b01
1
Parent(s):
0a17f2b
Update app.py
Browse files
app.py
CHANGED
@@ -47,7 +47,7 @@ def resize_and_pad(image, target_size):
|
|
47 |
return new_image
|
48 |
|
49 |
# Process a single frame through the depth model
|
50 |
-
def process_frame(frame, seed=0, target_size=(
|
51 |
"""Process a single frame and return depth map."""
|
52 |
try:
|
53 |
torch.cuda.empty_cache() # Clear GPU cache
|
@@ -104,7 +104,7 @@ def process_video(video_path, fps=0, seed=0):
|
|
104 |
depth_map = process_frame(frame, seed)
|
105 |
|
106 |
if depth_map is not None:
|
107 |
-
# Save frame
|
108 |
frame_path = os.path.join(frames_dir, f"frame_{i:06d}.png")
|
109 |
depth_map.save(frame_path, format='PNG', compress_level=0)
|
110 |
|
@@ -123,20 +123,20 @@ def process_video(video_path, fps=0, seed=0):
|
|
123 |
zip_path = os.path.join(temp_dir, zip_filename)
|
124 |
shutil.make_archive(zip_path[:-4], 'zip', frames_dir)
|
125 |
|
126 |
-
# Create MP4 video
|
127 |
video_filename = f"depth_video_{int(time.time())}.mp4"
|
128 |
output_video_path = os.path.join(temp_dir, video_filename)
|
129 |
|
130 |
try:
|
131 |
-
# FFmpeg settings for
|
132 |
input_pattern = os.path.join(frames_dir, 'frame_%06d.png')
|
133 |
(
|
134 |
ffmpeg
|
135 |
.input(input_pattern, pattern_type='sequence', framerate=fps)
|
136 |
-
.output(output_video_path, vcodec='libx264', pix_fmt='yuv420p',
|
137 |
.run(overwrite_output=True, quiet=True)
|
138 |
)
|
139 |
-
logger.info("MP4 video created successfully!")
|
140 |
|
141 |
except ffmpeg.Error as e:
|
142 |
logger.error(f"Error creating video: {e.stderr.decode() if e.stderr else str(e)}")
|
|
|
47 |
return new_image
|
48 |
|
49 |
# Process a single frame through the depth model
|
50 |
+
def process_frame(frame, seed=0, target_size=(1024, 1024)):
|
51 |
"""Process a single frame and return depth map."""
|
52 |
try:
|
53 |
torch.cuda.empty_cache() # Clear GPU cache
|
|
|
104 |
depth_map = process_frame(frame, seed)
|
105 |
|
106 |
if depth_map is not None:
|
107 |
+
# Save frame in lossless PNG format
|
108 |
frame_path = os.path.join(frames_dir, f"frame_{i:06d}.png")
|
109 |
depth_map.save(frame_path, format='PNG', compress_level=0)
|
110 |
|
|
|
123 |
zip_path = os.path.join(temp_dir, zip_filename)
|
124 |
shutil.make_archive(zip_path[:-4], 'zip', frames_dir)
|
125 |
|
126 |
+
# Create MP4 video with lossless encoding
|
127 |
video_filename = f"depth_video_{int(time.time())}.mp4"
|
128 |
output_video_path = os.path.join(temp_dir, video_filename)
|
129 |
|
130 |
try:
|
131 |
+
# FFmpeg settings for lossless MP4
|
132 |
input_pattern = os.path.join(frames_dir, 'frame_%06d.png')
|
133 |
(
|
134 |
ffmpeg
|
135 |
.input(input_pattern, pattern_type='sequence', framerate=fps)
|
136 |
+
.output(output_video_path, vcodec='libx264', pix_fmt='yuv420p', preset='veryslow', crf=0)
|
137 |
.run(overwrite_output=True, quiet=True)
|
138 |
)
|
139 |
+
logger.info("Lossless MP4 video created successfully!")
|
140 |
|
141 |
except ffmpeg.Error as e:
|
142 |
logger.error(f"Error creating video: {e.stderr.decode() if e.stderr else str(e)}")
|