Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
BC
public
external
libvpx
Commits
95ac8fa7
Commit
95ac8fa7
authored
10 years ago
by
Dmitry Kovalev
Committed by
Gerrit Code Review
10 years ago
Browse files
Options
Download
Plain Diff
Merge "twopass_encoder: Flush encoder."
parents
28eaa5f4
1e82bdec
v1.14.0-linphone
1.4.X
feature/update_to_v1.9.0-linphone
feature/uwp_nuget
highbitdepth
indianrunnerduck
javanwhistlingduck
khakicampbell
linphone
linphone-android
linphone-old
longtailedduck
m49-2623
m52-2743
m54-2840
m56-2924
m66-3359
m68-3440
mandarinduck
nextgen
nextgenv2
sandbox/Jingning/experimental
sandbox/Jingning/vpx
sandbox/aconverse@google.com/ansbench
sandbox/hkuang@google.com/decode
sandbox/jimbankoski@google.com/proposed-aom
sandbox/jingning@google.com/decoder_test_suite
sandbox/jingning@google.com/experimental
sandbox/jzern@google.com/test
sandbox/wangch@google.com/vp9
sandbox/yaowu@google.com/mergeaom
v1.12.0-linphone
v1.6.1_linphone
v1.7.0-linphone
v1.9.0-linphone
v1.9.0
v1.9.0-rc1
v1.8.2
v1.8.1
v1.8.0
v1.7.0
v1.6.1
v1.6.0
v1.5.0
v1.4.0
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/twopass_encoder.c
+33
-17
examples/twopass_encoder.c
with
33 additions
and
17 deletions
examples/twopass_encoder.c
+
33
−
17
View file @
95ac8fa7
...
...
@@ -66,13 +66,14 @@ void usage_exit() {
exit
(
EXIT_FAILURE
);
}
static
void
get_frame_stats
(
vpx_codec_ctx_t
*
ctx
,
const
vpx_image_t
*
img
,
vpx_codec_pts_t
pts
,
unsigned
int
duration
,
vpx_enc_frame_flags_t
flags
,
unsigned
int
deadline
,
vpx_fixed_buf_t
*
stats
)
{
static
int
get_frame_stats
(
vpx_codec_ctx_t
*
ctx
,
const
vpx_image_t
*
img
,
vpx_codec_pts_t
pts
,
unsigned
int
duration
,
vpx_enc_frame_flags_t
flags
,
unsigned
int
deadline
,
vpx_fixed_buf_t
*
stats
)
{
int
got_pkts
=
0
;
vpx_codec_iter_t
iter
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_err_t
res
=
vpx_codec_encode
(
ctx
,
img
,
pts
,
duration
,
flags
,
...
...
@@ -81,6 +82,8 @@ static void get_frame_stats(vpx_codec_ctx_t *ctx,
die_codec
(
ctx
,
"Failed to get frame stats."
);
while
((
pkt
=
vpx_codec_get_cx_data
(
ctx
,
&
iter
))
!=
NULL
)
{
got_pkts
=
1
;
if
(
pkt
->
kind
==
VPX_CODEC_STATS_PKT
)
{
const
uint8_t
*
const
pkt_buf
=
pkt
->
data
.
twopass_stats
.
buf
;
const
size_t
pkt_size
=
pkt
->
data
.
twopass_stats
.
sz
;
...
...
@@ -89,15 +92,18 @@ static void get_frame_stats(vpx_codec_ctx_t *ctx,
stats
->
sz
+=
pkt_size
;
}
}
return
got_pkts
;
}
static
void
encode_frame
(
vpx_codec_ctx_t
*
ctx
,
const
vpx_image_t
*
img
,
vpx_codec_pts_t
pts
,
unsigned
int
duration
,
vpx_enc_frame_flags_t
flags
,
unsigned
int
deadline
,
VpxVideoWriter
*
writer
)
{
static
int
encode_frame
(
vpx_codec_ctx_t
*
ctx
,
const
vpx_image_t
*
img
,
vpx_codec_pts_t
pts
,
unsigned
int
duration
,
vpx_enc_frame_flags_t
flags
,
unsigned
int
deadline
,
VpxVideoWriter
*
writer
)
{
int
got_pkts
=
0
;
vpx_codec_iter_t
iter
=
NULL
;
const
vpx_codec_cx_pkt_t
*
pkt
=
NULL
;
const
vpx_codec_err_t
res
=
vpx_codec_encode
(
ctx
,
img
,
pts
,
duration
,
flags
,
...
...
@@ -106,6 +112,7 @@ static void encode_frame(vpx_codec_ctx_t *ctx,
die_codec
(
ctx
,
"Failed to encode frame."
);
while
((
pkt
=
vpx_codec_get_cx_data
(
ctx
,
&
iter
))
!=
NULL
)
{
got_pkts
=
1
;
if
(
pkt
->
kind
==
VPX_CODEC_CX_FRAME_PKT
)
{
const
int
keyframe
=
(
pkt
->
data
.
frame
.
flags
&
VPX_FRAME_IS_KEY
)
!=
0
;
...
...
@@ -117,12 +124,14 @@ static void encode_frame(vpx_codec_ctx_t *ctx,
fflush
(
stdout
);
}
}
return
got_pkts
;
}
static
vpx_fixed_buf_t
pass0
(
vpx_image_t
*
raw
,
FILE
*
infile
,
const
VpxInterface
*
encoder
,
vpx_codec_enc_cfg_t
*
cfg
)
{
const
vpx_codec_enc_cfg_t
*
cfg
)
{
vpx_codec_ctx_t
codec
;
int
frame_count
=
0
;
vpx_fixed_buf_t
stats
=
{
NULL
,
0
};
...
...
@@ -130,13 +139,16 @@ static vpx_fixed_buf_t pass0(vpx_image_t *raw,
if
(
vpx_codec_enc_init
(
&
codec
,
encoder
->
codec_interface
(),
cfg
,
0
))
die_codec
(
&
codec
,
"Failed to initialize encoder"
);
// Calculate frame statistics.
while
(
vpx_img_read
(
raw
,
infile
))
{
++
frame_count
;
get_frame_stats
(
&
codec
,
raw
,
frame_count
,
1
,
0
,
VPX_DL_BEST_QUALITY
,
&
stats
);
}
get_frame_stats
(
&
codec
,
NULL
,
frame_count
,
1
,
0
,
VPX_DL_BEST_QUALITY
,
&
stats
);
// Flush encoder.
while
(
get_frame_stats
(
&
codec
,
NULL
,
frame_count
,
1
,
0
,
VPX_DL_BEST_QUALITY
,
&
stats
))
{}
printf
(
"Pass 0 complete. Processed %d frames.
\n
"
,
frame_count
);
if
(
vpx_codec_destroy
(
&
codec
))
...
...
@@ -149,7 +161,7 @@ static void pass1(vpx_image_t *raw,
FILE
*
infile
,
const
char
*
outfile_name
,
const
VpxInterface
*
encoder
,
vpx_codec_enc_cfg_t
*
cfg
)
{
const
vpx_codec_enc_cfg_t
*
cfg
)
{
VpxVideoInfo
info
=
{
encoder
->
fourcc
,
cfg
->
g_w
,
...
...
@@ -167,11 +179,15 @@ static void pass1(vpx_image_t *raw,
if
(
vpx_codec_enc_init
(
&
codec
,
encoder
->
codec_interface
(),
cfg
,
0
))
die_codec
(
&
codec
,
"Failed to initialize encoder"
);
// Encode frames.
while
(
vpx_img_read
(
raw
,
infile
))
{
++
frame_count
;
encode_frame
(
&
codec
,
raw
,
frame_count
,
1
,
0
,
VPX_DL_BEST_QUALITY
,
writer
);
}
// Flush encoder.
while
(
encode_frame
(
&
codec
,
NULL
,
-
1
,
1
,
0
,
VPX_DL_BEST_QUALITY
,
writer
))
{}
printf
(
"
\n
"
);
if
(
vpx_codec_destroy
(
&
codec
))
...
...
This diff is collapsed.
Click to expand it.
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets