Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
b0d9eab7
Commit
b0d9eab7
authored
Nov 28, 2017
by
Mark Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/hw_decode: Use hw-config information to find pixfmt
This removes all remaining device-type specificity.
parent
8d51d10e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
32 deletions
+22
-32
hw_decode.c
doc/examples/hw_decode.c
+22
-32
No files found.
doc/examples/hw_decode.c
View file @
b0d9eab7
...
@@ -44,34 +44,6 @@ static AVBufferRef *hw_device_ctx = NULL;
...
@@ -44,34 +44,6 @@ static AVBufferRef *hw_device_ctx = NULL;
static
enum
AVPixelFormat
hw_pix_fmt
;
static
enum
AVPixelFormat
hw_pix_fmt
;
static
FILE
*
output_file
=
NULL
;
static
FILE
*
output_file
=
NULL
;
static
enum
AVPixelFormat
find_fmt_by_hw_type
(
const
enum
AVHWDeviceType
type
)
{
enum
AVPixelFormat
fmt
;
switch
(
type
)
{
case
AV_HWDEVICE_TYPE_VAAPI
:
fmt
=
AV_PIX_FMT_VAAPI
;
break
;
case
AV_HWDEVICE_TYPE_DXVA2
:
fmt
=
AV_PIX_FMT_DXVA2_VLD
;
break
;
case
AV_HWDEVICE_TYPE_D3D11VA
:
fmt
=
AV_PIX_FMT_D3D11
;
break
;
case
AV_HWDEVICE_TYPE_VDPAU
:
fmt
=
AV_PIX_FMT_VDPAU
;
break
;
case
AV_HWDEVICE_TYPE_VIDEOTOOLBOX
:
fmt
=
AV_PIX_FMT_VIDEOTOOLBOX
;
break
;
default:
fmt
=
AV_PIX_FMT_NONE
;
break
;
}
return
fmt
;
}
static
int
hw_decoder_init
(
AVCodecContext
*
ctx
,
const
enum
AVHWDeviceType
type
)
static
int
hw_decoder_init
(
AVCodecContext
*
ctx
,
const
enum
AVHWDeviceType
type
)
{
{
int
err
=
0
;
int
err
=
0
;
...
@@ -184,18 +156,22 @@ int main(int argc, char *argv[])
...
@@ -184,18 +156,22 @@ int main(int argc, char *argv[])
AVCodec
*
decoder
=
NULL
;
AVCodec
*
decoder
=
NULL
;
AVPacket
packet
;
AVPacket
packet
;
enum
AVHWDeviceType
type
;
enum
AVHWDeviceType
type
;
int
i
;
if
(
argc
<
4
)
{
if
(
argc
<
4
)
{
fprintf
(
stderr
,
"Usage: %s <
vaapi|vdpau|dxva2|d3d11va
> <input file> <output file>
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"Usage: %s <
device type
> <input file> <output file>
\n
"
,
argv
[
0
]);
return
-
1
;
return
-
1
;
}
}
av_register_all
();
av_register_all
();
type
=
av_hwdevice_find_type_by_name
(
argv
[
1
]);
type
=
av_hwdevice_find_type_by_name
(
argv
[
1
]);
hw_pix_fmt
=
find_fmt_by_hw_type
(
type
);
if
(
type
==
AV_HWDEVICE_TYPE_NONE
)
{
if
(
hw_pix_fmt
==
-
1
)
{
fprintf
(
stderr
,
"Device type %s is not supported.
\n
"
,
argv
[
1
]);
fprintf
(
stderr
,
"Cannot support '%s' in this example.
\n
"
,
argv
[
1
]);
fprintf
(
stderr
,
"Available device types:"
);
while
((
type
=
av_hwdevice_iterate_types
(
type
))
!=
AV_HWDEVICE_TYPE_NONE
)
fprintf
(
stderr
,
" %s"
,
av_hwdevice_get_type_name
(
type
));
fprintf
(
stderr
,
"
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -218,6 +194,20 @@ int main(int argc, char *argv[])
...
@@ -218,6 +194,20 @@ int main(int argc, char *argv[])
}
}
video_stream
=
ret
;
video_stream
=
ret
;
for
(
i
=
0
;;
i
++
)
{
const
AVCodecHWConfig
*
config
=
avcodec_get_hw_config
(
decoder
,
i
);
if
(
!
config
)
{
fprintf
(
stderr
,
"Decoder %s does not support device type %s.
\n
"
,
decoder
->
name
,
av_hwdevice_get_type_name
(
type
));
return
-
1
;
}
if
(
config
->
methods
&
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
&&
config
->
device_type
==
type
)
{
hw_pix_fmt
=
config
->
pix_fmt
;
break
;
}
}
if
(
!
(
decoder_ctx
=
avcodec_alloc_context3
(
decoder
)))
if
(
!
(
decoder_ctx
=
avcodec_alloc_context3
(
decoder
)))
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
...
...
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