Skip to content

Commit c20c38d

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Fixed missing audio with video_reader backend (#3934)
Summary: * Fixed missing audio with video_reader backend * Added unit test Reviewed By: fmassa Differential Revision: D29264318 fbshipit-source-id: de95e0bd38d2f844c756652fe42de99b1ab32210
1 parent 7c776fb commit c20c38d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

test/test_video_reader.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,17 @@ def test_invalid_file(self):
12441244
with self.assertRaises(RuntimeError):
12451245
io.read_video('foo.mp4')
12461246

1247+
def test_audio_present(self):
1248+
"""Test if audio frames are returned with video_reader backend."""
1249+
set_video_backend('video_reader')
1250+
for test_video, _ in test_videos.items():
1251+
full_path = os.path.join(VIDEO_DIR, test_video)
1252+
container = av.open(full_path)
1253+
if container.streams.audio:
1254+
_, audio, _ = io.read_video(full_path)
1255+
self.assertGreaterEqual(audio.shape[0], 1)
1256+
self.assertGreaterEqual(audio.shape[1], 1)
1257+
12471258

12481259
if __name__ == "__main__":
12491260
unittest.main()

torchvision/io/_video_opt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _align_audio_frames(aframes, aframe_pts, audio_pts_range):
122122
e_idx = num_samples
123123
if start < audio_pts_range[0]:
124124
s_idx = int((audio_pts_range[0] - start) / step_per_aframe)
125-
if end > audio_pts_range[1]:
125+
if audio_pts_range[1] != -1 and end > audio_pts_range[1]:
126126
e_idx = int((audio_pts_range[1] - end) / step_per_aframe)
127127
return aframes[s_idx:e_idx, :]
128128

0 commit comments

Comments
 (0)