[FFmpeg-devel] [PATCH] add segment_path for save segment movie
Steven Liu
lingjiujianke at gmail.com
Fri Oct 25 16:54:18 CEST 2013
在 2013-10-25,下午9:56,Stefano Sabatini <stefasab at gmail.com> 写道:
> On date Friday 2013-10-25 16:01:11 +0800, Steven Liu encoded:
>>
>> 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];
>
> weird indent
>
>> 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);
>> + }
>
> inverted logic?
>
> You should use av_asprintf() in order to avoid arbitrary limitations
> on the path length.
>
> Also I believe you should change the set_segment_filename() code
> instead, in order to avoid code duplication.
>
>> + 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 },
>
> set segment path?
> Also weird indent.
>
Okay, I will send a new patch by this suggestion.
More information about the ffmpeg-devel
mailing list