Skip to content

Commit

Permalink
🐛 Fix bug that inferenced video cannot play (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanpuhaha committed Feb 2, 2023
1 parent 7f0e621 commit ecf9f0f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from datetime import datetime
import os
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -134,7 +135,7 @@ def _inference_video(model_info: ModelInfo, video_filepath: FilePath) -> FilePat
visualizer = VISUALIZERS.build(model.cfg.visualizer)
visualizer.dataset_meta = model.dataset_meta
video_reader = mmcv.VideoReader(str(video_filepath))
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
fourcc = cv2.VideoWriter_fourcc(*"MP4V")
out_filepath = video_filepath.parent / (f"inferenced_{video_filepath.name}")
video_writer = cv2.VideoWriter(
str(out_filepath),
Expand All @@ -155,7 +156,13 @@ def _inference_video(model_info: ModelInfo, video_filepath: FilePath) -> FilePat
frame = visualizer.get_image()
video_writer.write(frame)
video_writer.release()
return out_filepath

new_filename = (
f'{video_filepath.stem}_inferenced{video_filepath.suffix}'
)
h264_filepath = video_filepath.with_name(new_filename)
os.system(f"/url/bin/ffmpeg -i {out_filepath} -vcodec libx264 {h264_filepath}")
return h264_filepath


class InferenceBody(BaseModel):
Expand Down

0 comments on commit ecf9f0f

Please sign in to comment.