Skip to content

Commit

Permalink
fix(visualizer): do not use h264 when video is not even
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Apr 21, 2023
1 parent 2bd9d2f commit 2cd0b9e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/python/pose_format/pose_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import logging
import math
from functools import lru_cache
from typing import Tuple, Iterable
Expand Down Expand Up @@ -144,16 +145,20 @@ def save_video(self, f_name: str, frames: Iterable[np.ndarray], custom_ffmpeg=No
"-vcodec": "libx264",
"-preset": "fast",
"-input_framerate": self.pose.body.fps,
"-pix_fmt": "yuv420p",
}

# Define writer with defined parameters and suitable output filename for e.g. `Output.mp4`
out = WriteGear(output=f_name, logging=False, custom_ffmpeg=custom_ffmpeg, **output_params)
# out = cv2.VideoWriter(f_name, cv2.VideoWriter_fourcc(*'MP4V'), self.pose.body.fps, image_size)
writer = None # Define writer with defined parameters and suitable output filename for e.g. `Output.mp4`
for frame in tqdm(frames):
out.write(frame)
if writer is None: # Create writer on first frame
if frame.shape[0] % 2 == 0 and frame.shape[1] % 2 == 0:
output_params["-pix_fmt"] = "yuv420p" # H.264
else:
logging.warning(
"Video shape is not divisible by 2. Can not use H.264. Consider resizing to a divisible shape.")
writer = WriteGear(output=f_name, logging=False, custom_ffmpeg=custom_ffmpeg, **output_params)
writer.write(frame)

out.close()
writer.close()


class FastAndUglyPoseVisualizer(PoseVisualizer):
Expand Down

0 comments on commit 2cd0b9e

Please sign in to comment.