Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
073f8b10
Commit
073f8b10
authored
14 years ago
by
Anton Khirnov
Committed by
Luca Barbato
14 years ago
Browse files
Options
Downloads
Patches
Plain Diff
nutenc: mux chapters.
Signed-off-by:
Luca Barbato
<
lu_zero@gentoo.org
>
parent
4af9c1a5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libavformat/nut.h
+5
-0
5 additions, 0 deletions
libavformat/nut.h
libavformat/nutenc.c
+62
-4
62 additions, 4 deletions
libavformat/nutenc.c
with
67 additions
and
4 deletions
libavformat/nut.h
+
5
−
0
View file @
073f8b10
...
@@ -81,6 +81,10 @@ typedef struct {
...
@@ -81,6 +81,10 @@ typedef struct {
int
decode_delay
;
//FIXME duplicate of has_b_frames
int
decode_delay
;
//FIXME duplicate of has_b_frames
}
StreamContext
;
}
StreamContext
;
typedef
struct
{
AVRational
*
time_base
;
}
ChapterContext
;
typedef
struct
{
typedef
struct
{
AVFormatContext
*
avf
;
AVFormatContext
*
avf
;
// int written_packet_size;
// int written_packet_size;
...
@@ -90,6 +94,7 @@ typedef struct {
...
@@ -90,6 +94,7 @@ typedef struct {
const
uint8_t
*
header
[
128
];
const
uint8_t
*
header
[
128
];
uint64_t
next_startcode
;
///< stores the next startcode if it has already been parsed but the stream is not seekable
uint64_t
next_startcode
;
///< stores the next startcode if it has already been parsed but the stream is not seekable
StreamContext
*
stream
;
StreamContext
*
stream
;
ChapterContext
*
chapter
;
unsigned
int
max_distance
;
unsigned
int
max_distance
;
unsigned
int
time_base_count
;
unsigned
int
time_base_count
;
int64_t
last_syncpoint_pos
;
int64_t
last_syncpoint_pos
;
...
...
This diff is collapsed.
Click to expand it.
libavformat/nutenc.c
+
62
−
4
View file @
073f8b10
...
@@ -241,9 +241,9 @@ static void build_frame_code(AVFormatContext *s){
...
@@ -241,9 +241,9 @@ static void build_frame_code(AVFormatContext *s){
nut
->
frame_code
[
'N'
].
flags
=
FLAG_INVALID
;
nut
->
frame_code
[
'N'
].
flags
=
FLAG_INVALID
;
}
}
static
void
put_tt
(
NUTContext
*
nut
,
StreamContext
*
nus
,
AVIOContext
*
bc
,
uint64_t
val
){
static
void
put_tt
(
NUTContext
*
nut
,
AVRational
*
time_base
,
AVIOContext
*
bc
,
uint64_t
val
){
val
*=
nut
->
time_base_count
;
val
*=
nut
->
time_base_count
;
val
+=
nus
->
time_base
-
nut
->
time_base
;
val
+=
time_base
-
nut
->
time_base
;
ff_put_v
(
bc
,
val
);
ff_put_v
(
bc
,
val
);
}
}
...
@@ -486,6 +486,34 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id){
...
@@ -486,6 +486,34 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id){
return
count
;
return
count
;
}
}
static
int
write_chapter
(
NUTContext
*
nut
,
AVIOContext
*
bc
,
int
id
)
{
AVIOContext
*
dyn_bc
;
uint8_t
*
dyn_buf
=
NULL
;
AVMetadataTag
*
t
=
NULL
;
AVChapter
*
ch
=
nut
->
avf
->
chapters
[
id
];
int
ret
,
dyn_size
,
count
=
0
;
ret
=
url_open_dyn_buf
(
&
dyn_bc
);
if
(
ret
<
0
)
return
ret
;
ff_put_v
(
bc
,
0
);
// stream_id_plus1
put_s
(
bc
,
id
+
1
);
// chapter_id
put_tt
(
nut
,
nut
->
chapter
[
id
].
time_base
,
bc
,
ch
->
start
);
// chapter_start
ff_put_v
(
bc
,
ch
->
end
-
ch
->
start
);
// chapter_len
while
((
t
=
av_metadata_get
(
ch
->
metadata
,
""
,
t
,
AV_METADATA_IGNORE_SUFFIX
)))
count
+=
add_info
(
dyn_bc
,
t
->
key
,
t
->
value
);
ff_put_v
(
bc
,
count
);
dyn_size
=
url_close_dyn_buf
(
dyn_bc
,
&
dyn_buf
);
avio_write
(
bc
,
dyn_buf
,
dyn_size
);
av_freep
(
&
dyn_buf
);
return
0
;
}
static
int
write_headers
(
AVFormatContext
*
avctx
,
AVIOContext
*
bc
){
static
int
write_headers
(
AVFormatContext
*
avctx
,
AVIOContext
*
bc
){
NUTContext
*
nut
=
avctx
->
priv_data
;
NUTContext
*
nut
=
avctx
->
priv_data
;
AVIOContext
*
dyn_bc
;
AVIOContext
*
dyn_bc
;
...
@@ -530,6 +558,20 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
...
@@ -530,6 +558,20 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
}
}
}
}
for
(
i
=
0
;
i
<
nut
->
avf
->
nb_chapters
;
i
++
)
{
ret
=
url_open_dyn_buf
(
&
dyn_bc
);
if
(
ret
<
0
)
return
ret
;
ret
=
write_chapter
(
nut
,
dyn_bc
,
i
);
if
(
ret
<
0
)
{
uint8_t
*
buf
;
url_close_dyn_buf
(
dyn_bc
,
&
buf
);
av_freep
(
&
buf
);
return
ret
;
}
put_packet
(
nut
,
bc
,
dyn_bc
,
1
,
INFO_STARTCODE
);
}
nut
->
last_syncpoint_pos
=
INT_MIN
;
nut
->
last_syncpoint_pos
=
INT_MIN
;
nut
->
header_count
++
;
nut
->
header_count
++
;
return
0
;
return
0
;
...
@@ -543,7 +585,9 @@ static int write_header(AVFormatContext *s){
...
@@ -543,7 +585,9 @@ static int write_header(AVFormatContext *s){
nut
->
avf
=
s
;
nut
->
avf
=
s
;
nut
->
stream
=
av_mallocz
(
sizeof
(
StreamContext
)
*
s
->
nb_streams
);
nut
->
stream
=
av_mallocz
(
sizeof
(
StreamContext
)
*
s
->
nb_streams
);
nut
->
time_base
=
av_mallocz
(
sizeof
(
AVRational
)
*
s
->
nb_streams
);
nut
->
chapter
=
av_mallocz
(
sizeof
(
ChapterContext
)
*
s
->
nb_chapters
);
nut
->
time_base
=
av_mallocz
(
sizeof
(
AVRational
)
*
(
s
->
nb_streams
+
s
->
nb_chapters
));
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
){
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
){
AVStream
*
st
=
s
->
streams
[
i
];
AVStream
*
st
=
s
->
streams
[
i
];
...
@@ -570,6 +614,20 @@ static int write_header(AVFormatContext *s){
...
@@ -570,6 +614,20 @@ static int write_header(AVFormatContext *s){
nut
->
stream
[
i
].
max_pts_distance
=
FFMAX
(
time_base
.
den
,
time_base
.
num
)
/
time_base
.
num
;
nut
->
stream
[
i
].
max_pts_distance
=
FFMAX
(
time_base
.
den
,
time_base
.
num
)
/
time_base
.
num
;
}
}
for
(
i
=
0
;
i
<
s
->
nb_chapters
;
i
++
)
{
AVChapter
*
ch
=
s
->
chapters
[
i
];
for
(
j
=
0
;
j
<
nut
->
time_base_count
;
j
++
)
{
if
(
!
memcmp
(
&
ch
->
time_base
,
&
nut
->
time_base
[
j
],
sizeof
(
AVRational
)))
break
;
}
nut
->
time_base
[
j
]
=
ch
->
time_base
;
nut
->
chapter
[
i
].
time_base
=
&
nut
->
time_base
[
j
];
if
(
j
==
nut
->
time_base_count
)
nut
->
time_base_count
++
;
}
nut
->
max_distance
=
MAX_DISTANCE
;
nut
->
max_distance
=
MAX_DISTANCE
;
build_elision_headers
(
s
);
build_elision_headers
(
s
);
build_frame_code
(
s
);
build_frame_code
(
s
);
...
@@ -672,7 +730,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
...
@@ -672,7 +730,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
ret
=
url_open_dyn_buf
(
&
dyn_bc
);
ret
=
url_open_dyn_buf
(
&
dyn_bc
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
put_tt
(
nut
,
nus
,
dyn_bc
,
pkt
->
dts
);
put_tt
(
nut
,
nus
->
time_base
,
dyn_bc
,
pkt
->
dts
);
ff_put_v
(
dyn_bc
,
sp
?
(
nut
->
last_syncpoint_pos
-
sp
->
pos
)
>>
4
:
0
);
ff_put_v
(
dyn_bc
,
sp
?
(
nut
->
last_syncpoint_pos
-
sp
->
pos
)
>>
4
:
0
);
put_packet
(
nut
,
bc
,
dyn_bc
,
1
,
SYNCPOINT_STARTCODE
);
put_packet
(
nut
,
bc
,
dyn_bc
,
1
,
SYNCPOINT_STARTCODE
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment