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
3825cd1d
Commit
3825cd1d
authored
Apr 05, 2002
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msmpeg4v2 encoding
Originally committed as revision 379 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
2ed627e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
53 deletions
+146
-53
msmpeg4.c
libavcodec/msmpeg4.c
+146
-53
No files found.
libavcodec/msmpeg4.c
View file @
3825cd1d
...
@@ -52,6 +52,9 @@ static int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
...
@@ -52,6 +52,9 @@ static int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
static
int
msmpeg4_decode_dc
(
MpegEncContext
*
s
,
int
n
,
int
*
dir_ptr
);
static
int
msmpeg4_decode_dc
(
MpegEncContext
*
s
,
int
n
,
int
*
dir_ptr
);
static
int
msmpeg4_decode_motion
(
MpegEncContext
*
s
,
static
int
msmpeg4_decode_motion
(
MpegEncContext
*
s
,
int
*
mx_ptr
,
int
*
my_ptr
);
int
*
mx_ptr
,
int
*
my_ptr
);
static
void
msmpeg4v2_encode_motion
(
MpegEncContext
*
s
,
int
val
);
static
void
init_h263_dc_for_msmpeg4
();
extern
UINT32
inverse
[
256
];
extern
UINT32
inverse
[
256
];
...
@@ -168,7 +171,11 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
...
@@ -168,7 +171,11 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits
(
&
s
->
pb
,
5
,
s
->
qscale
);
put_bits
(
&
s
->
pb
,
5
,
s
->
qscale
);
s
->
rl_table_index
=
2
;
s
->
rl_table_index
=
2
;
s
->
rl_chroma_table_index
=
1
;
/* only for I frame */
if
(
s
->
msmpeg4_version
==
2
)
s
->
rl_chroma_table_index
=
2
;
/* only for I frame */
else
s
->
rl_chroma_table_index
=
1
;
/* only for I frame */
s
->
dc_table_index
=
1
;
s
->
dc_table_index
=
1
;
s
->
mv_table_index
=
1
;
/* only if P frame */
s
->
mv_table_index
=
1
;
/* only if P frame */
s
->
use_skip_mb_code
=
1
;
/* only if P frame */
s
->
use_skip_mb_code
=
1
;
/* only if P frame */
...
@@ -176,21 +183,25 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
...
@@ -176,21 +183,25 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
if
(
s
->
pict_type
==
I_TYPE
)
{
if
(
s
->
pict_type
==
I_TYPE
)
{
put_bits
(
&
s
->
pb
,
5
,
0x17
);
/* indicate only one "slice" */
put_bits
(
&
s
->
pb
,
5
,
0x17
);
/* indicate only one "slice" */
code012
(
&
s
->
pb
,
s
->
rl_chroma_table_index
);
if
(
s
->
msmpeg4_version
!=
2
){
code012
(
&
s
->
pb
,
s
->
rl_table_index
);
code012
(
&
s
->
pb
,
s
->
rl_chroma_table_index
);
code012
(
&
s
->
pb
,
s
->
rl_table_index
);
put_bits
(
&
s
->
pb
,
1
,
s
->
dc_table_index
);
put_bits
(
&
s
->
pb
,
1
,
s
->
dc_table_index
);
}
s
->
no_rounding
=
1
;
s
->
no_rounding
=
1
;
}
else
{
}
else
{
put_bits
(
&
s
->
pb
,
1
,
s
->
use_skip_mb_code
);
put_bits
(
&
s
->
pb
,
1
,
s
->
use_skip_mb_code
);
s
->
rl_chroma_table_index
=
s
->
rl_table_index
;
s
->
rl_chroma_table_index
=
s
->
rl_table_index
;
code012
(
&
s
->
pb
,
s
->
rl_table_index
);
if
(
s
->
msmpeg4_version
!=
2
){
code012
(
&
s
->
pb
,
s
->
rl_table_index
);
put_bits
(
&
s
->
pb
,
1
,
s
->
dc_table_index
);
put_bits
(
&
s
->
pb
,
1
,
s
->
dc_table_index
);
put_bits
(
&
s
->
pb
,
1
,
s
->
mv_table_index
);
}
put_bits
(
&
s
->
pb
,
1
,
s
->
mv_table_index
);
if
(
s
->
flipflop_rounding
){
if
(
s
->
flipflop_rounding
){
s
->
no_rounding
^=
1
;
s
->
no_rounding
^=
1
;
}
else
{
}
else
{
...
@@ -205,6 +216,8 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
...
@@ -205,6 +216,8 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
init_mv_table
(
&
mv_tables
[
1
]);
init_mv_table
(
&
mv_tables
[
1
]);
for
(
i
=
0
;
i
<
NB_RL_TABLES
;
i
++
)
for
(
i
=
0
;
i
<
NB_RL_TABLES
;
i
++
)
init_rl
(
&
rl_table
[
i
]);
init_rl
(
&
rl_table
[
i
]);
init_h263_dc_for_msmpeg4
();
}
}
#ifdef DEBUG
#ifdef DEBUG
...
@@ -315,14 +328,30 @@ void msmpeg4_encode_mb(MpegEncContext * s,
...
@@ -315,14 +328,30 @@ void msmpeg4_encode_mb(MpegEncContext * s,
if
(
s
->
use_skip_mb_code
)
if
(
s
->
use_skip_mb_code
)
put_bits
(
&
s
->
pb
,
1
,
0
);
/* mb coded */
put_bits
(
&
s
->
pb
,
1
,
0
);
/* mb coded */
put_bits
(
&
s
->
pb
,
if
(
s
->
msmpeg4_version
==
2
){
table_mb_non_intra
[
cbp
+
64
][
1
],
put_bits
(
&
s
->
pb
,
table_mb_non_intra
[
cbp
+
64
][
0
]);
v2_mb_type
[
cbp
&
3
][
1
],
v2_mb_type
[
cbp
&
3
][
0
]);
/* motion vector */
if
((
cbp
&
3
)
!=
3
)
coded_cbp
=
cbp
^
0x3C
;
h263_pred_motion
(
s
,
0
,
&
pred_x
,
&
pred_y
);
else
coded_cbp
=
cbp
;
msmpeg4_encode_motion
(
s
,
motion_x
-
pred_x
,
motion_y
-
pred_y
);
put_bits
(
&
s
->
pb
,
cbpy_tab
[
coded_cbp
>>
2
][
1
],
cbpy_tab
[
coded_cbp
>>
2
][
0
]);
h263_pred_motion
(
s
,
0
,
&
pred_x
,
&
pred_y
);
msmpeg4v2_encode_motion
(
s
,
motion_x
-
pred_x
);
msmpeg4v2_encode_motion
(
s
,
motion_y
-
pred_y
);
}
else
{
put_bits
(
&
s
->
pb
,
table_mb_non_intra
[
cbp
+
64
][
1
],
table_mb_non_intra
[
cbp
+
64
][
0
]);
/* motion vector */
h263_pred_motion
(
s
,
0
,
&
pred_x
,
&
pred_y
);
msmpeg4_encode_motion
(
s
,
motion_x
-
pred_x
,
motion_y
-
pred_y
);
}
}
else
{
}
else
{
/* compute cbp */
/* compute cbp */
cbp
=
0
;
cbp
=
0
;
...
@@ -344,19 +373,36 @@ void msmpeg4_encode_mb(MpegEncContext * s,
...
@@ -344,19 +373,36 @@ void msmpeg4_encode_mb(MpegEncContext * s,
printf("cbp=%x %x\n", cbp, coded_cbp);
printf("cbp=%x %x\n", cbp, coded_cbp);
#endif
#endif
if
(
s
->
pict_type
==
I_TYPE
)
{
if
(
s
->
msmpeg4_version
==
2
){
set_stat
(
ST_INTRA_MB
);
if
(
s
->
pict_type
==
I_TYPE
)
{
put_bits
(
&
s
->
pb
,
put_bits
(
&
s
->
pb
,
table_mb_intra
[
coded_cbp
][
1
],
table_mb_intra
[
coded_cbp
][
0
]);
v2_intra_cbpc
[
cbp
&
3
][
1
],
v2_intra_cbpc
[
cbp
&
3
][
0
]);
}
else
{
}
else
{
if
(
s
->
use_skip_mb_code
)
if
(
s
->
use_skip_mb_code
)
put_bits
(
&
s
->
pb
,
1
,
0
);
/* mb coded */
put_bits
(
&
s
->
pb
,
1
,
0
);
/* mb coded */
put_bits
(
&
s
->
pb
,
v2_mb_type
[(
cbp
&
3
)
+
4
][
1
],
v2_mb_type
[(
cbp
&
3
)
+
4
][
0
]);
}
put_bits
(
&
s
->
pb
,
1
,
0
);
/* no AC prediction yet */
put_bits
(
&
s
->
pb
,
put_bits
(
&
s
->
pb
,
table_mb_non_intra
[
cbp
][
1
],
cbpy_tab
[
cbp
>>
2
][
1
],
table_mb_non_intra
[
cbp
][
0
]);
cbpy_tab
[
cbp
>>
2
][
0
]);
}
else
{
if
(
s
->
pict_type
==
I_TYPE
)
{
set_stat
(
ST_INTRA_MB
);
put_bits
(
&
s
->
pb
,
table_mb_intra
[
coded_cbp
][
1
],
table_mb_intra
[
coded_cbp
][
0
]);
}
else
{
if
(
s
->
use_skip_mb_code
)
put_bits
(
&
s
->
pb
,
1
,
0
);
/* mb coded */
put_bits
(
&
s
->
pb
,
table_mb_non_intra
[
cbp
][
1
],
table_mb_non_intra
[
cbp
][
0
]);
}
set_stat
(
ST_INTRA_MB
);
put_bits
(
&
s
->
pb
,
1
,
0
);
/* no AC prediction yet */
}
}
set_stat
(
ST_INTRA_MB
);
put_bits
(
&
s
->
pb
,
1
,
0
);
/* no AC prediction yet */
}
}
for
(
i
=
0
;
i
<
6
;
i
++
)
{
for
(
i
=
0
;
i
<
6
;
i
++
)
{
...
@@ -476,35 +522,46 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr
...
@@ -476,35 +522,46 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr
/* do the prediction */
/* do the prediction */
level
-=
pred
;
level
-=
pred
;
sign
=
0
;
if
(
s
->
msmpeg4_version
==
2
){
if
(
level
<
0
)
{
level
=
-
level
;
sign
=
1
;
}
code
=
level
;
if
(
code
>
DC_MAX
)
code
=
DC_MAX
;
if
(
s
->
dc_table_index
==
0
)
{
if
(
n
<
4
)
{
if
(
n
<
4
)
{
put_bits
(
&
s
->
pb
,
table0_dc_lum
[
code
][
1
],
table0_dc_lum
[
code
][
0
]);
put_bits
(
&
s
->
pb
,
}
else
{
v2_dc_lum_table
[
level
+
256
][
1
],
put_bits
(
&
s
->
pb
,
table0_dc_chroma
[
code
][
1
],
table0_dc_chroma
[
code
][
0
]);
v2_dc_lum_table
[
level
+
256
][
0
]);
}
else
{
put_bits
(
&
s
->
pb
,
v2_dc_chroma_table
[
level
+
256
][
1
],
v2_dc_chroma_table
[
level
+
256
][
0
]);
}
}
}
else
{
}
else
{
if
(
n
<
4
)
{
sign
=
0
;
put_bits
(
&
s
->
pb
,
table1_dc_lum
[
code
][
1
],
table1_dc_lum
[
code
][
0
]);
if
(
level
<
0
)
{
level
=
-
level
;
sign
=
1
;
}
code
=
level
;
if
(
code
>
DC_MAX
)
code
=
DC_MAX
;
if
(
s
->
dc_table_index
==
0
)
{
if
(
n
<
4
)
{
put_bits
(
&
s
->
pb
,
table0_dc_lum
[
code
][
1
],
table0_dc_lum
[
code
][
0
]);
}
else
{
put_bits
(
&
s
->
pb
,
table0_dc_chroma
[
code
][
1
],
table0_dc_chroma
[
code
][
0
]);
}
}
else
{
}
else
{
put_bits
(
&
s
->
pb
,
table1_dc_chroma
[
code
][
1
],
table1_dc_chroma
[
code
][
0
]);
if
(
n
<
4
)
{
put_bits
(
&
s
->
pb
,
table1_dc_lum
[
code
][
1
],
table1_dc_lum
[
code
][
0
]);
}
else
{
put_bits
(
&
s
->
pb
,
table1_dc_chroma
[
code
][
1
],
table1_dc_chroma
[
code
][
0
]);
}
}
if
(
code
==
DC_MAX
)
put_bits
(
&
s
->
pb
,
8
,
level
);
if
(
level
!=
0
)
{
put_bits
(
&
s
->
pb
,
1
,
sign
);
}
}
}
if
(
code
==
DC_MAX
)
put_bits
(
&
s
->
pb
,
8
,
level
);
if
(
level
!=
0
)
{
put_bits
(
&
s
->
pb
,
1
,
sign
);
}
}
}
}
...
@@ -532,7 +589,10 @@ static void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
...
@@ -532,7 +589,10 @@ static void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
}
else
{
}
else
{
i
=
0
;
i
=
0
;
rl
=
&
rl_table
[
3
+
s
->
rl_table_index
];
rl
=
&
rl_table
[
3
+
s
->
rl_table_index
];
run_diff
=
1
;
if
(
s
->
msmpeg4_version
==
2
)
run_diff
=
0
;
else
run_diff
=
1
;
set_stat
(
ST_INTER_AC
);
set_stat
(
ST_INTER_AC
);
}
}
...
@@ -853,6 +913,39 @@ static inline void memsetw(short *tab, int val, int n)
...
@@ -853,6 +913,39 @@ static inline void memsetw(short *tab, int val, int n)
tab
[
i
]
=
val
;
tab
[
i
]
=
val
;
}
}
static
void
msmpeg4v2_encode_motion
(
MpegEncContext
*
s
,
int
val
)
{
int
range
,
bit_size
,
sign
,
code
,
bits
;
if
(
val
==
0
)
{
/* zero vector */
code
=
0
;
put_bits
(
&
s
->
pb
,
mvtab
[
code
][
1
],
mvtab
[
code
][
0
]);
}
else
{
bit_size
=
s
->
f_code
-
1
;
range
=
1
<<
bit_size
;
if
(
val
<=
-
64
)
val
+=
64
;
else
if
(
val
>=
64
)
val
-=
64
;
if
(
val
>=
0
)
{
sign
=
0
;
}
else
{
val
=
-
val
;
sign
=
1
;
}
val
--
;
code
=
(
val
>>
bit_size
)
+
1
;
bits
=
val
&
(
range
-
1
);
put_bits
(
&
s
->
pb
,
mvtab
[
code
][
1
]
+
1
,
(
mvtab
[
code
][
0
]
<<
1
)
|
sign
);
if
(
bit_size
>
0
)
{
put_bits
(
&
s
->
pb
,
bit_size
,
bits
);
}
}
}
/* this is identical to h263 except that its range is multiplied by 2 */
/* this is identical to h263 except that its range is multiplied by 2 */
static
int
msmpeg4v2_decode_motion
(
MpegEncContext
*
s
,
int
pred
,
int
f_code
)
static
int
msmpeg4v2_decode_motion
(
MpegEncContext
*
s
,
int
pred
,
int
f_code
)
{
{
...
...
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