Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
b74366b8
Unverified
Commit
b74366b8
authored
Jun 15, 2021
by
Prabhat Roy
Committed by
GitHub
Jun 15, 2021
Browse files
Fixed missing audio with video_reader backend (#3934)
* Fixed missing audio with video_reader backend * Added unit test
parent
496cb40e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
test/test_video_reader.py
test/test_video_reader.py
+11
-0
torchvision/io/_video_opt.py
torchvision/io/_video_opt.py
+1
-1
No files found.
test/test_video_reader.py
View file @
b74366b8
...
@@ -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
()
torchvision/io/_video_opt.py
View file @
b74366b8
...
@@ -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
,
:]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment