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
d60a8f85
Commit
d60a8f85
authored
Dec 17, 2003
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vbv_delay
Originally committed as revision 2623 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
044007c2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
11 deletions
+43
-11
mpeg12.c
libavcodec/mpeg12.c
+5
-3
mpegvideo.c
libavcodec/mpegvideo.c
+17
-1
mpegvideo.h
libavcodec/mpegvideo.h
+1
-0
ratecontrol.c
libavcodec/ratecontrol.c
+20
-7
No files found.
libavcodec/mpeg12.c
View file @
d60a8f85
...
@@ -408,7 +408,9 @@ void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
...
@@ -408,7 +408,9 @@ void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
s
->
fake_picture_number
++
;
s
->
fake_picture_number
++
;
put_bits
(
&
s
->
pb
,
3
,
s
->
pict_type
);
put_bits
(
&
s
->
pb
,
3
,
s
->
pict_type
);
put_bits
(
&
s
->
pb
,
16
,
0xffff
);
/* non constant bit rate */
s
->
vbv_delay_ptr
=
s
->
pb
.
buf
+
get_bit_count
(
&
s
->
pb
)
/
8
;
put_bits
(
&
s
->
pb
,
16
,
0xFFFF
);
/* vbv_delay */
// RAL: Forward f_code also needed for B frames
// RAL: Forward f_code also needed for B frames
if
(
s
->
pict_type
==
P_TYPE
||
s
->
pict_type
==
B_TYPE
)
{
if
(
s
->
pict_type
==
P_TYPE
||
s
->
pict_type
==
B_TYPE
)
{
...
@@ -1758,7 +1760,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
...
@@ -1758,7 +1760,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
{
{
Mpeg1Context
*
s1
=
avctx
->
priv_data
;
Mpeg1Context
*
s1
=
avctx
->
priv_data
;
MpegEncContext
*
s
=
&
s1
->
mpeg_enc_ctx
;
MpegEncContext
*
s
=
&
s1
->
mpeg_enc_ctx
;
int
ref
,
f_code
;
int
ref
,
f_code
,
vbv_delay
;
init_get_bits
(
&
s
->
gb
,
buf
,
buf_size
*
8
);
init_get_bits
(
&
s
->
gb
,
buf
,
buf_size
*
8
);
...
@@ -1766,7 +1768,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
...
@@ -1766,7 +1768,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
s
->
pict_type
=
get_bits
(
&
s
->
gb
,
3
);
s
->
pict_type
=
get_bits
(
&
s
->
gb
,
3
);
dprintf
(
"pict_type=%d number=%d
\n
"
,
s
->
pict_type
,
s
->
picture_number
);
dprintf
(
"pict_type=%d number=%d
\n
"
,
s
->
pict_type
,
s
->
picture_number
);
skip
_bits
(
&
s
->
gb
,
16
);
vbv_delay
=
get
_bits
(
&
s
->
gb
,
16
);
if
(
s
->
pict_type
==
P_TYPE
||
s
->
pict_type
==
B_TYPE
)
{
if
(
s
->
pict_type
==
P_TYPE
||
s
->
pict_type
==
B_TYPE
)
{
s
->
full_pel
[
0
]
=
get_bits1
(
&
s
->
gb
);
s
->
full_pel
[
0
]
=
get_bits1
(
&
s
->
gb
);
f_code
=
get_bits
(
&
s
->
gb
,
3
);
f_code
=
get_bits
(
&
s
->
gb
,
3
);
...
...
libavcodec/mpegvideo.c
View file @
d60a8f85
...
@@ -1865,7 +1865,23 @@ int MPV_encode_picture(AVCodecContext *avctx,
...
@@ -1865,7 +1865,23 @@ int MPV_encode_picture(AVCodecContext *avctx,
flush_put_bits
(
&
s
->
pb
);
flush_put_bits
(
&
s
->
pb
);
s
->
frame_bits
=
(
pbBufPtr
(
&
s
->
pb
)
-
s
->
pb
.
buf
)
*
8
;
s
->
frame_bits
=
(
pbBufPtr
(
&
s
->
pb
)
-
s
->
pb
.
buf
)
*
8
;
}
}
/* update mpeg1/2 vbv_delay for CBR */
if
(
s
->
avctx
->
rc_max_rate
&&
s
->
avctx
->
rc_min_rate
==
s
->
avctx
->
rc_max_rate
){
int
vbv_delay
;
assert
(
s
->
repeat_first_field
==
0
&&
s
->
avctx
->
repeat_pic
==
0
);
vbv_delay
=
lrint
(
90000
*
s
->
rc_context
.
buffer_index
/
s
->
avctx
->
rc_max_rate
);
assert
(
vbv_delay
<
0xFFFF
);
s
->
vbv_delay_ptr
[
0
]
&=
0xF8
;
s
->
vbv_delay_ptr
[
0
]
|=
vbv_delay
>>
13
;
s
->
vbv_delay_ptr
[
1
]
=
vbv_delay
>>
5
;
s
->
vbv_delay_ptr
[
2
]
&=
0x07
;
s
->
vbv_delay_ptr
[
2
]
|=
vbv_delay
<<
3
;
}
s
->
total_bits
+=
s
->
frame_bits
;
s
->
total_bits
+=
s
->
frame_bits
;
avctx
->
frame_bits
=
s
->
frame_bits
;
avctx
->
frame_bits
=
s
->
frame_bits
;
...
...
libavcodec/mpegvideo.h
View file @
d60a8f85
...
@@ -605,6 +605,7 @@ typedef struct MpegEncContext {
...
@@ -605,6 +605,7 @@ typedef struct MpegEncContext {
int
gop_picture_number
;
///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
int
gop_picture_number
;
///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
int
last_mv_dir
;
///< last mv_dir, used for b frame encoding
int
last_mv_dir
;
///< last mv_dir, used for b frame encoding
int
broken_link
;
///< no_output_of_prior_pics_flag
int
broken_link
;
///< no_output_of_prior_pics_flag
uint8_t
*
vbv_delay_ptr
;
///< pointer to vbv_delay in the bitstream
/* MPEG2 specific - I wish I had not to support this mess. */
/* MPEG2 specific - I wish I had not to support this mess. */
int
progressive_sequence
;
int
progressive_sequence
;
...
...
libavcodec/ratecontrol.c
View file @
d60a8f85
...
@@ -198,11 +198,11 @@ static inline double bits2qp(RateControlEntry *rce, double bits){
...
@@ -198,11 +198,11 @@ static inline double bits2qp(RateControlEntry *rce, double bits){
int
ff_vbv_update
(
MpegEncContext
*
s
,
int
frame_size
){
int
ff_vbv_update
(
MpegEncContext
*
s
,
int
frame_size
){
RateControlContext
*
rcc
=
&
s
->
rc_context
;
RateControlContext
*
rcc
=
&
s
->
rc_context
;
const
double
fps
=
(
double
)
s
->
avctx
->
frame_rate
/
(
double
)
s
->
avctx
->
frame_rate_base
;
const
double
fps
=
(
double
)
s
->
avctx
->
frame_rate
/
(
double
)
s
->
avctx
->
frame_rate_base
;
const
double
buffer_size
=
s
->
avctx
->
rc_buffer_size
;
const
int
buffer_size
=
s
->
avctx
->
rc_buffer_size
;
const
double
min_rate
=
s
->
avctx
->
rc_min_rate
/
fps
;
const
double
min_rate
=
s
->
avctx
->
rc_min_rate
/
fps
;
const
double
max_rate
=
s
->
avctx
->
rc_max_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);
//printf("%
d
%f %d %f %f\n", buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);
if
(
buffer_size
){
if
(
buffer_size
){
int
left
;
int
left
;
...
@@ -215,8 +215,8 @@ int ff_vbv_update(MpegEncContext *s, int frame_size){
...
@@ -215,8 +215,8 @@ int ff_vbv_update(MpegEncContext *s, int frame_size){
left
=
buffer_size
-
rcc
->
buffer_index
-
1
;
left
=
buffer_size
-
rcc
->
buffer_index
-
1
;
rcc
->
buffer_index
+=
clip
(
left
,
min_rate
,
max_rate
);
rcc
->
buffer_index
+=
clip
(
left
,
min_rate
,
max_rate
);
if
(
rcc
->
buffer_index
>
s
->
avctx
->
rc_
buffer_size
){
if
(
rcc
->
buffer_index
>
buffer_size
){
int
stuffing
=
ceil
((
rcc
->
buffer_index
-
s
->
avctx
->
rc_
buffer_size
)
/
8
);
int
stuffing
=
ceil
((
rcc
->
buffer_index
-
buffer_size
)
/
8
);
if
(
stuffing
<
4
&&
s
->
codec_id
==
CODEC_ID_MPEG4
)
if
(
stuffing
<
4
&&
s
->
codec_id
==
CODEC_ID_MPEG4
)
stuffing
=
4
;
stuffing
=
4
;
...
@@ -413,6 +413,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
...
@@ -413,6 +413,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
/* buffer overflow/underflow protection */
/* buffer overflow/underflow protection */
if
(
buffer_size
){
if
(
buffer_size
){
double
expected_size
=
rcc
->
buffer_index
;
double
expected_size
=
rcc
->
buffer_index
;
double
q_limit
;
if
(
min_rate
){
if
(
min_rate
){
double
d
=
2
*
(
buffer_size
-
expected_size
)
/
buffer_size
;
double
d
=
2
*
(
buffer_size
-
expected_size
)
/
buffer_size
;
...
@@ -420,7 +421,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
...
@@ -420,7 +421,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
q
*=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
*=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
=
FFMIN
(
q
,
bits2qp
(
rce
,
FFMAX
((
min_rate
-
buffer_size
+
rcc
->
buffer_index
)
*
3
,
1
)));
q_limit
=
bits2qp
(
rce
,
FFMAX
((
min_rate
-
buffer_size
+
rcc
->
buffer_index
)
*
3
,
1
));
if
(
q
>
q_limit
){
if
(
s
->
avctx
->
debug
&
FF_DEBUG_RC
){
av_log
(
s
->
avctx
,
AV_LOG_DEBUG
,
"limiting QP %f -> %f
\n
"
,
q
,
q_limit
);
}
q
=
q_limit
;
}
}
}
if
(
max_rate
){
if
(
max_rate
){
...
@@ -429,7 +436,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
...
@@ -429,7 +436,13 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
else
if
(
d
<
0
.
0001
)
d
=
0
.
0001
;
q
/=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
/=
pow
(
d
,
1
.
0
/
s
->
avctx
->
rc_buffer_aggressivity
);
q
=
FFMAX
(
q
,
bits2qp
(
rce
,
FFMAX
(
rcc
->
buffer_index
/
3
,
1
)));
q_limit
=
bits2qp
(
rce
,
FFMAX
(
rcc
->
buffer_index
/
3
,
1
));
if
(
q
<
q_limit
){
if
(
s
->
avctx
->
debug
&
FF_DEBUG_RC
){
av_log
(
s
->
avctx
,
AV_LOG_DEBUG
,
"limiting QP %f -> %f
\n
"
,
q
,
q_limit
);
}
q
=
q_limit
;
}
}
}
}
}
//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);
//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