[FFmpeg-devel] [PATCH] add segment_path for save segment movie
Steven Liu
lingjiujianke at gmail.com
Fri Oct 25 10:01:11 CEST 2013
Create file in segment_path, and *DO NOT WANT* write the path into the
list file, use "-segment_path path" can do it. if *WANT* write the path into
the list, *NO USE* "-segment_path path"
---
libavformat/segment.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 05e29d4..4e4765e 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -75,6 +75,7 @@ typedef struct {
ListType list_type; ///< set the list type
AVIOContext *list_pb; ///< list file put-byte context
char *time_str; ///< segment duration specification string
+ char *path;
int64_t time; ///< segment duration
char *times_str; ///< segment times specification string
@@ -175,6 +176,7 @@ static int segment_start(AVFormatContext *s, int write_header)
SegmentContext *seg = s->priv_data;
AVFormatContext *oc = seg->avf;
int err = 0;
+ uint8_t seg_path[1024];
if (write_header) {
avformat_free_context(oc);
@@ -188,7 +190,13 @@ static int segment_start(AVFormatContext *s, int write_header)
if ((err = set_segment_filename(s)) < 0)
return err;
- if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
+ /* seg_path = path + filename */
+ if (!seg->path) {
+ snprintf(seg_path, sizeof(seg_path), "%s/%s", seg->path, oc->filename);
+ } else {
+ snprintf(seg_path, sizeof(seg_path), "%s", oc->filename);
+ }
+ if ((err = avio_open2(&oc->pb, seg_path, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0)
return err;
@@ -528,6 +536,7 @@ static int seg_write_header(AVFormatContext *s)
SegmentContext *seg = s->priv_data;
AVFormatContext *oc = NULL;
int ret;
+ uint8_t seg_path[1024];
seg->segment_count = 0;
if (!seg->write_header_trailer)
@@ -599,8 +608,15 @@ static int seg_write_header(AVFormatContext *s)
goto fail;
if (seg->write_header_trailer) {
- if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
- &s->interrupt_callback, NULL)) < 0)
+
+ /* seg_path = path + filename */
+ if (!seg->path) {
+ snprintf(seg_path, sizeof(seg_path), "%s/%s", seg->path, oc->filename);
+ } else {
+ snprintf(seg_path, sizeof(seg_path), "%s", oc->filename);
+ }
+ if ((ret = avio_open2(&oc->pb, seg_path, AVIO_FLAG_WRITE,
+ &s->interrupt_callback, NULL)) < 0)
goto fail;
} else {
if ((ret = open_null_ctx(&oc->pb)) < 0)
@@ -779,6 +795,7 @@ static const AVOption options[] = {
{ "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, 0, E },
{ "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
{ "segment_frames", "set segment split frame numbers", OFFSET(frames_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
+ { "segment_path", "set segment save to path", OFFSET(path),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
{ "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
{ "segment_start_number", "set the sequence number of the first segment", OFFSET(segment_idx), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
--
1.7.12.4 (Apple Git-37)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-add-segment_path-for-save-segment-movie.patch
Type: application/octet-stream
Size: 3815 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131025/d321dc22/attachment.obj>
More information about the ffmpeg-devel
mailing list