Commit f3e34072 authored by Steven Liu's avatar Steven Liu

avformat/img2enc: add frame_pts option for make output filename

fix ticket id: #1452
when use frame_pts option, the output image name can be set with PTS
of current frame.
Signed-off-by: 's avatarSteven Liu <lq@onvideo.cn>
parent 3ee63f3f
...@@ -897,9 +897,18 @@ can be used: ...@@ -897,9 +897,18 @@ can be used:
ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg" ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg"
@end example @end example
You can set the file name with current frame's PTS:
@example
ffmpeg -f v4l2 -r 1 -i /dev/video0 -copyts -f image2 -frame_pts true %d.jpg"
@end example
@subsection Options @subsection Options
@table @option @table @option
@item frame_pts
If set to 1, expand the filename with pts from pkt->pts.
Default value is 0.
@item start_number @item start_number
Start the sequence from the specified number. Default value is 1. Start the sequence from the specified number. Default value is 1.
......
...@@ -42,6 +42,7 @@ typedef struct VideoMuxData { ...@@ -42,6 +42,7 @@ typedef struct VideoMuxData {
char target[4][1024]; char target[4][1024];
int update; int update;
int use_strftime; int use_strftime;
int frame_pts;
const char *muxer; const char *muxer;
int use_rename; int use_rename;
} VideoMuxData; } VideoMuxData;
...@@ -99,6 +100,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -99,6 +100,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n"); av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
} 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.");
return AVERROR(EINVAL);
}
} else if (av_get_frame_filename2(filename, sizeof(filename), img->path, } else if (av_get_frame_filename2(filename, sizeof(filename), img->path,
img->img_number, img->img_number,
AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 && AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
...@@ -206,6 +212,7 @@ static const AVOption muxoptions[] = { ...@@ -206,6 +212,7 @@ static const AVOption muxoptions[] = {
{ "update", "continuously overwrite one file", OFFSET(update), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "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 }, { "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", "use strftime for filename", OFFSET(use_strftime), 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 }, { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
{ NULL }, { NULL },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment