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
7c9f9685
Commit
7c9f9685
authored
Jun 22, 2012
by
Clément Bœsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavf: add internal demuxer helpers for subtitles.
parent
f926d916
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
0 deletions
+163
-0
Makefile
libavformat/Makefile
+1
-0
subtitles.c
libavformat/subtitles.c
+101
-0
subtitles.h
libavformat/subtitles.h
+61
-0
No files found.
libavformat/Makefile
View file @
7c9f9685
...
@@ -19,6 +19,7 @@ OBJS = allformats.o \
...
@@ -19,6 +19,7 @@ OBJS = allformats.o \
riff.o
\
riff.o
\
sdp.o
\
sdp.o
\
seek.o
\
seek.o
\
subtitles.o
\
utils.o
\
utils.o
\
OBJS-$(CONFIG_NETWORK)
+=
network.o
OBJS-$(CONFIG_NETWORK)
+=
network.o
...
...
libavformat/subtitles.c
0 → 100644
View file @
7c9f9685
/*
* Copyright (c) 2012 Clément Bœsch
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "subtitles.h"
AVPacket
*
ff_subtitles_queue_insert
(
FFDemuxSubtitlesQueue
*
q
,
const
uint8_t
*
event
,
int
len
,
int
merge
)
{
AVPacket
*
subs
,
*
sub
;
if
(
merge
&&
q
->
nb_subs
>
0
)
{
/* merge with previous event */
int
old_len
;
sub
=
&
q
->
subs
[
q
->
nb_subs
-
1
];
old_len
=
sub
->
size
;
if
(
av_grow_packet
(
sub
,
len
)
<
0
)
return
NULL
;
memcpy
(
sub
->
data
+
old_len
,
event
,
len
);
}
else
{
/* new event */
if
(
q
->
nb_subs
>=
INT_MAX
/
sizeof
(
*
q
->
subs
)
-
1
)
return
NULL
;
subs
=
av_fast_realloc
(
q
->
subs
,
&
q
->
allocated_size
,
(
q
->
nb_subs
+
1
)
*
sizeof
(
*
q
->
subs
));
if
(
!
subs
)
return
NULL
;
q
->
subs
=
subs
;
sub
=
&
subs
[
q
->
nb_subs
++
];
if
(
av_new_packet
(
sub
,
len
)
<
0
)
return
NULL
;
sub
->
destruct
=
NULL
;
sub
->
flags
|=
AV_PKT_FLAG_KEY
;
sub
->
pts
=
sub
->
dts
=
0
;
memcpy
(
sub
->
data
,
event
,
len
);
}
return
sub
;
}
static
int
cmp_pkt_sub
(
const
void
*
a
,
const
void
*
b
)
{
const
AVPacket
*
s1
=
a
;
const
AVPacket
*
s2
=
b
;
if
(
s1
->
pts
==
s2
->
pts
)
{
if
(
s1
->
pos
==
s2
->
pos
)
return
0
;
return
s1
->
pos
>
s2
->
pos
?
1
:
-
1
;
}
return
s1
->
pts
>
s2
->
pts
?
1
:
-
1
;
}
void
ff_subtitles_queue_finalize
(
FFDemuxSubtitlesQueue
*
q
)
{
int
i
;
qsort
(
q
->
subs
,
q
->
nb_subs
,
sizeof
(
*
q
->
subs
),
cmp_pkt_sub
);
for
(
i
=
0
;
i
<
q
->
nb_subs
;
i
++
)
if
(
q
->
subs
[
i
].
duration
==
-
1
&&
i
<
q
->
nb_subs
-
1
)
q
->
subs
[
i
].
duration
=
q
->
subs
[
i
+
1
].
pts
-
q
->
subs
[
i
].
pts
;
}
int
ff_subtitles_queue_read_packet
(
FFDemuxSubtitlesQueue
*
q
,
AVPacket
*
pkt
)
{
AVPacket
*
sub
=
q
->
subs
+
q
->
current_sub_idx
;
if
(
q
->
current_sub_idx
==
q
->
nb_subs
)
return
AVERROR_EOF
;
*
pkt
=
*
sub
;
pkt
->
dts
=
pkt
->
pts
;
q
->
current_sub_idx
++
;
return
0
;
}
void
ff_subtitles_queue_clean
(
FFDemuxSubtitlesQueue
*
q
)
{
int
i
;
for
(
i
=
0
;
i
<
q
->
nb_subs
;
i
++
)
av_destruct_packet
(
&
q
->
subs
[
i
]);
av_freep
(
&
q
->
subs
);
q
->
nb_subs
=
q
->
allocated_size
=
q
->
current_sub_idx
=
0
;
}
libavformat/subtitles.h
0 → 100644
View file @
7c9f9685
/*
* Copyright (c) 2012 Clément Bœsch
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_SUBTITLES_H
#define AVFORMAT_SUBTITLES_H
#include <stdint.h>
#include "avformat.h"
typedef
struct
{
AVPacket
*
subs
;
///< array of subtitles packets
int
nb_subs
;
///< number of subtitles packets
int
allocated_size
;
///< allocated size for subs
int
current_sub_idx
;
///< current position for the read packet callback
}
FFDemuxSubtitlesQueue
;
/**
* Insert a new subtitle event.
*
* @param event the subtitle line, may not be zero terminated
* @param len the length of the event (in strlen() sense, so without '\0')
* @param merge set to 1 if the current event should be concatenated with the
* previous one instead of adding a new entry, 0 otherwise
*/
AVPacket
*
ff_subtitles_queue_insert
(
FFDemuxSubtitlesQueue
*
q
,
const
uint8_t
*
event
,
int
len
,
int
merge
);
/**
* Set missing durations and sort subtitles by PTS, and then byte position.
*/
void
ff_subtitles_queue_finalize
(
FFDemuxSubtitlesQueue
*
q
);
/**
* Generic read_packet() callback for subtitles demuxers using this queue
* system.
*/
int
ff_subtitles_queue_read_packet
(
FFDemuxSubtitlesQueue
*
q
,
AVPacket
*
pkt
);
/**
* Remove and destroy all the subtitles packets.
*/
void
ff_subtitles_queue_clean
(
FFDemuxSubtitlesQueue
*
q
);
#endif
/* AVFORMAT_SUBTITLES_H */
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