Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xiph.Org
aom-rav1e
Commits
421bb4d4
Commit
421bb4d4
authored
Jan 28, 2016
by
clang-format
Committed by
James Zern
Jan 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply clang-format to the examples
Change-Id: I31e383b0e3312d6a07efa104c799ff9aa42d433f
parent
99e28b8b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
263 additions
and
332 deletions
+263
-332
examples/decode_to_md5.c
examples/decode_to_md5.c
+9
-14
examples/decode_with_drops.c
examples/decode_with_drops.c
+6
-10
examples/set_maps.c
examples/set_maps.c
+22
-34
examples/simple_decoder.c
examples/simple_decoder.c
+6
-11
examples/simple_encoder.c
examples/simple_encoder.c
+21
-34
examples/twopass_encoder.c
examples/twopass_encoder.c
+36
-54
examples/vpx_temporal_svc_encoder.c
examples/vpx_temporal_svc_encoder.c
+163
-175
No files found.
examples/decode_to_md5.c
View file @
421bb4d4
...
@@ -65,8 +65,7 @@ static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
...
@@ -65,8 +65,7 @@ static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
static
void
print_md5
(
FILE
*
stream
,
unsigned
char
digest
[
16
])
{
static
void
print_md5
(
FILE
*
stream
,
unsigned
char
digest
[
16
])
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
16
;
++
i
)
for
(
i
=
0
;
i
<
16
;
++
i
)
fprintf
(
stream
,
"%02x"
,
digest
[
i
]);
fprintf
(
stream
,
"%02x"
,
digest
[
i
]);
}
}
static
const
char
*
exec_name
;
static
const
char
*
exec_name
;
...
@@ -86,12 +85,10 @@ int main(int argc, char **argv) {
...
@@ -86,12 +85,10 @@ int main(int argc, char **argv) {
exec_name
=
argv
[
0
];
exec_name
=
argv
[
0
];
if
(
argc
!=
3
)
if
(
argc
!=
3
)
die
(
"Invalid number of arguments."
);
die
(
"Invalid number of arguments."
);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
...
@@ -99,8 +96,7 @@ int main(int argc, char **argv) {
...
@@ -99,8 +96,7 @@ int main(int argc, char **argv) {
info
=
vpx_video_reader_get_info
(
reader
);
info
=
vpx_video_reader_get_info
(
reader
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
if
(
!
decoder
)
if
(
!
decoder
)
die
(
"Unknown input codec."
);
die
(
"Unknown input codec."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
...
@@ -111,8 +107,8 @@ int main(int argc, char **argv) {
...
@@ -111,8 +107,8 @@ int main(int argc, char **argv) {
vpx_codec_iter_t
iter
=
NULL
;
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
size_t
frame_size
=
0
;
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
const
unsigned
char
*
frame
=
&
frame_size
);
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame"
);
die_codec
(
&
codec
,
"Failed to decode frame"
);
...
@@ -121,14 +117,13 @@ int main(int argc, char **argv) {
...
@@ -121,14 +117,13 @@ int main(int argc, char **argv) {
get_image_md5
(
img
,
digest
);
get_image_md5
(
img
,
digest
);
print_md5
(
outfile
,
digest
);
print_md5
(
outfile
,
digest
);
fprintf
(
outfile
,
" img-%dx%d-%04d.i420
\n
"
,
fprintf
(
outfile
,
" img-%dx%d-%04d.i420
\n
"
,
img
->
d_w
,
img
->
d_h
,
img
->
d_w
,
img
->
d_h
,
++
frame_cnt
);
++
frame_cnt
);
}
}
}
}
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
if
(
vpx_codec_destroy
(
&
codec
))
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec."
);
die_codec
(
&
codec
,
"Failed to destroy codec."
);
vpx_video_reader_close
(
reader
);
vpx_video_reader_close
(
reader
);
...
...
examples/decode_with_drops.c
View file @
421bb4d4
...
@@ -84,12 +84,10 @@ int main(int argc, char **argv) {
...
@@ -84,12 +84,10 @@ int main(int argc, char **argv) {
exec_name
=
argv
[
0
];
exec_name
=
argv
[
0
];
if
(
argc
!=
4
)
if
(
argc
!=
4
)
die
(
"Invalid number of arguments."
);
die
(
"Invalid number of arguments."
);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
...
@@ -103,8 +101,7 @@ int main(int argc, char **argv) {
...
@@ -103,8 +101,7 @@ int main(int argc, char **argv) {
info
=
vpx_video_reader_get_info
(
reader
);
info
=
vpx_video_reader_get_info
(
reader
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
if
(
!
decoder
)
if
(
!
decoder
)
die
(
"Unknown input codec."
);
die
(
"Unknown input codec."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
...
@@ -116,8 +113,8 @@ int main(int argc, char **argv) {
...
@@ -116,8 +113,8 @@ int main(int argc, char **argv) {
vpx_image_t
*
img
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
size_t
frame_size
=
0
;
int
skip
;
int
skip
;
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
const
unsigned
char
*
frame
=
&
frame_size
);
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame."
);
die_codec
(
&
codec
,
"Failed to decode frame."
);
...
@@ -139,8 +136,7 @@ int main(int argc, char **argv) {
...
@@ -139,8 +136,7 @@ int main(int argc, char **argv) {
}
}
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
if
(
vpx_codec_destroy
(
&
codec
))
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec."
);
die_codec
(
&
codec
,
"Failed to destroy codec."
);
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
...
...
examples/set_maps.c
View file @
421bb4d4
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
* be found in the AUTHORS file in the root of the source tree.
*/
*/
// VP8 Set Active and ROI Maps
// VP8 Set Active and ROI Maps
// ===========================
// ===========================
//
//
...
@@ -86,8 +85,7 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
...
@@ -86,8 +85,7 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
roi
.
static_threshold
[
3
]
=
0
;
roi
.
static_threshold
[
3
]
=
0
;
roi
.
roi_map
=
(
uint8_t
*
)
malloc
(
roi
.
rows
*
roi
.
cols
);
roi
.
roi_map
=
(
uint8_t
*
)
malloc
(
roi
.
rows
*
roi
.
cols
);
for
(
i
=
0
;
i
<
roi
.
rows
*
roi
.
cols
;
++
i
)
for
(
i
=
0
;
i
<
roi
.
rows
*
roi
.
cols
;
++
i
)
roi
.
roi_map
[
i
]
=
i
%
4
;
roi
.
roi_map
[
i
]
=
i
%
4
;
if
(
vpx_codec_control
(
codec
,
VP8E_SET_ROI_MAP
,
&
roi
))
if
(
vpx_codec_control
(
codec
,
VP8E_SET_ROI_MAP
,
&
roi
))
die_codec
(
codec
,
"Failed to set ROI map"
);
die_codec
(
codec
,
"Failed to set ROI map"
);
...
@@ -98,14 +96,13 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
...
@@ -98,14 +96,13 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
static
void
set_active_map
(
const
vpx_codec_enc_cfg_t
*
cfg
,
static
void
set_active_map
(
const
vpx_codec_enc_cfg_t
*
cfg
,
vpx_codec_ctx_t
*
codec
)
{
vpx_codec_ctx_t
*
codec
)
{
unsigned
int
i
;
unsigned
int
i
;
vpx_active_map_t
map
=
{
0
,
0
,
0
};
vpx_active_map_t
map
=
{
0
,
0
,
0
};
map
.
rows
=
(
cfg
->
g_h
+
15
)
/
16
;
map
.
rows
=
(
cfg
->
g_h
+
15
)
/
16
;
map
.
cols
=
(
cfg
->
g_w
+
15
)
/
16
;
map
.
cols
=
(
cfg
->
g_w
+
15
)
/
16
;
map
.
active_map
=
(
uint8_t
*
)
malloc
(
map
.
rows
*
map
.
cols
);
map
.
active_map
=
(
uint8_t
*
)
malloc
(
map
.
rows
*
map
.
cols
);
for
(
i
=
0
;
i
<
map
.
rows
*
map
.
cols
;
++
i
)
for
(
i
=
0
;
i
<
map
.
rows
*
map
.
cols
;
++
i
)
map
.
active_map
[
i
]
=
i
%
2
;
map
.
active_map
[
i
]
=
i
%
2
;
if
(
vpx_codec_control
(
codec
,
VP8E_SET_ACTIVEMAP
,
&
map
))
if
(
vpx_codec_control
(
codec
,
VP8E_SET_ACTIVEMAP
,
&
map
))
die_codec
(
codec
,
"Failed to set active map"
);
die_codec
(
codec
,
"Failed to set active map"
);
...
@@ -115,7 +112,7 @@ static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
...
@@ -115,7 +112,7 @@ static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
static
void
unset_active_map
(
const
vpx_codec_enc_cfg_t
*
cfg
,
static
void
unset_active_map
(
const
vpx_codec_enc_cfg_t
*
cfg
,
vpx_codec_ctx_t
*
codec
)
{
vpx_codec_ctx_t
*
codec
)
{
vpx_active_map_t
map
=
{
0
,
0
,
0
};
vpx_active_map_t
map
=
{
0
,
0
,
0
};
map
.
rows
=
(
cfg
->
g_h
+
15
)
/
16
;
map
.
rows
=
(
cfg
->
g_h
+
15
)
/
16
;
map
.
cols
=
(
cfg
->
g_w
+
15
)
/
16
;
map
.
cols
=
(
cfg
->
g_w
+
15
)
/
16
;
...
@@ -125,25 +122,21 @@ static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
...
@@ -125,25 +122,21 @@ static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
die_codec
(
codec
,
"Failed to set active map"
);
die_codec
(
codec
,
"Failed to set active map"
);
}
}
static
int
encode_frame
(
vpx_codec_ctx_t
*
codec
,
static
int
encode_frame
(
vpx_codec_ctx_t
*
codec
,
vpx_image_t
*
img
,
vpx_image_t
*
img
,
int
frame_index
,
VpxVideoWriter
*
writer
)
{
int
frame_index
,
VpxVideoWriter
*
writer
)
{
int
got_pkts
=
0
;
int
got_pkts
=
0
;
vpx_codec_iter_t
iter
=
NULL
;
vpx_codec_iter_t
iter
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_err_t
res
=
vpx_codec_encode
(
codec
,
img
,
frame_index
,
1
,
0
,
const
vpx_codec_err_t
res
=
VPX_DL_GOOD_QUALITY
);
vpx_codec_encode
(
codec
,
img
,
frame_index
,
1
,
0
,
VPX_DL_GOOD_QUALITY
);
if
(
res
!=
VPX_CODEC_OK
)
if
(
res
!=
VPX_CODEC_OK
)
die_codec
(
codec
,
"Failed to encode frame"
);
die_codec
(
codec
,
"Failed to encode frame"
);
while
((
pkt
=
vpx_codec_get_cx_data
(
codec
,
&
iter
))
!=
NULL
)
{
while
((
pkt
=
vpx_codec_get_cx_data
(
codec
,
&
iter
))
!=
NULL
)
{
got_pkts
=
1
;
got_pkts
=
1
;
if
(
pkt
->
kind
==
VPX_CODEC_CX_FRAME_PKT
)
{
if
(
pkt
->
kind
==
VPX_CODEC_CX_FRAME_PKT
)
{
const
int
keyframe
=
(
pkt
->
data
.
frame
.
flags
&
VPX_FRAME_IS_KEY
)
!=
0
;
const
int
keyframe
=
(
pkt
->
data
.
frame
.
flags
&
VPX_FRAME_IS_KEY
)
!=
0
;
if
(
!
vpx_video_writer_write_frame
(
writer
,
if
(
!
vpx_video_writer_write_frame
(
writer
,
pkt
->
data
.
frame
.
buf
,
pkt
->
data
.
frame
.
buf
,
pkt
->
data
.
frame
.
sz
,
pkt
->
data
.
frame
.
sz
,
pkt
->
data
.
frame
.
pts
))
{
pkt
->
data
.
frame
.
pts
))
{
die_codec
(
codec
,
"Failed to write compressed frame"
);
die_codec
(
codec
,
"Failed to write compressed frame"
);
...
@@ -167,12 +160,11 @@ int main(int argc, char **argv) {
...
@@ -167,12 +160,11 @@ int main(int argc, char **argv) {
VpxVideoInfo
info
;
VpxVideoInfo
info
;
VpxVideoWriter
*
writer
=
NULL
;
VpxVideoWriter
*
writer
=
NULL
;
const
VpxInterface
*
encoder
=
NULL
;
const
VpxInterface
*
encoder
=
NULL
;
const
int
fps
=
2
;
// TODO(dkovalev) add command line argument
const
int
fps
=
2
;
// TODO(dkovalev) add command line argument
const
double
bits_per_pixel_per_frame
=
0
.
067
;
const
double
bits_per_pixel_per_frame
=
0
.
067
;
exec_name
=
argv
[
0
];
exec_name
=
argv
[
0
];
if
(
argc
!=
6
)
if
(
argc
!=
6
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments"
);
memset
(
&
info
,
0
,
sizeof
(
info
));
memset
(
&
info
,
0
,
sizeof
(
info
));
...
@@ -187,35 +179,31 @@ int main(int argc, char **argv) {
...
@@ -187,35 +179,31 @@ int main(int argc, char **argv) {
info
.
time_base
.
numerator
=
1
;
info
.
time_base
.
numerator
=
1
;
info
.
time_base
.
denominator
=
fps
;
info
.
time_base
.
denominator
=
fps
;
if
(
info
.
frame_width
<=
0
||
if
(
info
.
frame_width
<=
0
||
info
.
frame_height
<=
0
||
info
.
frame_height
<=
0
||
(
info
.
frame_width
%
2
)
!=
0
||
(
info
.
frame_height
%
2
)
!=
0
)
{
(
info
.
frame_width
%
2
)
!=
0
||
(
info
.
frame_height
%
2
)
!=
0
)
{
die
(
"Invalid frame size: %dx%d"
,
info
.
frame_width
,
info
.
frame_height
);
die
(
"Invalid frame size: %dx%d"
,
info
.
frame_width
,
info
.
frame_height
);
}
}
if
(
!
vpx_img_alloc
(
&
raw
,
VPX_IMG_FMT_I420
,
info
.
frame_width
,
if
(
!
vpx_img_alloc
(
&
raw
,
VPX_IMG_FMT_I420
,
info
.
frame_width
,
info
.
frame_height
,
1
))
{
info
.
frame_height
,
1
))
{
die
(
"Failed to allocate image."
);
die
(
"Failed to allocate image."
);
}
}
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
encoder
->
codec_interface
()));
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
encoder
->
codec_interface
()));
res
=
vpx_codec_enc_config_default
(
encoder
->
codec_interface
(),
&
cfg
,
0
);
res
=
vpx_codec_enc_config_default
(
encoder
->
codec_interface
(),
&
cfg
,
0
);
if
(
res
)
if
(
res
)
die_codec
(
&
codec
,
"Failed to get default codec config."
);
die_codec
(
&
codec
,
"Failed to get default codec config."
);
cfg
.
g_w
=
info
.
frame_width
;
cfg
.
g_w
=
info
.
frame_width
;
cfg
.
g_h
=
info
.
frame_height
;
cfg
.
g_h
=
info
.
frame_height
;
cfg
.
g_timebase
.
num
=
info
.
time_base
.
numerator
;
cfg
.
g_timebase
.
num
=
info
.
time_base
.
numerator
;
cfg
.
g_timebase
.
den
=
info
.
time_base
.
denominator
;
cfg
.
g_timebase
.
den
=
info
.
time_base
.
denominator
;
cfg
.
rc_target_bitrate
=
(
unsigned
int
)(
bits_per_pixel_per_frame
*
cfg
.
g_w
*
cfg
.
rc_target_bitrate
=
cfg
.
g_h
*
fps
/
1000
);
(
unsigned
int
)(
bits_per_pixel_per_frame
*
cfg
.
g_w
*
cfg
.
g_h
*
fps
/
1000
);
cfg
.
g_lag_in_frames
=
0
;
cfg
.
g_lag_in_frames
=
0
;
writer
=
vpx_video_writer_open
(
argv
[
5
],
kContainerIVF
,
&
info
);
writer
=
vpx_video_writer_open
(
argv
[
5
],
kContainerIVF
,
&
info
);
if
(
!
writer
)
if
(
!
writer
)
die
(
"Failed to open %s for writing."
,
argv
[
5
]);
die
(
"Failed to open %s for writing."
,
argv
[
5
]);
if
(
!
(
infile
=
fopen
(
argv
[
4
],
"rb"
)))
if
(
!
(
infile
=
fopen
(
argv
[
4
],
"rb"
)))
die
(
"Failed to open %s for reading."
,
argv
[
4
]);
die
(
"Failed to open %s for reading."
,
argv
[
4
]);
...
@@ -239,15 +227,15 @@ int main(int argc, char **argv) {
...
@@ -239,15 +227,15 @@ int main(int argc, char **argv) {
}
}
// Flush encoder.
// Flush encoder.
while
(
encode_frame
(
&
codec
,
NULL
,
-
1
,
writer
))
{}
while
(
encode_frame
(
&
codec
,
NULL
,
-
1
,
writer
))
{
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
fclose
(
infile
);
fclose
(
infile
);
printf
(
"Processed %d frames.
\n
"
,
frame_count
);
printf
(
"Processed %d frames.
\n
"
,
frame_count
);
vpx_img_free
(
&
raw
);
vpx_img_free
(
&
raw
);
if
(
vpx_codec_destroy
(
&
codec
))
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec."
);
die_codec
(
&
codec
,
"Failed to destroy codec."
);
vpx_video_writer_close
(
writer
);
vpx_video_writer_close
(
writer
);
...
...
examples/simple_decoder.c
View file @
421bb4d4
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
* be found in the AUTHORS file in the root of the source tree.
*/
*/
// Simple Decoder
// Simple Decoder
// ==============
// ==============
//
//
...
@@ -103,12 +102,10 @@ int main(int argc, char **argv) {
...
@@ -103,12 +102,10 @@ int main(int argc, char **argv) {
exec_name
=
argv
[
0
];
exec_name
=
argv
[
0
];
if
(
argc
!=
3
)
if
(
argc
!=
3
)
die
(
"Invalid number of arguments."
);
die
(
"Invalid number of arguments."
);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
die
(
"Failed to open %s for writing."
,
argv
[
2
]);
...
@@ -116,8 +113,7 @@ int main(int argc, char **argv) {
...
@@ -116,8 +113,7 @@ int main(int argc, char **argv) {
info
=
vpx_video_reader_get_info
(
reader
);
info
=
vpx_video_reader_get_info
(
reader
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
decoder
=
get_vpx_decoder_by_fourcc
(
info
->
codec_fourcc
);
if
(
!
decoder
)
if
(
!
decoder
)
die
(
"Unknown input codec."
);
die
(
"Unknown input codec."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
decoder
->
codec_interface
()));
...
@@ -128,8 +124,8 @@ int main(int argc, char **argv) {
...
@@ -128,8 +124,8 @@ int main(int argc, char **argv) {
vpx_codec_iter_t
iter
=
NULL
;
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
size_t
frame_size
=
0
;
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
const
unsigned
char
*
frame
=
&
frame_size
);
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
if
(
vpx_codec_decode
(
&
codec
,
frame
,
(
unsigned
int
)
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame."
);
die_codec
(
&
codec
,
"Failed to decode frame."
);
...
@@ -140,8 +136,7 @@ int main(int argc, char **argv) {
...
@@ -140,8 +136,7 @@ int main(int argc, char **argv) {
}
}
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
if
(
vpx_codec_destroy
(
&
codec
))
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec"
);
die_codec
(
&
codec
,
"Failed to destroy codec"
);
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
...
...
examples/simple_encoder.c
View file @
421bb4d4
...
@@ -109,32 +109,27 @@ static const char *exec_name;
...
@@ -109,32 +109,27 @@ static const char *exec_name;
void
usage_exit
(
void
)
{
void
usage_exit
(
void
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Usage: %s <codec> <width> <height> <infile> <outfile> "
"Usage: %s <codec> <width> <height> <infile> <outfile> "
"<keyframe-interval> [<error-resilient>]
\n
See comments in "
"<keyframe-interval> [<error-resilient>]
\n
See comments in "
"simple_encoder.c for more information.
\n
"
,
"simple_encoder.c for more information.
\n
"
,
exec_name
);
exec_name
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
static
int
encode_frame
(
vpx_codec_ctx_t
*
codec
,
static
int
encode_frame
(
vpx_codec_ctx_t
*
codec
,
vpx_image_t
*
img
,
vpx_image_t
*
img
,
int
frame_index
,
int
flags
,
VpxVideoWriter
*
writer
)
{
int
frame_index
,
int
flags
,
VpxVideoWriter
*
writer
)
{
int
got_pkts
=
0
;
int
got_pkts
=
0
;
vpx_codec_iter_t
iter
=
NULL
;
vpx_codec_iter_t
iter
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_err_t
res
=
vpx_codec_encode
(
codec
,
img
,
frame_index
,
1
,
const
vpx_codec_err_t
res
=
flags
,
VPX_DL_GOOD_QUALITY
);
vpx_codec_encode
(
codec
,
img
,
frame_index
,
1
,
flags
,
VPX_DL_GOOD_QUALITY
);
if
(
res
!=
VPX_CODEC_OK
)
if
(
res
!=
VPX_CODEC_OK
)
die_codec
(
codec
,
"Failed to encode frame"
);
die_codec
(
codec
,
"Failed to encode frame"
);
while
((
pkt
=
vpx_codec_get_cx_data
(
codec
,
&
iter
))
!=
NULL
)
{
while
((
pkt
=
vpx_codec_get_cx_data
(
codec
,
&
iter
))
!=
NULL
)
{
got_pkts
=
1
;
got_pkts
=
1
;
if
(
pkt
->
kind
==
VPX_CODEC_CX_FRAME_PKT
)
{
if
(
pkt
->
kind
==
VPX_CODEC_CX_FRAME_PKT
)
{
const
int
keyframe
=
(
pkt
->
data
.
frame
.
flags
&
VPX_FRAME_IS_KEY
)
!=
0
;
const
int
keyframe
=
(
pkt
->
data
.
frame
.
flags
&
VPX_FRAME_IS_KEY
)
!=
0
;
if
(
!
vpx_video_writer_write_frame
(
writer
,
if
(
!
vpx_video_writer_write_frame
(
writer
,
pkt
->
data
.
frame
.
buf
,
pkt
->
data
.
frame
.
buf
,
pkt
->
data
.
frame
.
sz
,
pkt
->
data
.
frame
.
sz
,
pkt
->
data
.
frame
.
pts
))
{
pkt
->
data
.
frame
.
pts
))
{
die_codec
(
codec
,
"Failed to write compressed frame"
);
die_codec
(
codec
,
"Failed to write compressed frame"
);
...
@@ -154,11 +149,11 @@ int main(int argc, char **argv) {
...
@@ -154,11 +149,11 @@ int main(int argc, char **argv) {
int
frame_count
=
0
;
int
frame_count
=
0
;
vpx_image_t
raw
;
vpx_image_t
raw
;
vpx_codec_err_t
res
;
vpx_codec_err_t
res
;
VpxVideoInfo
info
=
{
0
};
VpxVideoInfo
info
=
{
0
};
VpxVideoWriter
*
writer
=
NULL
;
VpxVideoWriter
*
writer
=
NULL
;
const
VpxInterface
*
encoder
=
NULL
;
const
VpxInterface
*
encoder
=
NULL
;
const
int
fps
=
30
;
// TODO(dkovalev) add command line argument
const
int
fps
=
30
;
// TODO(dkovalev) add command line argument
const
int
bitrate
=
200
;
// kbit/s TODO(dkovalev) add command line argument
const
int
bitrate
=
200
;
// kbit/s TODO(dkovalev) add command line argument
int
keyframe_interval
=
0
;
int
keyframe_interval
=
0
;
// TODO(dkovalev): Add some simple command line parsing code to make the
// TODO(dkovalev): Add some simple command line parsing code to make the
...
@@ -172,8 +167,7 @@ int main(int argc, char **argv) {
...
@@ -172,8 +167,7 @@ int main(int argc, char **argv) {
exec_name
=
argv
[
0
];
exec_name
=
argv
[
0
];
if
(
argc
<
7
)
if
(
argc
<
7
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments"
);
codec_arg
=
argv
[
1
];
codec_arg
=
argv
[
1
];
width_arg
=
argv
[
2
];
width_arg
=
argv
[
2
];
...
@@ -183,8 +177,7 @@ int main(int argc, char **argv) {
...
@@ -183,8 +177,7 @@ int main(int argc, char **argv) {
keyframe_interval_arg
=
argv
[
6
];
keyframe_interval_arg
=
argv
[
6
];
encoder
=
get_vpx_encoder_by_name
(
codec_arg
);
encoder
=
get_vpx_encoder_by_name
(
codec_arg
);
if
(
!
encoder
)
if
(
!
encoder
)
die
(
"Unsupported codec."
);
die
(
"Unsupported codec."
);
info
.
codec_fourcc
=
encoder
->
fourcc
;
info
.
codec_fourcc
=
encoder
->
fourcc
;
info
.
frame_width
=
strtol
(
width_arg
,
NULL
,
0
);
info
.
frame_width
=
strtol
(
width_arg
,
NULL
,
0
);
...
@@ -192,27 +185,23 @@ int main(int argc, char **argv) {
...
@@ -192,27 +185,23 @@ int main(int argc, char **argv) {
info
.
time_base
.
numerator
=
1
;
info
.
time_base
.
numerator
=
1
;
info
.
time_base
.
denominator
=
fps
;
info
.
time_base
.
denominator
=
fps
;
if
(
info
.
frame_width
<=
0
||
if
(
info
.
frame_width
<=
0
||
info
.
frame_height
<=
0
||
info
.
frame_height
<=
0
||
(
info
.
frame_width
%
2
)
!=
0
||
(
info
.
frame_height
%
2
)
!=
0
)
{
(
info
.
frame_width
%
2
)
!=
0
||
(
info
.
frame_height
%
2
)
!=
0
)
{
die
(
"Invalid frame size: %dx%d"
,
info
.
frame_width
,
info
.
frame_height
);
die
(
"Invalid frame size: %dx%d"
,
info
.
frame_width
,
info
.
frame_height
);
}
}
if
(
!
vpx_img_alloc
(
&
raw
,
VPX_IMG_FMT_I420
,
info
.
frame_width
,
if
(
!
vpx_img_alloc
(
&
raw
,
VPX_IMG_FMT_I420
,
info
.
frame_width
,
info
.
frame_height
,
1
))
{
info
.
frame_height
,
1
))
{
die
(
"Failed to allocate image."
);
die
(
"Failed to allocate image."
);
}
}
keyframe_interval
=
strtol
(
keyframe_interval_arg
,
NULL
,
0
);
keyframe_interval
=
strtol
(
keyframe_interval_arg
,
NULL
,
0
);
if
(
keyframe_interval
<
0
)
if
(
keyframe_interval
<
0
)
die
(
"Invalid keyframe interval value."
);
die
(
"Invalid keyframe interval value."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
encoder
->
codec_interface
()));
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
encoder
->
codec_interface
()));
res
=
vpx_codec_enc_config_default
(
encoder
->
codec_interface
(),
&
cfg
,
0
);
res
=
vpx_codec_enc_config_default
(
encoder
->
codec_interface
(),
&
cfg
,
0
);
if
(
res
)
if
(
res
)
die_codec
(
&
codec
,
"Failed to get default codec config."
);
die_codec
(
&
codec
,
"Failed to get default codec config."
);
cfg
.
g_w
=
info
.
frame_width
;
cfg
.
g_w
=
info
.
frame_width
;
cfg
.
g_h
=
info
.
frame_height
;
cfg
.
g_h
=
info
.
frame_height
;
...
@@ -222,8 +211,7 @@ int main(int argc, char **argv) {
...
@@ -222,8 +211,7 @@ int main(int argc, char **argv) {
cfg
.
g_error_resilient
=
argc
>
7
?
strtol
(
argv
[
7
],
NULL
,
0
)
:
0
;
cfg
.
g_error_resilient
=
argc
>
7
?
strtol
(
argv
[
7
],
NULL
,
0
)
:
0
;