原本只能輸出成 %4d.mp4 ==> 0000.mp4, 0001.mp4
要改成可以像行車紀錄器般的檔案格式 201405020248.mp4
增加 %t 的參數
ffmpeg -i input -f segment -segment_time 60 -reset_timestamps 1 %t.mp4
這邊將 %t.mp4 定義成 Webcam年日月/E年日月時分秒.mp4
strftime(buf1, sizeof(buf1), “WebCam%Y%m%d/E%Y%m%d%H%M%S”, localtime(&tv.tv_sec));
修改方式如下:
修改 ffmpeg source / libavformat / utils.c 檔案
增加引用 #include <sys/time.h>
尋找 av_get_frame_filename function
替換成下面這一個
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) { const char *p; char *q, buf1[50], c; int nd, len, percentd_found, percentt_found; struct timeval tv; q = buf; p = path; percentd_found = 0; percentt_found = 0; for (;;) { c = *p++; if (c == ' ') break; if (c == '%') { do { nd = 0; while (av_isdigit(*p)) nd = nd * 10 + *p++ - '0'; c = *p++; } while (av_isdigit(c)); switch (c) { case '%': goto addchar; case 'd': if (percentd_found) goto fail; percentd_found = 1; snprintf(buf1, sizeof(buf1), "%0*d", nd, number); len = strlen(buf1); if ((q - buf + len) > buf_size - 1) goto fail; memcpy(q, buf1, len); q += len; break; case 't': if (percentt_found) goto fail; percentt_found = 1; gettimeofday(&tv, NULL); //strftime(buf1, sizeof(buf1), "%Y-%m-%d_%H-%M-%S", localtime(&tv.tv_sec)); // strftime(buf1, sizeof(buf1), "WebCam%Y%m%d/E%Y%m%d%H%M%S", localtime(&tv.tv_sec)); len = strlen(buf1); if ((q - buf + len) > buf_size - 1) goto fail; memcpy(q, buf1, len); q += len; break; default: goto fail; } } else { addchar: if ((q - buf) < buf_size - 1) *q++ = c; } } if (!percentd_found && !percentt_found) goto fail; *q = ' '; return 0; fail: *q = ' '; return -1; } |