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
2058b52c
Commit
2058b52c
authored
Jan 28, 2012
by
Stefano Sabatini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavf/segment: add -segment_times option
Address trac ticket #1504.
parent
f8911b98
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
7 deletions
+96
-7
muxers.texi
doc/muxers.texi
+10
-0
segment.c
libavformat/segment.c
+85
-6
version.h
libavformat/version.h
+1
-1
No files found.
doc/muxers.texi
View file @
2058b52c
...
@@ -474,6 +474,9 @@ the segment start and end time expressed in seconds.
...
@@ -474,6 +474,9 @@ the segment start and end time expressed in seconds.
Default value is "flat".
Default value is "flat".
@item segment_time @var{time}
@item segment_time @var{time}
Set segment duration to @var{time}. Default value is "2".
Set segment duration to @var{time}. Default value is "2".
@item segment_times @var{times}
Specify a list of split points. @var{times} contains a list of comma
separated duration specifications, in increasing order.
@item segment_wrap @var{limit}
@item segment_wrap @var{limit}
Wrap around segment index once it reaches @var{limit}.
Wrap around segment index once it reaches @var{limit}.
@end table
@end table
...
@@ -489,6 +492,13 @@ generated segments to @file{out.list}:
...
@@ -489,6 +492,13 @@ generated segments to @file{out.list}:
ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list out.list out%03d.nut
ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list out.list out%03d.nut
@end example
@end example
@item
As the example above, but segment the input file according to the split
points specified by the @var{segment_times} option:
@example
ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list_type ext -segment_list out.list -segment_list_size 0 -segment_times 1,2,3,5,8,13,21 out%03d.nut
@end example
@item
@item
To convert the @file{in.mkv} to TS segments using the @code{libx264}
To convert the @file{in.mkv} to TS segments using the @code{libx264}
and @code{libfaac} encoders:
and @code{libfaac} encoders:
...
...
libavformat/segment.c
View file @
2058b52c
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "avformat.h"
#include "avformat.h"
#include "internal.h"
#include "internal.h"
#include "libavutil/avassert.h"
#include "libavutil/log.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "libavutil/avstring.h"
#include "libavutil/avstring.h"
...
@@ -48,6 +49,9 @@ typedef struct {
...
@@ -48,6 +49,9 @@ typedef struct {
int
wrap
;
///< number after which the index wraps
int
wrap
;
///< number after which the index wraps
char
*
time_str
;
///< segment duration specification string
char
*
time_str
;
///< segment duration specification string
int64_t
time
;
///< segment duration
int64_t
time
;
///< segment duration
char
*
times_str
;
///< segment times specification string
int64_t
*
times
;
///< list of segment interval specification
int
nb_times
;
///< number of elments in the times array
int
has_video
;
int
has_video
;
double
start_time
,
end_time
;
double
start_time
,
end_time
;
}
SegmentContext
;
}
SegmentContext
;
...
@@ -136,6 +140,59 @@ end:
...
@@ -136,6 +140,59 @@ end:
return
ret
;
return
ret
;
}
}
static
int
parse_times
(
void
*
log_ctx
,
int64_t
**
times
,
int
*
nb_times
,
const
char
*
times_str
)
{
char
*
p
;
int
i
,
ret
=
0
;
char
*
times_str1
=
av_strdup
(
times_str
);
char
*
saveptr
=
NULL
;
if
(
!
times_str1
)
return
AVERROR
(
ENOMEM
);
#define FAIL(err) ret = err; goto end
*
nb_times
=
1
;
for
(
p
=
times_str1
;
*
p
;
p
++
)
if
(
*
p
==
','
)
(
*
nb_times
)
++
;
*
times
=
av_malloc
(
sizeof
(
**
times
)
*
*
nb_times
);
if
(
!*
times
)
{
av_log
(
log_ctx
,
AV_LOG_ERROR
,
"Could not allocate forced times array
\n
"
);
FAIL
(
AVERROR
(
ENOMEM
));
}
p
=
times_str1
;
for
(
i
=
0
;
i
<
*
nb_times
;
i
++
)
{
int64_t
t
;
char
*
tstr
=
av_strtok
(
p
,
","
,
&
saveptr
);
av_assert0
(
tstr
);
p
=
NULL
;
ret
=
av_parse_time
(
&
t
,
tstr
,
1
);
if
(
ret
<
0
)
{
av_log
(
log_ctx
,
AV_LOG_ERROR
,
"Invalid time duration specification in %s
\n
"
,
p
);
FAIL
(
AVERROR
(
EINVAL
));
}
(
*
times
)[
i
]
=
t
;
/* check on monotonicity */
if
(
i
&&
(
*
times
)[
i
-
1
]
>
(
*
times
)[
i
])
{
av_log
(
log_ctx
,
AV_LOG_ERROR
,
"Specified time %f is greater than the following time %f
\n
"
,
(
float
)((
*
times
)[
i
])
/
1000000
,
(
float
)((
*
times
)[
i
-
1
])
/
1000000
);
FAIL
(
AVERROR
(
EINVAL
));
}
}
end:
av_free
(
times_str1
);
return
ret
;
}
static
int
seg_write_header
(
AVFormatContext
*
s
)
static
int
seg_write_header
(
AVFormatContext
*
s
)
{
{
SegmentContext
*
seg
=
s
->
priv_data
;
SegmentContext
*
seg
=
s
->
priv_data
;
...
@@ -144,11 +201,25 @@ static int seg_write_header(AVFormatContext *s)
...
@@ -144,11 +201,25 @@ static int seg_write_header(AVFormatContext *s)
seg
->
number
=
0
;
seg
->
number
=
0
;
if
(
(
ret
=
av_parse_time
(
&
seg
->
time
,
seg
->
time_str
,
1
))
<
0
)
{
if
(
seg
->
time_str
&&
seg
->
times_str
)
{
av_log
(
s
,
AV_LOG_ERROR
,
av_log
(
s
,
AV_LOG_ERROR
,
"Invalid time duration specification '%s' for segment_time option
\n
"
,
"segment_time and segment_times options are mutually exclusive, select just one of them
\n
"
);
seg
->
time_str
);
return
AVERROR
(
EINVAL
);
return
ret
;
}
if
(
seg
->
times_str
)
{
if
((
ret
=
parse_times
(
s
,
&
seg
->
times
,
&
seg
->
nb_times
,
seg
->
times_str
))
<
0
)
return
ret
;
}
else
{
/* set default value if not specified */
if
(
!
seg
->
time_str
)
seg
->
time_str
=
av_strdup
(
"2"
);
if
((
ret
=
av_parse_time
(
&
seg
->
time
,
seg
->
time_str
,
1
))
<
0
)
{
av_log
(
s
,
AV_LOG_ERROR
,
"Invalid time duration specification '%s' for segment_time option
\n
"
,
seg
->
time_str
);
return
ret
;
}
}
}
oc
=
avformat_alloc_context
();
oc
=
avformat_alloc_context
();
...
@@ -221,9 +292,15 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
...
@@ -221,9 +292,15 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
SegmentContext
*
seg
=
s
->
priv_data
;
SegmentContext
*
seg
=
s
->
priv_data
;
AVFormatContext
*
oc
=
seg
->
avf
;
AVFormatContext
*
oc
=
seg
->
avf
;
AVStream
*
st
=
oc
->
streams
[
pkt
->
stream_index
];
AVStream
*
st
=
oc
->
streams
[
pkt
->
stream_index
];
int64_t
end_pts
=
seg
->
time
*
seg
->
number
;
int64_t
end_pts
;
int
ret
;
int
ret
;
if
(
seg
->
times
)
{
end_pts
=
seg
->
number
<=
seg
->
nb_times
?
seg
->
times
[
seg
->
number
-
1
]
:
INT64_MAX
;
}
else
{
end_pts
=
seg
->
time
*
seg
->
number
;
}
/* if the segment has video, start a new segment *only* with a key video frame */
/* if the segment has video, start a new segment *only* with a key video frame */
if
((
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
||
!
seg
->
has_video
)
&&
if
((
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
||
!
seg
->
has_video
)
&&
av_compare_ts
(
pkt
->
pts
,
st
->
time_base
,
av_compare_ts
(
pkt
->
pts
,
st
->
time_base
,
...
@@ -264,6 +341,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
...
@@ -264,6 +341,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
avio_close
(
seg
->
list_pb
);
avio_close
(
seg
->
list_pb
);
av_opt_free
(
seg
);
av_opt_free
(
seg
);
av_freep
(
&
seg
->
times
);
oc
->
streams
=
NULL
;
oc
->
streams
=
NULL
;
oc
->
nb_streams
=
0
;
oc
->
nb_streams
=
0
;
...
@@ -280,7 +358,8 @@ static const AVOption options[] = {
...
@@ -280,7 +358,8 @@ static const AVOption options[] = {
{
"segment_list_type"
,
"set the segment list type"
,
OFFSET
(
list_type
),
AV_OPT_TYPE_INT
,
{.
dbl
=
LIST_TYPE_FLAT
},
0
,
LIST_TYPE_NB
-
1
,
E
,
"list_type"
},
{
"segment_list_type"
,
"set the segment list type"
,
OFFSET
(
list_type
),
AV_OPT_TYPE_INT
,
{.
dbl
=
LIST_TYPE_FLAT
},
0
,
LIST_TYPE_NB
-
1
,
E
,
"list_type"
},
{
"flat"
,
"flat format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
dbl
=
LIST_TYPE_FLAT
},
INT_MIN
,
INT_MAX
,
0
,
"list_type"
},
{
"flat"
,
"flat format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
dbl
=
LIST_TYPE_FLAT
},
INT_MIN
,
INT_MAX
,
0
,
"list_type"
},
{
"ext"
,
"extended format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
dbl
=
LIST_TYPE_EXT
},
INT_MIN
,
INT_MAX
,
0
,
"list_type"
},
{
"ext"
,
"extended format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
dbl
=
LIST_TYPE_EXT
},
INT_MIN
,
INT_MAX
,
0
,
"list_type"
},
{
"segment_time"
,
"set segment duration"
,
OFFSET
(
time_str
),
AV_OPT_TYPE_STRING
,
{.
str
=
"2"
},
0
,
0
,
E
},
{
"segment_time"
,
"set segment duration"
,
OFFSET
(
time_str
),
AV_OPT_TYPE_STRING
,
{.
str
=
NULL
},
0
,
0
,
E
},
{
"segment_times"
,
"set segment split time points"
,
OFFSET
(
times_str
),
AV_OPT_TYPE_STRING
,{.
str
=
NULL
},
0
,
0
,
E
},
{
"segment_wrap"
,
"set number after which the index wraps"
,
OFFSET
(
wrap
),
AV_OPT_TYPE_INT
,
{.
dbl
=
0
},
0
,
INT_MAX
,
E
},
{
"segment_wrap"
,
"set number after which the index wraps"
,
OFFSET
(
wrap
),
AV_OPT_TYPE_INT
,
{.
dbl
=
0
},
0
,
INT_MAX
,
E
},
{
NULL
},
{
NULL
},
};
};
...
...
libavformat/version.h
View file @
2058b52c
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 15
#define LIBAVFORMAT_VERSION_MINOR 15
#define LIBAVFORMAT_VERSION_MICRO 10
2
#define LIBAVFORMAT_VERSION_MICRO 10
3
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
LIBAVFORMAT_VERSION_MINOR, \
...
...
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