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
4c7a91ef
Unverified
Commit
4c7a91ef
authored
Jan 24, 2022
by
Prabhat Roy
Committed by
GitHub
Jan 24, 2022
Browse files
Add support for get_metadata() in GPU decoder (#5256)
parent
44ae1e51
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
2 deletions
+33
-2
test/test_video_gpu_decoder.py
test/test_video_gpu_decoder.py
+13
-0
torchvision/csrc/io/decoder/gpu/demuxer.h
torchvision/csrc/io/decoder/gpu/demuxer.h
+8
-0
torchvision/csrc/io/decoder/gpu/gpu_decoder.cpp
torchvision/csrc/io/decoder/gpu/gpu_decoder.cpp
+11
-0
torchvision/csrc/io/decoder/gpu/gpu_decoder.h
torchvision/csrc/io/decoder/gpu/gpu_decoder.h
+1
-0
torchvision/io/__init__.py
torchvision/io/__init__.py
+0
-2
No files found.
test/test_video_gpu_decoder.py
View file @
4c7a91ef
import
math
import
os
import
os
import
pytest
import
pytest
...
@@ -36,6 +37,18 @@ class TestVideoGPUDecoder:
...
@@ -36,6 +37,18 @@ class TestVideoGPUDecoder:
mean_delta
=
torch
.
mean
(
torch
.
abs
(
av_frames
.
float
()
-
vision_frames
.
cpu
().
float
()))
mean_delta
=
torch
.
mean
(
torch
.
abs
(
av_frames
.
float
()
-
vision_frames
.
cpu
().
float
()))
assert
mean_delta
<
0.75
assert
mean_delta
<
0.75
@
pytest
.
mark
.
skipif
(
av
is
None
,
reason
=
"PyAV unavailable"
)
def
test_metadata
(
self
):
for
test_video
in
test_videos
:
full_path
=
os
.
path
.
join
(
VIDEO_DIR
,
test_video
)
decoder
=
VideoReader
(
full_path
,
device
=
"cuda:0"
)
video_metadata
=
decoder
.
get_metadata
()[
"video"
]
with
av
.
open
(
full_path
)
as
container
:
video
=
container
.
streams
.
video
[
0
]
av_duration
=
float
(
video
.
duration
*
video
.
time_base
)
assert
math
.
isclose
(
video_metadata
[
"duration"
],
av_duration
,
rel_tol
=
1e-2
)
assert
math
.
isclose
(
video_metadata
[
"fps"
],
video
.
base_rate
,
rel_tol
=
1e-2
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
pytest
.
main
([
__file__
])
pytest
.
main
([
__file__
])
torchvision/csrc/io/decoder/gpu/demuxer.h
View file @
4c7a91ef
...
@@ -142,6 +142,14 @@ class Demuxer {
...
@@ -142,6 +142,14 @@ class Demuxer {
return
eVideoCodec
;
return
eVideoCodec
;
}
}
double
get_duration
()
const
{
return
(
double
)
fmtCtx
->
duration
/
AV_TIME_BASE
;
}
double
get_fps
()
const
{
return
av_q2d
(
fmtCtx
->
streams
[
iVideoStream
]
->
r_frame_rate
);
}
bool
demux
(
uint8_t
**
video
,
unsigned
long
*
videoBytes
)
{
bool
demux
(
uint8_t
**
video
,
unsigned
long
*
videoBytes
)
{
if
(
!
fmtCtx
)
{
if
(
!
fmtCtx
)
{
return
false
;
return
false
;
...
...
torchvision/csrc/io/decoder/gpu/gpu_decoder.cpp
View file @
4c7a91ef
...
@@ -38,8 +38,19 @@ torch::Tensor GPUDecoder::decode() {
...
@@ -38,8 +38,19 @@ torch::Tensor GPUDecoder::decode() {
return
frame
;
return
frame
;
}
}
c10
::
Dict
<
std
::
string
,
c10
::
Dict
<
std
::
string
,
double
>>
GPUDecoder
::
get_metadata
()
const
{
c10
::
Dict
<
std
::
string
,
c10
::
Dict
<
std
::
string
,
double
>>
metadata
;
c10
::
Dict
<
std
::
string
,
double
>
video_metadata
;
video_metadata
.
insert
(
"duration"
,
demuxer
.
get_duration
());
video_metadata
.
insert
(
"fps"
,
demuxer
.
get_fps
());
metadata
.
insert
(
"video"
,
video_metadata
);
return
metadata
;
}
TORCH_LIBRARY
(
torchvision
,
m
)
{
TORCH_LIBRARY
(
torchvision
,
m
)
{
m
.
class_
<
GPUDecoder
>
(
"GPUDecoder"
)
m
.
class_
<
GPUDecoder
>
(
"GPUDecoder"
)
.
def
(
torch
::
init
<
std
::
string
,
int64_t
>
())
.
def
(
torch
::
init
<
std
::
string
,
int64_t
>
())
.
def
(
"get_metadata"
,
&
GPUDecoder
::
get_metadata
)
.
def
(
"next"
,
&
GPUDecoder
::
decode
);
.
def
(
"next"
,
&
GPUDecoder
::
decode
);
}
}
torchvision/csrc/io/decoder/gpu/gpu_decoder.h
View file @
4c7a91ef
...
@@ -8,6 +8,7 @@ class GPUDecoder : public torch::CustomClassHolder {
...
@@ -8,6 +8,7 @@ class GPUDecoder : public torch::CustomClassHolder {
GPUDecoder
(
std
::
string
,
int64_t
);
GPUDecoder
(
std
::
string
,
int64_t
);
~
GPUDecoder
();
~
GPUDecoder
();
torch
::
Tensor
decode
();
torch
::
Tensor
decode
();
c10
::
Dict
<
std
::
string
,
c10
::
Dict
<
std
::
string
,
double
>>
get_metadata
()
const
;
private:
private:
Demuxer
demuxer
;
Demuxer
demuxer
;
...
...
torchvision/io/__init__.py
View file @
4c7a91ef
...
@@ -185,8 +185,6 @@ class VideoReader:
...
@@ -185,8 +185,6 @@ class VideoReader:
Returns:
Returns:
(dict): dictionary containing duration and frame rate for every stream
(dict): dictionary containing duration and frame rate for every stream
"""
"""
if
self
.
is_cuda
:
raise
RuntimeError
(
"get_metadata() not yet supported with GPU decoding."
)
return
self
.
_c
.
get_metadata
()
return
self
.
_c
.
get_metadata
()
def
set_current_stream
(
self
,
stream
:
str
)
->
bool
:
def
set_current_stream
(
self
,
stream
:
str
)
->
bool
:
...
...
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