Unverified Commit b74366b8 authored by Prabhat Roy's avatar Prabhat Roy Committed by GitHub
Browse files

Fixed missing audio with video_reader backend (#3934)

* Fixed missing audio with video_reader backend

* Added unit test
parent 496cb40e
...@@ -1244,6 +1244,17 @@ class TestVideoReader(unittest.TestCase): ...@@ -1244,6 +1244,17 @@ class TestVideoReader(unittest.TestCase):
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
io.read_video('foo.mp4') io.read_video('foo.mp4')
def test_audio_present(self):
"""Test if audio frames are returned with video_reader backend."""
set_video_backend('video_reader')
for test_video, _ in test_videos.items():
full_path = os.path.join(VIDEO_DIR, test_video)
container = av.open(full_path)
if container.streams.audio:
_, audio, _ = io.read_video(full_path)
self.assertGreaterEqual(audio.shape[0], 1)
self.assertGreaterEqual(audio.shape[1], 1)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -155,7 +155,7 @@ def _align_audio_frames(aframes, aframe_pts, audio_pts_range): ...@@ -155,7 +155,7 @@ def _align_audio_frames(aframes, aframe_pts, audio_pts_range):
e_idx = num_samples e_idx = num_samples
if start < audio_pts_range[0]: if start < audio_pts_range[0]:
s_idx = int((audio_pts_range[0] - start) / step_per_aframe) s_idx = int((audio_pts_range[0] - start) / step_per_aframe)
if end > audio_pts_range[1]: if audio_pts_range[1] != -1 and end > audio_pts_range[1]:
e_idx = int((audio_pts_range[1] - end) / step_per_aframe) e_idx = int((audio_pts_range[1] - end) / step_per_aframe)
return aframes[s_idx:e_idx, :] return aframes[s_idx:e_idx, :]
......
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