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
1eaac1d6
Commit
1eaac1d6
authored
11 years ago
by
John Stebbins
Committed by
Anton Khirnov
11 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mpeg12dec: Extract CC user data into frame side data
Signed-off-by:
Anton Khirnov
<
anton@khirnov.net
>
parent
a16577d9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
1 deletion
+78
-1
APIchanges
doc/APIchanges
+4
-0
mpeg12dec.c
libavcodec/mpeg12dec.c
+67
-0
frame.h
libavutil/frame.h
+6
-0
version.h
libavutil/version.h
+1
-1
No files found.
doc/APIchanges
View file @
1eaac1d6
...
...
@@ -13,6 +13,10 @@ libavutil: 2012-10-22
API changes, most recent first:
2013-11-xx - xxxxxxx- - lavu 52.19.0 - frame.h
Add AV_FRAME_DATA_A53_CC value to the AVFrameSideDataType enum, which
identifies ATSC A53 Part 4 Closed Captions data.
2013-11-xx - xxxxxxx - lavu 52.18.0 - mem.h
Move av_fast_malloc() and av_fast_realloc() for libavcodec to libavutil.
...
...
This diff is collapsed.
Click to expand it.
libavcodec/mpeg12dec.c
View file @
1eaac1d6
...
...
@@ -44,6 +44,8 @@ typedef struct Mpeg1Context {
int
mpeg_enc_ctx_allocated
;
/* true if decoding context allocated */
int
repeat_field
;
/* true if we must repeat the field */
AVPanScan
pan_scan
;
/**< some temporary storage for the panscan */
uint8_t
*
a53_caption
;
int
a53_caption_size
;
int
slice_count
;
int
save_aspect_info
;
int
save_width
,
save_height
,
save_progressive_seq
;
...
...
@@ -1529,6 +1531,14 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
return
AVERROR
(
ENOMEM
);
memcpy
(
pan_scan
->
data
,
&
s1
->
pan_scan
,
sizeof
(
s1
->
pan_scan
));
if
(
s1
->
a53_caption
)
{
AVFrameSideData
*
sd
=
av_frame_new_side_data
(
&
s
->
current_picture_ptr
->
f
,
AV_FRAME_DATA_A53_CC
,
s1
->
a53_caption_size
);
if
(
sd
)
memcpy
(
sd
->
data
,
s1
->
a53_caption
,
s1
->
a53_caption_size
);
av_freep
(
&
s1
->
a53_caption
);
}
if
(
HAVE_THREADS
&&
(
avctx
->
active_thread_type
&
FF_THREAD_FRAME
))
ff_thread_finish_setup
(
avctx
);
}
else
{
// second field
...
...
@@ -2038,6 +2048,60 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
}
static
int
mpeg_decode_a53_cc
(
AVCodecContext
*
avctx
,
const
uint8_t
*
p
,
int
buf_size
)
{
Mpeg1Context
*
s1
=
avctx
->
priv_data
;
if
(
buf_size
>=
6
&&
p
[
0
]
==
'G'
&&
p
[
1
]
==
'A'
&&
p
[
2
]
==
'9'
&&
p
[
3
]
==
'4'
&&
p
[
4
]
==
3
&&
(
p
[
5
]
&
0x40
))
{
/* extract A53 Part 4 CC data */
int
cc_count
=
p
[
5
]
&
0x1f
;
if
(
cc_count
>
0
&&
buf_size
>=
7
+
cc_count
*
3
)
{
av_freep
(
&
s1
->
a53_caption
);
s1
->
a53_caption_size
=
cc_count
*
3
;
s1
->
a53_caption
=
av_malloc
(
s1
->
a53_caption_size
);
if
(
s1
->
a53_caption
)
{
memcpy
(
s1
->
a53_caption
,
p
+
7
,
s1
->
a53_caption_size
);
}
}
return
1
;
}
else
if
(
buf_size
>=
11
&&
p
[
0
]
==
'C'
&&
p
[
1
]
==
'C'
&&
p
[
2
]
==
0x01
&&
p
[
3
]
==
0xf8
)
{
/* extract DVD CC data */
int
cc_count
=
0
;
int
i
;
// There is a caption count field in the data, but it is often
// incorect. So count the number of captions present.
for
(
i
=
5
;
i
+
6
<=
buf_size
&&
((
p
[
i
]
&
0xfe
)
==
0xfe
);
i
+=
6
)
cc_count
++
;
// Transform the DVD format into A53 Part 4 format
if
(
cc_count
>
0
)
{
av_freep
(
&
s1
->
a53_caption
);
s1
->
a53_caption_size
=
cc_count
*
6
;
s1
->
a53_caption
=
av_malloc
(
s1
->
a53_caption_size
);
if
(
s1
->
a53_caption
)
{
uint8_t
field1
=
!!
(
p
[
4
]
&
0x80
);
uint8_t
*
cap
=
s1
->
a53_caption
;
p
+=
5
;
for
(
i
=
0
;
i
<
cc_count
;
i
++
)
{
cap
[
0
]
=
(
p
[
0
]
==
0xff
&&
field1
)
?
0xfc
:
0xfd
;
cap
[
1
]
=
p
[
1
];
cap
[
2
]
=
p
[
2
];
cap
[
3
]
=
(
p
[
3
]
==
0xff
&&
!
field1
)
?
0xfc
:
0xfd
;
cap
[
4
]
=
p
[
4
];
cap
[
5
]
=
p
[
5
];
cap
+=
6
;
p
+=
6
;
}
}
}
return
1
;
}
return
0
;
}
static
void
mpeg_decode_user_data
(
AVCodecContext
*
avctx
,
const
uint8_t
*
p
,
int
buf_size
)
{
...
...
@@ -2057,6 +2121,8 @@ static void mpeg_decode_user_data(AVCodecContext *avctx,
return
;
avctx
->
dtg_active_format
=
p
[
0
]
&
0x0f
;
}
}
else
if
(
mpeg_decode_a53_cc
(
avctx
,
p
,
buf_size
))
{
return
;
}
}
...
...
@@ -2402,6 +2468,7 @@ static av_cold int mpeg_decode_end(AVCodecContext *avctx)
if
(
s
->
mpeg_enc_ctx_allocated
)
ff_MPV_common_end
(
&
s
->
mpeg_enc_ctx
);
av_freep
(
&
s
->
a53_caption
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
libavutil/frame.h
View file @
1eaac1d6
...
...
@@ -35,6 +35,12 @@ enum AVFrameSideDataType {
* The data is the AVPanScan struct defined in libavcodec.
*/
AV_FRAME_DATA_PANSCAN
,
/**
* ATSC A53 Part 4 Closed Captions.
* A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.
* The number of bytes of CC data is AVFrameSideData.size.
*/
AV_FRAME_DATA_A53_CC
,
};
typedef
struct
AVFrameSideData
{
...
...
This diff is collapsed.
Click to expand it.
libavutil/version.h
View file @
1eaac1d6
...
...
@@ -37,7 +37,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 1
8
#define LIBAVUTIL_VERSION_MINOR 1
9
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
...
...
This diff is collapsed.
Click to expand it.
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