[FFmpeg-devel] [PATCH v2 0/6] avformat/segment: Various segment muxer improvements
ffmpegagent
ffmpegagent at gmail.com
Sat Jun 14 03:59:06 EEST 2025
Includes
* Two new options
* segment_write_temp
Allows to write segments as temp files (.tmp) which are renamed on
completion
* segment_limit Stop after n segments have been written
* some minor changes (option contraints and formatting fixes)
Versions
========
V2
==
* merge the documentation patch with the feature patch
* segment_write_temp: use av_asprintf() directly instead of strlcatf() +
av_strdup()
(as per review by Marton - thanks!)
* removed logging patch
.
softworkz (6):
avformat/segment: Add segment_write_temp option
avformat/segment: Add segment_limit option
avformat/segment: Remove non-negative constraint from
segment_time_delta
avformat/segment: Don't allow negative segment duration
avformat/segment: Fix typo
avformat/segment: Indent and whitespace fixes
doc/muxers.texi | 12 ++++++
libavformat/segment.c | 95 +++++++++++++++++++++++++++++--------------
2 files changed, 76 insertions(+), 31 deletions(-)
base-commit: f3bf5356966b4ad9334034e720fa224c2d9464a6
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-96%2Fsoftworkz%2Fsubmit_segment_muxer-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-96/softworkz/submit_segment_muxer-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/96
Range-diff vs v1:
1: 0132f3f933 ! 1: 79b4f63573 avformat/segment: Add segment_write_temp option
@@ Commit message
Signed-off-by: softworkz <softworkz at hotmail.com>
+ ## doc/muxers.texi ##
+@@ doc/muxers.texi: argument must be a time duration specification, and defaults to 0.
+ If enabled, write an empty segment if there are no packets during the period a
+ segment would usually span. Otherwise, the segment will be filled with the next
+ packet written. Defaults to @code{0}.
++
++ at item segment_write_temp @var{1|0}
++Write segments to files with a .tmp extension. Each file is renamed to its
++actual name on completion. This can help to prevent segment files from
++being accessed before they are complete. Disabled by default (@code{0}).
+ @end table
+
+ Make sure to require a closed GOP when encoding and to set the GOP
+
## libavformat/segment.c ##
@@ libavformat/segment.c: typedef struct SegmentContext {
int break_non_keyframes;
@@ libavformat/segment.c: static int set_segment_filename(AVFormatContext *s)
+ // Write segment as a temp file and rename on completion
+ if(seg->segment_write_temp) {
-+ av_strlcatf(buf, sizeof(buf), ".tmp");
-+ char *temp_name = av_strdup(buf);
++ char *temp_name = av_asprintf("%s%s", buf, ".tmp");
+ if (!temp_name)
+ return AVERROR(ENOMEM);
+ ff_format_set_url(oc, temp_name);
2: 2bad7a3acc < -: ---------- doc/muxers: Add documentation for segment_write_temp option
3: 6a76e43900 < -: ---------- avformat/segment: Log more detailed information about written segments
4: 4f05a7d2e9 ! 2: 10b1c22439 avformat/segment: Add segment_limit option
@@ Commit message
Signed-off-by: softworkz <softworkz at hotmail.com>
+ ## doc/muxers.texi ##
+@@ doc/muxers.texi: packet written. Defaults to @code{0}.
+ Write segments to files with a .tmp extension. Each file is renamed to its
+ actual name on completion. This can help to prevent segment files from
+ being accessed before they are complete. Disabled by default (@code{0}).
++
++ at item segment_limit @var{number}
++Stops after the specified number of segments has been generated.
++This can be helpful to fill gaps in a range of already generated segments,
++which is difficult to achieve otherwise as it would either cause the last
++segment to be incomplete or to overwrite an existing segment with a partial
++data. Default is @code{0} - no limit.
+ @end table
+
+ Make sure to require a closed GOP when encoding and to set the GOP
+
## libavformat/segment.c ##
@@ libavformat/segment.c: typedef struct SegmentContext {
int break_non_keyframes;
5: 53b693320f < -: ---------- doc/muxers: Add documentation for segment_limit option
6: ddf37a882b < -: ---------- avformat/segment: Fix invalid codecpar extradata_size after copying
7: d5def15604 = 3: a855134dc7 avformat/segment: Remove non-negative constraint from segment_time_delta
8: 16cb8ea92b = 4: 33139f28c8 avformat/segment: Don't allow negative segment duration
9: 1348b1b42c = 5: 64451d004a avformat/segment: Fix typo
10: 88a8dc7875 = 6: cb3267591d avformat/segment: Indent and whitespace fixes
--
ffmpeg-codebot
More information about the ffmpeg-devel
mailing list