fix ticket id: #1452
when use frame_pts option, the output image name can be set with PTS
of current frame.
Signed-off-by: Steven Liu <lq@onvideo.cn>
... | ... |
@@ -897,9 +897,18 @@ can be used: |
897 | 897 |
ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg" |
898 | 898 |
@end example |
899 | 899 |
|
900 |
+You can set the file name with current frame's PTS: |
|
901 |
+@example |
|
902 |
+ffmpeg -f v4l2 -r 1 -i /dev/video0 -copyts -f image2 -frame_pts true %d.jpg" |
|
903 |
+@end example |
|
904 |
+ |
|
900 | 905 |
@subsection Options |
901 | 906 |
|
902 | 907 |
@table @option |
908 |
+@item frame_pts |
|
909 |
+If set to 1, expand the filename with pts from pkt->pts. |
|
910 |
+Default value is 0. |
|
911 |
+ |
|
903 | 912 |
@item start_number |
904 | 913 |
Start the sequence from the specified number. Default value is 1. |
905 | 914 |
|
... | ... |
@@ -42,6 +42,7 @@ typedef struct VideoMuxData { |
42 | 42 |
char target[4][1024]; |
43 | 43 |
int update; |
44 | 44 |
int use_strftime; |
45 |
+ int frame_pts; |
|
45 | 46 |
const char *muxer; |
46 | 47 |
int use_rename; |
47 | 48 |
} VideoMuxData; |
... | ... |
@@ -99,6 +100,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) |
99 | 99 |
av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n"); |
100 | 100 |
return AVERROR(EINVAL); |
101 | 101 |
} |
102 |
+ } else if (img->frame_pts) { |
|
103 |
+ if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) { |
|
104 |
+ av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames."); |
|
105 |
+ return AVERROR(EINVAL); |
|
106 |
+ } |
|
102 | 107 |
} else if (av_get_frame_filename2(filename, sizeof(filename), img->path, |
103 | 108 |
img->img_number, |
104 | 109 |
AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 && |
... | ... |
@@ -206,6 +212,7 @@ static const AVOption muxoptions[] = { |
206 | 206 |
{ "update", "continuously overwrite one file", OFFSET(update), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, |
207 | 207 |
{ "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC }, |
208 | 208 |
{ "strftime", "use strftime for filename", OFFSET(use_strftime), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, |
209 |
+ { "frame_pts", "use current frame pts for filename", OFFSET(frame_pts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, |
|
209 | 210 |
{ "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, |
210 | 211 |
{ NULL }, |
211 | 212 |
}; |