Unverified Commit 32f21dad authored by Quentin Duval's avatar Quentin Duval Committed by GitHub
Browse files

Fix: PyAV does not support floating point numbers with decimals as FPS when...

Fix: PyAV does not support floating point numbers with decimals as FPS when writing and will throw in case this constraint is not satisfied. (#2334)
parent cd2b7f07
...@@ -2,7 +2,7 @@ import gc ...@@ -2,7 +2,7 @@ import gc
import math import math
import re import re
import warnings import warnings
from typing import Tuple, List from typing import List, Tuple, Union
import numpy as np import numpy as np
import torch import torch
...@@ -49,7 +49,7 @@ _CALLED_TIMES = 0 ...@@ -49,7 +49,7 @@ _CALLED_TIMES = 0
_GC_COLLECTION_INTERVAL = 10 _GC_COLLECTION_INTERVAL = 10
def write_video(filename, video_array, fps, video_codec="libx264", options=None): def write_video(filename, video_array, fps: Union[int, float], video_codec="libx264", options=None):
""" """
Writes a 4d tensor in [T, H, W, C] format in a video file Writes a 4d tensor in [T, H, W, C] format in a video file
...@@ -65,6 +65,11 @@ def write_video(filename, video_array, fps, video_codec="libx264", options=None) ...@@ -65,6 +65,11 @@ def write_video(filename, video_array, fps, video_codec="libx264", options=None)
_check_av_available() _check_av_available()
video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy() video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy()
# PyAV does not support floating point numbers with decimal point
# and will throw OverflowException in case this is not the case
if isinstance(fps, float):
fps = np.round(fps)
container = av.open(filename, mode="w") container = av.open(filename, mode="w")
stream = container.add_stream(video_codec, rate=fps) stream = container.add_stream(video_codec, rate=fps)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment