Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
fb066639
Commit
fb066639
authored
Dec 12, 2003
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CBR improvements
Originally committed as revision 2601 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
7a0f9d7e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
18 deletions
+25
-18
ffmpeg.c
ffmpeg.c
+4
-1
mpegvideo.h
libavcodec/mpegvideo.h
+1
-1
ratecontrol.c
libavcodec/ratecontrol.c
+20
-16
No files found.
ffmpeg.c
View file @
fb066639
...
...
@@ -1567,7 +1567,7 @@ static void opt_video_bitrate_min(const char *arg)
static
void
opt_video_buffer_size
(
const
char
*
arg
)
{
video_rc_buffer_size
=
atoi
(
arg
)
*
10
00
;
video_rc_buffer_size
=
atoi
(
arg
)
*
10
24
;
}
static
void
opt_video_rc_eq
(
char
*
arg
)
...
...
@@ -2767,6 +2767,7 @@ static void opt_target(const char *arg)
video_bit_rate
=
1150000
;
video_rc_max_rate
=
1150000
;
video_rc_min_rate
=
1150000
;
video_rc_buffer_size
=
40
*
1024
*
8
;
audio_bit_rate
=
224000
;
audio_sample_rate
=
44100
;
...
...
@@ -2783,6 +2784,7 @@ static void opt_target(const char *arg)
video_bit_rate
=
2040000
;
video_rc_max_rate
=
2516000
;
video_rc_min_rate
=
1145000
;
video_rc_buffer_size
=
224
*
1024
*
8
;
audio_bit_rate
=
224000
;
audio_sample_rate
=
44100
;
...
...
@@ -2799,6 +2801,7 @@ static void opt_target(const char *arg)
video_bit_rate
=
6000000
;
video_rc_max_rate
=
9000000
;
video_rc_min_rate
=
1500000
;
video_rc_buffer_size
=
224
*
1024
*
8
;
audio_bit_rate
=
448000
;
audio_sample_rate
=
48000
;
...
...
libavcodec/mpegvideo.h
View file @
fb066639
...
...
@@ -93,7 +93,7 @@ typedef struct RateControlContext{
FILE
*
stats_file
;
int
num_entries
;
///< number of RateControlEntries
RateControlEntry
*
entry
;
int
buffer_index
;
///< amount of bits in the video/audio buffer
double
buffer_index
;
///< amount of bits in the video/audio buffer
Predictor
pred
[
5
];
double
short_term_qsum
;
///< sum of recent qscales
double
short_term_qcount
;
///< count of recent qscales
...
...
libavcodec/ratecontrol.c
View file @
fb066639
/*
* Rate control for video encoders
*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2002
-2003
Michael Niedermayer <michaelni@gmx.at>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -62,7 +62,7 @@ int ff_rate_control_init(MpegEncContext *s)
rcc
->
frame_count
[
i
]
=
1
;
// 1 is better cuz of 1/0 and such
rcc
->
last_qscale_for
[
i
]
=
FF_QP2LAMBDA
*
5
;
}
rcc
->
buffer_index
=
s
->
avctx
->
rc_
buffer_size
/
2
;
rcc
->
buffer_index
=
s
->
avctx
->
rc_
initial_buffer_occupancy
;
if
(
s
->
flags
&
CODEC_FLAG_PASS2
){
int
i
;
...
...
@@ -202,20 +202,23 @@ static void update_rc_buffer(MpegEncContext *s, int frame_size){
const
double
min_rate
=
s
->
avctx
->
rc_min_rate
/
fps
;
const
double
max_rate
=
s
->
avctx
->
rc_max_rate
/
fps
;
//printf("%f %f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);
if
(
buffer_size
){
int
left
;
rcc
->
buffer_index
-=
frame_size
;
if
(
rcc
->
buffer_index
<
buffer_size
/
2
/*FIXME /2 */
||
min_rate
==
0
){
rcc
->
buffer_index
+=
max_rate
;
if
(
rcc
->
buffer_index
>=
buffer_size
)
rcc
->
buffer_index
=
buffer_size
-
1
;
}
else
{
rcc
->
buffer_index
+=
min_rate
;
if
(
rcc
->
buffer_index
<
0
){
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"rc buffer underflow
\n
"
);
rcc
->
buffer_index
=
0
;
}
if
(
rcc
->
buffer_index
<
0
)
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"rc buffer underflow
\n
"
);
if
(
rcc
->
buffer_index
>=
s
->
avctx
->
rc_buffer_size
)
left
=
buffer_size
-
rcc
->
buffer_index
-
1
;
rcc
->
buffer_index
+=
clip
(
left
,
min_rate
,
max_rate
);
if
(
rcc
->
buffer_index
>
s
->
avctx
->
rc_buffer_size
){
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"rc buffer overflow
\n
"
);
rcc
->
buffer_index
=
s
->
avctx
->
rc_buffer_size
;
}
}
}
...
...
@@ -385,8 +388,9 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
double
bits
;
const
int
pict_type
=
rce
->
new_pict_type
;
const
double
buffer_size
=
s
->
avctx
->
rc_buffer_size
;
const
double
min_rate
=
s
->
avctx
->
rc_min_rate
;
const
double
max_rate
=
s
->
avctx
->
rc_max_rate
;
const
double
fps
=
(
double
)
s
->
avctx
->
frame_rate
/
(
double
)
s
->
avctx
->
frame_rate_base
;
const
double
min_rate
=
s
->
avctx
->
rc_min_rate
/
fps
;
const
double
max_rate
=
s
->
avctx
->
rc_max_rate
/
fps
;
get_qminmax
(
&
qmin
,
&
qmax
,
s
,
pict_type
);
...
...
@@ -406,7 +410,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
q
*=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
=
FFMIN
(
q
,
bits2qp
(
rce
,
FFMAX
((
min_rate
-
buffer_size
+
rcc
->
buffer_index
)
*
2
,
1
)));
q
=
FFMIN
(
q
,
bits2qp
(
rce
,
FFMAX
((
min_rate
-
buffer_size
+
rcc
->
buffer_index
)
*
3
,
1
)));
}
if
(
max_rate
){
...
...
@@ -415,7 +419,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
q
/=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
=
FFMAX
(
q
,
bits2qp
(
rce
,
FFMAX
(
rcc
->
buffer_index
/
2
,
1
)));
q
=
FFMAX
(
q
,
bits2qp
(
rce
,
FFMAX
(
rcc
->
buffer_index
/
3
,
1
)));
}
}
//printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity);
...
...
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