{"id":8625,"date":"2023-01-29T12:17:43","date_gmt":"2023-01-29T04:17:43","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=8625"},"modified":"2024-05-05T23:08:03","modified_gmt":"2024-05-05T15:08:03","slug":"%e4%bd%bf%e7%94%a8-ffmpeg-%e5%b0%86%e5%9b%be%e7%89%87%e8%a7%86%e9%a2%91%e7%94%9f%e6%88%90-gif-%e5%8a%a8%e5%9b%be","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=8625","title":{"rendered":"\u4f7f\u7528 FFmpeg \u5c06\u56fe\u7247\u89c6\u9891\u751f\u6210 GIF \u52a8\u56fe"},"content":{"rendered":"<p>\u914d\u7f6e FFmpeg \u73af\u5883\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=8613\">https:\/\/blog.iyatt.com\/?p=8613<\/a><\/p>\n<p>\u547d\u4ee4\u683c\u5f0f<\/p>\n<pre><code class=\"language-bash\">ffmpeg [\u53c2\u6570] [\u52a8\u56fe\u6587\u4ef6\u540d.gif]<\/code><\/pre>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u89c6\u9891\u6587\u4ef6\u540d\u4e3a: video.mp4\uff0c\u52a8\u56fe\u6587\u4ef6\u540d\u8bbe\u4e3a\uff1apic.gif<br \/>\n\u6700\u7b80\u5355\u7684\u4f7f\u7528\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">ffmpeg -i video.mp4 pic.gif<\/code><\/pre>\n<p>\u6765\u6e90\u4e0d\u662f\u89c6\u9891\u800c\u662f\u56fe\u7247\u7684\u8bdd\uff0c\u9700\u8981\u5c06\u89c6\u9891\u6309\u6570\u5b57\u7f16\u53f7\u8fde\u8d77\u6765\uff08\u6570\u5b57\u5fc5\u987b\u8fde\u7eed\uff09\uff0c\u6bd4\u5982<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674965203611.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 888px; --smush-placeholder-aspect-ratio: 888\/404;\" \/><br \/>\n\u90a3\u4e48<\/p>\n<pre><code class=\"language-bash\"># \u56fe\u7247\u751f\u6210\u52a8\u56fe\nffmpeg -i %d.png pic.gif\n\n# \u56fe\u7247\u751f\u6210 mp4 \u89c6\u9891\nffmpeg -i %d.png pic.mp4<\/code><\/pre>\n<p>\u5f53\u7136\u6587\u4ef6\u540d\u4e5f\u4e0d\u4e00\u5b9a\u8981\u7eaf\u6570\u5b57\uff0c\u6bd4\u5982\u53ef\u4ee5 aa1.png\uff0caa2.png\uff0caa3.png\uff0c\u5339\u914d\u7684\u65f6\u5019\u5c31\u7528 aa%d.png<\/p>\n<p>\u5176\u5b83\u90e8\u5206\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>-ss xx:xx:xx\uff0c\u4ece\u6307\u5b9a\u7684 xx:xx:xx \u65f6\u95f4\u5f00\u59cb\u751f\u6210<\/li>\n<li>-t xx \u4ece\u5f00\u5934\u6301\u7eed xx \u79d2\u7684\u89c6\u9891\u7528\u4e8e\u751f\u6210\u52a8\u56fe<\/li>\n<li>-to \u6307\u5b9a\u7ed3\u675f\u65f6\u95f4<\/li>\n<li>-s AAxBB \u751f\u6210\u7684\u52a8\u56fe\u5206\u8fa8\u7387\u4e3a AAxBB<\/li>\n<li>-vf scale=xxx:-1 \u7b49\u6bd4\u4f8b\u8c03\u6574\u5206\u8fa8\u7387\uff0c\u8fd9\u91cc xxx \u6307\u5b9a\u6a2a\u5411\uff0c\u90a3\u4e48\u7ad6\u76f4\u65b9\u5411\u5c31\u662f\u8ddf\u968f\u7b49\u6bd4\u4f8b\u8c03\u6574\uff0c\u53cd\u8fc7\u6765\u4e00\u6837<\/li>\n<li>-r xx \u751f\u6210\u52a8\u56fe\u7684\u5e27\u7387\uff0c\u6bcf\u79d2\u64ad\u653e\u7684\u56fe\u7247\u6570<\/li>\n<li>-b:v xx \u8c03\u6574\u7801\u7387\u4f1a\u5f71\u54cd\u6e05\u6670\u5ea6,\u6bd4\u5982 xx \u8bbe\u4e3a 1M\uff0c\u5373\u6bcf\u79d2\u949f\u64ad\u653e\u7684\u6570\u636e\u91cf\u4e3a 1M\uff0cxx \u8bbe\u4e3a 500k\uff0c\u5373\u6bcf\u79d2 500KB<\/li>\n<li>-threads xx \u6267\u884c\u7684\u7ebf\u7a0b\u6570<\/li>\n<li>-crf xx \u5e73\u8861\u89c6\u9891\u8d28\u91cf\u548c\u6587\u4ef6\u5927\u5c0f\uff0c\u53d6\u503c 0~51\uff0c\u8d8a\u5927\u89c6\u9891\u8d28\u91cf\u8d8a\u5dee\uff0c\u5efa\u8bae\u53d6\u503c 17~28\uff0c\u9ed8\u8ba4\u4e3a 23<\/li>\n<li>-c:v xx \u7f16\u7801\u683c\u5f0f\uff0cffmpeg \u5bf9 mp4 \u9ed8\u8ba4\u4f7f\u7528 H264\uff08<code>libx264<\/code>\uff09\uff0c\u53ef\u4ee5\u6307\u5b9a <code>libx265<\/code>\uff0c\u751f\u6210\u540c\u7b49\u8d28\u91cf\u6587\u4ef6\u66f4\u5c0f\u7684 H265\uff0cv8 \u548c v9 \u7684 webm \u6587\u4ef6\u7684\u8bdd\uff0c\u5206\u522b\u6307\u5b9a <code>libvpx<\/code> \u548c <code>libvpx-vp9<\/code>\uff0c\u6307\u5b9a <code>copy<\/code> \u5219\u4fdd\u6301\u7f16\u7801\uff0c\u53ea\u662f\u590d\u5236\uff0c\u4e00\u822c\u5728\u622a\u53d6\u7247\u6bb5\u7684\u65f6\u5019\u4f7f\u7528<\/li>\n<li>-vf &quot;transpose=XXX&quot; 0:\u9006\u65f6\u9488\u65cb\u8f6c90\u5ea6\u5e76\u5782\u76f4\u7ffb\u8f6c\uff1b1:\u987a\u65f6\u9488\u65cb\u8f6c90\u5ea6\uff1b2:\u9006\u65f6\u9488\u65cb\u8f6c90\u5ea6\uff1b3:\u987a\u65f6\u9488\u65cb\u8f6c90\u5ea6\u540e\u5e76\u5782\u76f4\u7ffb\u8f6c<\/li>\n<\/ul>\n<p>\u6211\u4e00\u822c\u7528\u52a8\u56fe\u5c55\u793a\u64cd\u4f5c\u6b65\u9aa4\uff0c\u5f55\u5c4f\u751f\u6210\u89c6\u9891\u6587\u4ef6\u6bd4\u8f83\u5927\u7684\uff08\u65f6\u95f4\u957f\u548c\u5f55\u5236\u5c4f\u5e55\u8303\u56f4\u5927\uff09\u5c31\u622a\u56fe\u518d\u751f\u6210\u52a8\u56fe\uff0c\u89c6\u9891\u5c0f\u7684\u5c31\u76f4\u63a5\u751f\u6210\u52a8\u56fe\u3002<br \/>\n\u5176\u4e2d\u7528\u56fe\u7247\u751f\u6210\u52a8\u56fe\u7684\u65f6\u5019\u6ce8\u610f\u8bbe\u7f6e\u5e27\u7387\uff0c\u4e0d\u7136\u6309\u89c6\u9891\u7684\u5e27\u7387\u4f1a\u4e00\u95ea\u800c\u8fc7\uff0c\u6bd4\u5982\u5e27\u7387\u8bbe\u4e3a 1\uff0c\u5373\u6bcf\u79d2\u949f\u64ad\u653e\u4e00\u5f20\u56fe\u7247\u3002<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/pic.gif\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 764px; --smush-placeholder-aspect-ratio: 764\/501;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u914d\u7f6e FFmpeg \u73af\u5883\uff1ahttps:\/\/blog.iyatt.com\/?p=8613 \u547d\u4ee4\u683c\u5f0f ffmpeg [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,609],"tags":[],"class_list":["post-8625","post","type-post","status-publish","format-standard","hentry","category-all","category-ffmpeg"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8625"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8625\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}