Skip to content

Commit 32f21da

Browse files
authored
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)
1 parent cd2b7f0 commit 32f21da

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

torchvision/io/video.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import math
33
import re
44
import warnings
5-
from typing import Tuple, List
5+
from typing import List, Tuple, Union
66

77
import numpy as np
88
import torch
@@ -49,7 +49,7 @@ def _av_available():
4949
_GC_COLLECTION_INTERVAL = 10
5050

5151

52-
def write_video(filename, video_array, fps, video_codec="libx264", options=None):
52+
def write_video(filename, video_array, fps: Union[int, float], video_codec="libx264", options=None):
5353
"""
5454
Writes a 4d tensor in [T, H, W, C] format in a video file
5555
@@ -65,6 +65,11 @@ def write_video(filename, video_array, fps, video_codec="libx264", options=None)
6565
_check_av_available()
6666
video_array = torch.as_tensor(video_array, dtype=torch.uint8).numpy()
6767

68+
# PyAV does not support floating point numbers with decimal point
69+
# and will throw OverflowException in case this is not the case
70+
if isinstance(fps, float):
71+
fps = np.round(fps)
72+
6873
container = av.open(filename, mode="w")
6974

7075
stream = container.add_stream(video_codec, rate=fps)

0 commit comments

Comments
 (0)