{"id":966,"date":"2014-05-02T02:51:24","date_gmt":"2014-05-01T18:51:24","guid":{"rendered":"https:\/\/cowman-chiang.no-ip.org\/wordpress\/?p=966"},"modified":"2019-06-20T10:25:07","modified_gmt":"2019-06-20T02:25:07","slug":"ffmpeg%ef%bc%9asegment-fromat-add-timestamp-into-filename-option","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=966","title":{"rendered":"FFMPEG\uff1asegment fromat add timestamp into filename option"},"content":{"rendered":"<p>\u539f\u672c\u53ea\u80fd\u8f38\u51fa\u6210 %4d.mp4 ==&gt; 0000.mp4, 0001.mp4<br \/>\n\u8981\u6539\u6210\u53ef\u4ee5\u50cf\u884c\u8eca\u7d00\u9304\u5668\u822c\u7684\u6a94\u6848\u683c\u5f0f 201405020248.mp4<\/p>\n<p>\u589e\u52a0 %t \u7684\u53c3\u6578<br \/>\nffmpeg -i input -f segment -segment_time 60 -reset_timestamps 1 %t.mp4<\/p>\n<p>\u9019\u908a\u5c07 %t.mp4 \u5b9a\u7fa9\u6210 Webcam\u5e74\u65e5\u6708\/E\u5e74\u65e5\u6708\u6642\u5206\u79d2.mp4<br \/>\nstrftime(buf1, sizeof(buf1), &#8220;WebCam%Y%m%d\/E%Y%m%d%H%M%S&#8221;, localtime(&amp;tv.tv_sec));<\/p>\n<p>\u4fee\u6539\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>\u4fee\u6539 ffmpeg source \/ libavformat \/ utils.c \u6a94\u6848<br \/>\n\u589e\u52a0\u5f15\u7528 <span style=\"color: #0000ff;\">#include &lt;sys\/time.h&gt;<\/span><\/p>\n<p>\u5c0b\u627e av_get_frame_filename function<br \/>\n\u66ff\u63db\u6210\u4e0b\u9762\u9019\u4e00\u500b<\/p>\n<pre lang=\"bash\">int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)\n{\n    const char *p;\n    char *q, buf1[50], c;\n    int nd, len, percentd_found, percentt_found;\n    struct timeval tv;\n\n    q = buf;\n    p = path;\n    percentd_found = 0;\n    percentt_found = 0;\n    for (;;) {\n        c = *p++;\n        if (c == '\u0000')\n            break;\n        if (c == '%') {\n            do {\n                nd = 0;\n                while (av_isdigit(*p))\n                    nd = nd * 10 + *p++ - '0';\n                c = *p++;\n            } while (av_isdigit(c));\n\n            switch (c) {\n            case '%':\n                goto addchar;\n            case 'd':\n                if (percentd_found)\n                    goto fail;\n                percentd_found = 1;\n                snprintf(buf1, sizeof(buf1), \"%0*d\", nd, number);\n                len = strlen(buf1);\n                if ((q - buf + len) &gt; buf_size - 1)\n                    goto fail;\n                memcpy(q, buf1, len);\n                q += len;\n                break;\n            case 't':\n                if (percentt_found)\n                    goto fail;\n                percentt_found = 1;\n\n                gettimeofday(&amp;tv, NULL);\n                \/\/strftime(buf1, sizeof(buf1), \"%Y-%m-%d_%H-%M-%S\", localtime(&amp;tv.tv_sec));\n                \/\/\n                strftime(buf1, sizeof(buf1), \"WebCam%Y%m%d\/E%Y%m%d%H%M%S\", localtime(&amp;tv.tv_sec));\n                len = strlen(buf1);\n                if ((q - buf + len) &gt; buf_size - 1)\n                    goto fail;\n                memcpy(q, buf1, len);\n                q += len;\n                break;\n            default:\n                goto fail;\n            }\n        } else {\n        addchar:\n            if ((q - buf) &lt; buf_size - 1)\n                *q++ = c;\n        }\n    }\n    if (!percentd_found &amp;&amp; !percentt_found)\n        goto fail;\n    *q = '\u0000';\n    return 0;\nfail:\n    *q = '\u0000';\n    return -1;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u672c\u53ea\u80fd\u8f38\u51fa\u6210 %4d.mp4 ==&gt; 0000.mp4, 0001.mp4 \u8981\u6539\u6210\u53ef\u4ee5\u50cf\u884c\u8eca\u7d00\u9304\u5668\u822c\u7684\u6a94\u6848\u683c\u5f0f 201405020248.mp4 \u589e\u52a0 %t \u7684\u53c3\u6578 ffmpeg -i input -f segment -segment_time 60 -reset_timestamps 1 %t.mp4 \u9019\u908a\u5c07 %t.mp4 \u5b9a\u7fa9\u6210 Webcam\u5e74\u65e5\u6708\/E\u5e74\u65e5\u6708\u6642\u5206\u79d2.mp4 strftime(buf1, sizeof(buf1), &#8220;WebCam%Y%m%d\/E%Y%m%d%H%M%S&#8221;, localtime(&amp;tv.tv_sec)); \u4fee\u6539\u65b9\u5f0f\u5982\u4e0b\uff1a \u4fee\u6539 ffmpeg source \/ libavformat \/ utils.c \u6a94\u6848 \u589e\u52a0\u5f15\u7528 #include &lt;sys\/time.h&gt; &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=966\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-966","post","type-post","status-publish","format-standard","hentry","category-ffmpeg"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=966"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":2049,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/966\/revisions\/2049"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}