[FFmpeg-devel] avformat/img2enc: add strftime_mkdir option to automatically create time-based directories

2020-09-17 Thread xiaofeng
-- 
xiaofeng

--
gpg key fingerprint:
2048R/5E63005B
C84F 671F 70B7 7330 4726  5EC8 02BC CBA2 5E63 005B
--
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
From 1d8e36f2231a03999d874a6915d042b0ebbe3d68 Mon Sep 17 00:00:00 2001
From: wxf 
Date: Thu, 17 Sep 2020 19:20:31 +0800
Subject: [PATCH] avformat/img2enc: add strftime_mkdir option to automatically
 create time-based directories

Signed-off-by: wxf 
---
 libavformat/img2enc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index b303d38239..10ffb227a9 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -42,6 +42,7 @@ typedef struct VideoMuxData {
 char target[4][1024];
 int update;
 int use_strftime;
+int use_strftime_mkdir;
 int frame_pts;
 const char *muxer;
 int use_rename;
@@ -147,6 +148,19 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
 av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n");
 return AVERROR(EINVAL);
 }
+if (img->use_strftime_mkdir) {
+const char *dir;
+char *fn_copy = av_strdup(filename);
+if (!fn_copy)
+return AVERROR(ENOMEM);
+dir = av_dirname(fn_copy);
+if (ff_mkdir_p(dir) == -1 && errno != EEXIST) {
+av_log(s, AV_LOG_ERROR, "Could not create directory %s with use_strftime_mkdir\n", dir);
+av_freep(_copy);
+return AVERROR(errno);
+}
+av_freep(_copy);
+}
 } else if (img->frame_pts) {
 if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
 av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames.");
@@ -243,6 +257,7 @@ static const AVOption muxoptions[] = {
 { "update",   "continuously overwrite one file", OFFSET(update),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0,   1, ENC },
 { "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT,  { .i64 = 1 }, 0, INT_MAX, ENC },
 { "strftime", "use strftime for filename", OFFSET(use_strftime),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
+{ "strftime_mkdir", "create last directory component in strftime-generated filename", OFFSET(use_strftime_mkdir),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
 { "frame_pts","use current frame pts for filename", OFFSET(frame_pts),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
 { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
 { "protocol_opts", "specify protocol options for the opened files", OFFSET(protocol_opts), AV_OPT_TYPE_DICT, {0}, 0, 0, ENC },
-- 
2.18.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] ffmpeg: break loop when dts_heuristic check done

2018-09-30 Thread xiaofeng
Signed-off-by: xiaofeng 

--
From 8fd783a0a4e7803e202624ae04e0a38ba18124e3 Mon Sep 17 00:00:00 2001
From: xiaofeng 
Date: Sun, 30 Sep 2018 20:16:22 +0800
Subject: [PATCH] ffmpeg: break loop when dts_heuristic check done

---
 fftools/ffmpeg_opt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index c44ed63730..d4851a2cd8 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1149,8 +1149,10 @@ static int open_input_file(OptionsContext *o, const char *filename)
 int dts_heuristic = 0;
 for (i=0; inb_streams; i++) {
 const AVCodecParameters *par = ic->streams[i]->codecpar;
-if (par->video_delay)
+if (par->video_delay) {
 dts_heuristic = 1;
+break;
+}
 }
 if (dts_heuristic) {
 seek_timestamp -= 3*AV_TIME_BASE / 23;
-- 
2.16.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel