{"id":13935,"date":"2024-02-19T11:17:04","date_gmt":"2024-02-19T03:17:04","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=13935"},"modified":"2024-05-05T23:07:38","modified_gmt":"2024-05-05T15:07:38","slug":"ffmpeg-%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%88%e7%bc%96%e8%be%91%e4%b8%ad%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=13935","title":{"rendered":"FFmpeg \u5f00\u53d1 &#8211; \u5b66\u4e60\u8bb0\u5f55\uff08\u7f16\u8f91\u4e2d\uff09"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#1_%E5%89%8D%E8%A8%80\" >1 \u524d\u8a00<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#2_%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\" >2 \u6d4b\u8bd5\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#3_%E9%85%8D%E7%BD%AE%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83\" >3 \u914d\u7f6e\u5f00\u53d1\u73af\u5883<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#31_%E5%88%9B%E5%BB%BA_Visual_Studio_%E9%A1%B9%E7%9B%AE%E6%BC%94%E7%A4%BA\" >3.1 \u521b\u5efa Visual Studio \u9879\u76ee\u6f14\u793a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#32_%E5%88%9B%E5%BB%BA_CMake_%E9%A1%B9%E7%9B%AE%E6%BC%94%E7%A4%BA%EF%BC%88Visual_Studio_%E6%88%96_Visual_Studio_Code%EF%BC%89\" >3.2 \u521b\u5efa CMake \u9879\u76ee\u6f14\u793a\uff08Visual Studio \u6216 Visual Studio Code\uff09<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#4_%E4%B8%80%E4%BA%9B%E5%8F%AF%E8%83%BD%E7%94%A8%E5%88%B0%E7%9A%84\" >4 \u4e00\u4e9b\u53ef\u80fd\u7528\u5230\u7684<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#41_VS_%E7%A6%81%E6%AD%A2%E5%AE%89%E5%85%A8%E6%A3%80%E6%9F%A5\" >4.1 VS \u7981\u6b62\u5b89\u5168\u68c0\u67e5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#42_%E6%96%87%E4%BB%B6%E9%80%89%E6%8B%A9\" >4.2 \u6587\u4ef6\u9009\u62e9<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#5_FFmpeg_%E5%AE%98%E6%96%B9%E5%8F%82%E8%80%83%E6%A1%88%E4%BE%8B\" >5 FFmpeg \u5b98\u65b9\u53c2\u8003\u6848\u4f8b<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.iyatt.com\/?p=13935\/#51_%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F%E8%BD%AC%E6%8D%A2\" >5.1 \u89c6\u9891\u683c\u5f0f\u8f6c\u6362<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1_%E5%89%8D%E8%A8%80\"><\/span>1 \u524d\u8a00<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u4ee5\u524d\u53ea\u662f\u5355\u7eaf\u62ff FFmpeg \u547d\u4ee4\u884c\u5de5\u5177\u6765\u7f16\u7801\u89c6\u9891\uff08\u56fe\u7247\u5408\u6210\u89c6\u9891\u3001\u89c6\u9891\u683c\u5f0f\u8f6c\u6362\u3001\u7f16\u7801\u5668\u8f6c\u6362\uff09\uff0c\u5e76\u6ca1\u6709\u6df1\u5165\u5b66\u4e60\u8fc7\uff0c\u8fd9\u6b21\u6253\u7b97\u5c1d\u8bd5\u4e00\u4e0b\u4f7f\u7528 FFmpeg \u7684\u5e93\u641e\u641e\u5f00\u53d1\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"2_%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\"><\/span>2 \u6d4b\u8bd5\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>\n<p>Intel i7-12700H\uff08Iris Xe Graphics\uff09<\/p>\n<\/li>\n<li>\n<p>NVIDIA RTX4060 Laptop GPU<\/p>\n<\/li>\n<li>\n<p>Windows 11 \u4e13\u4e1a\u7248 23H2<\/p>\n<\/li>\n<li>\n<p>ffmpeg-master-latest-win64-gpl-shared \u2013 Auto-Build (2024-02-18 12:47)\uff1a<a href=\"https:\/\/github.com\/BtbN\/FFmpeg-Builds\/releases\">https:\/\/github.com\/BtbN\/FFmpeg-Builds\/releases<\/a><\/p>\n<\/li>\n<li>\n<p>Visual Studio 2022\uff08\u6307\u5b9a C17 \u6807\u51c6\u7f16\u8bd1\u6d4b\u8bd5\uff09<\/p>\n<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"3_%E9%85%8D%E7%BD%AE%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83\"><\/span>3 \u914d\u7f6e\u5f00\u53d1\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u7eaf\u914d\u7f6e\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=8613\">https:\/\/blog.iyatt.com\/?p=8613<\/a><br \/>\n\u8fd9\u91cc\u8981\u505a\u5f00\u53d1\uff0c\u4e0b\u8f7d\u7684\u65f6\u5019\u9009\u52a8\u6001\u5e93\u7248\u672c\uff0c\u91cc\u9762\u4e5f\u5305\u542b\u4e86\u547d\u4ee4\u884c\u5de5\u5177<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708328514668.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 463px; --smush-placeholder-aspect-ratio: 463\/277;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708328575328.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 549px; --smush-placeholder-aspect-ratio: 549\/299;\" \/><\/p>\n<p><strong>bin<\/strong> \u76ee\u5f55\u4e2d\u7684\u662f\u547d\u4ee4\u884c\u5de5\u5177\uff08\u53ef\u6267\u884c\u6587\u4ef6\uff09\uff0c\u6dfb\u52a0\u5230 PATH \u73af\u5883\u53d8\u91cf\uff0c\u5c31\u80fd\u5728\u7ec8\u7aef\u76f4\u63a5\u6267\u884c\u3002FFmpeg \u662f C \u8bed\u8a00\u5f00\u53d1\u7684\uff0cinclude \u4e2d\u662f\u5934\u6587\u4ef6\uff0clib \u76ee\u5f55\u4e2d\u7684 lib \u6587\u4ef6\u76f8\u5f53\u4e8e\u52a8\u6001\u5e93\u7684\u7d22\u5f15\uff0c<strong>bin<\/strong> \u76ee\u5f55\u4e2d\u7684 dll \u6587\u4ef6\u662f\u52a8\u6001\u5e93\u7684\u5b9e\u73b0\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708328910538.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 568px; --smush-placeholder-aspect-ratio: 568\/479;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708328923838.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 543px; --smush-placeholder-aspect-ratio: 543\/473;\" \/><\/p>\n<p>\u73b0\u5728\u9009\u4e00\u4e2a\u8def\u5f84\u521b\u5efa\u9879\u76ee\u76ee\u5f55\uff0c\u6211\u5728\u684c\u9762\u521b\u5efa\u4e86\u4e00\u4e2a FFmpeg \u76ee\u5f55\u3002\u5c06\u4e0a\u9762\u7684 <strong>include<\/strong> \u548c <strong>lib<\/strong> \u4e24\u4e2a\u76ee\u5f55\u590d\u5236\u5230\u521b\u5efa\u7684\u76ee\u5f55\u4e2d\uff0c\u53e6\u5916\u5c06\u4e0a\u9762\u7684 <strong>bin<\/strong> \u76ee\u5f55\u4e2d\u7684 <strong>.dll<\/strong> \u6587\u4ef6\u4e5f\u590d\u5236\u5230\u9879\u76ee\u76ee\u5f55\u7684 <strong>lib<\/strong> \u76ee\u5f55\u4e2d\u3002\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u518d\u521b\u5efa\u4e00\u4e2a <strong>src<\/strong> \u76ee\u5f55\uff0c\u7528\u4e8e\u5b58\u653e\u81ea\u5df1\u7f16\u5199\u7684\u4ee3\u7801\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708329153948.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 501px; --smush-placeholder-aspect-ratio: 501\/258;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708329277324.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 764px; --smush-placeholder-aspect-ratio: 764\/523;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708329294486.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 970px; --smush-placeholder-aspect-ratio: 970\/396;\" \/><\/p>\n<hr \/>\n<p>Visual Studio \u4e2d\u8bb0\u5f97\u52fe\u9009\u5b89\u88c5 C++ \u5f00\u53d1\uff0c\u8fd9\u91cc\u9762\u5305\u542b C\/C++ \u5f00\u53d1\u7684\u5de5\u5177\u94fe<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708329391144.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 459px; --smush-placeholder-aspect-ratio: 459\/152;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"31_%E5%88%9B%E5%BB%BA_Visual_Studio_%E9%A1%B9%E7%9B%AE%E6%BC%94%E7%A4%BA\"><\/span>3.1 \u521b\u5efa Visual Studio \u9879\u76ee\u6f14\u793a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>\u521b\u5efa\u9879\u76ee\u6f14\u793a<\/strong><\/p>\n<p>\u6253\u5f00 VS \u521b\u5efa\u4e00\u4e2a\u7a7a\u9879\u76ee<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708332566733.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 388px; --smush-placeholder-aspect-ratio: 388\/407;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708332575644.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 574px; --smush-placeholder-aspect-ratio: 574\/311;\" \/><\/p>\n<p>\u8def\u5f84\u9009\u5728\u521b\u5efa\u7684 <strong>src<\/strong> \u76ee\u5f55<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708332617758.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 532px; --smush-placeholder-aspect-ratio: 532\/332;\" \/><\/p>\n<p>\u65b0\u5efa\u6e90\u7801<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708332672704.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 676px; --smush-placeholder-aspect-ratio: 676\/441;\" \/><\/p>\n<p>\u6587\u4ef6\u547d\u540d\u65f6\u6ce8\u610f\u6269\u5c55\u540d\u5199 <strong>.c<\/strong>\uff0cVisual Studio \u9ed8\u8ba4\u7ed9\u7684\u6269\u5c55\u540d\u662f <strong>.cpp<\/strong>\uff08C++\uff0cC Plus Plus\uff09\u3002\u8c28\u8bb0 C \u8bed\u8a00\u548c C++ \u662f\u4e24\u95e8\u8bed\u8a00\uff0c\u53ea\u662f C++ \u57fa\u672c\u517c\u5bb9\u4e86 C \u8bed\u8a00\u7684\u8bed\u6cd5\uff0c\u4f46\u662f\u4e24\u8005\u5728\u7f16\u8bd1\u5668\u5904\u7406\u4e0a\u5f88\u5927\u4e0d\u540c\uff0c\u5355\u7eaf\u6e90\u7801\u517c\u5bb9\u6027\u8fd8\u9ad8\u4e00\u4e9b\uff0c\u8fd9\u91cc\u662f\u76f4\u63a5\u94fe\u63a5 FFmpeg \u7684 C \u8bed\u8a00\u5e93\u6587\u4ef6\uff08\u5df2\u7ecf\u6309\u7167 C \u8bed\u8a00\u7f16\u8bd1\uff09\uff0c\u6700\u660e\u663e\u7684\u4e00\u70b9\u5c31\u662f C++ \u4e3a\u4e86\u51fd\u6570\u91cd\u8f7d\uff0c\u5728\u7f16\u8bd1\u65f6\u4e3a\u4e86\u533a\u522b\u540c\u540d\u51fd\u6570\uff0c\u4f1a\u52a0\u4e0a\u53c2\u6570\u7c7b\u578b\u91cd\u547d\u540d\uff0c\u800c C \u8bed\u8a00\u6ca1\u6709\u8fd9\u4e2a\uff0c\u5728\u5df2\u7ecf\u7f16\u8bd1\u597d\u7684\u5e93\u6587\u4ef6\u4e2d\uff0cC++ \u5f15\u7528 C \u5e93\u5c31\u53ef\u80fd\u51fa\u73b0\u95ee\u9898\u3002\u4e00\u5b9a\u8981\u5728 C++ \u4e2d\u5f15\u7528 C \u7684\u8bdd\uff0c\u9700\u8981\u4f7f\u7528 <strong>extern \u201cC\u201d { }<\/strong> \u628a\u5f15\u7528 C \u5934\u6587\u4ef6\u90e8\u5206\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u3002\u8fd9\u6837\u7f16\u8bd1\u7684\u662f\u65f6\u5019\u5728\u62ec\u8d77\u6765\u7684\u90e8\u5206\u5c31\u4f1a\u81ea\u52a8\u8c03\u7528 C \u8bed\u8a00\u7f16\u8bd1\u5668\u6765\u7f16\u8bd1\uff0c\u5176\u5b83\u90e8\u5206\u6309\u7167 C++ \u7f16\u8bd1\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708332708556.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 379px; --smush-placeholder-aspect-ratio: 379\/130;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708426899715.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 284px; --smush-placeholder-aspect-ratio: 284\/82;\" \/><\/p>\n<p>\u7136\u540e\u5728\u9879\u76ee\u540d\u4e0a\u53f3\u952e-\u5c5e\u6027<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708333302910.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 365px; --smush-placeholder-aspect-ratio: 365\/829;\" \/><\/p>\n<p>\u6ce8\u610f\u5c5e\u6027\u9875\u4e0a\u65b9\u53ef\u9009\uff0c\u662f\u914d\u7f6e\u7ed9 Debug\uff08\u8c03\u8bd5\uff09\u8fd8\u662f Release\uff08\u53d1\u5e03\u7248\uff09\u6216\u8005\u6240\u7528\uff0c\u4ee5\u53ca 64 \u4f4d\u914d\u7f6e\u8fd8\u662f 32 \u4f4d\u914d\u7f6e\uff0c\u5bf9\u5e94\u7740\u7f16\u8bd1\u6a21\u5f0f\u3002<br \/>\n\u521d\u5b66\u9636\u6bb5\u4e5f\u4e0d\u6d89\u53ca\u53d1\u5e03\u81ea\u5df1\u7f16\u5199\u7684\u8f6f\u4ef6\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u4e0d\u4f1a\u9488\u5bf9\u4e0d\u540c\u7248\u672c\u914d\u7f6e\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u8fd9\u4e2a\u5176\u5b9e\u65e0\u6240\u8c13\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708336147492.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 653px; --smush-placeholder-aspect-ratio: 653\/73;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708336246228.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 369px; --smush-placeholder-aspect-ratio: 369\/145;\" \/><\/p>\n<p>\u5728 C\/C++ -&gt; \u5e38\u89c4 -&gt; \u9644\u52a0\u5305\u76ee\u5f55 \u4e2d\u6dfb\u52a0\u4e0a <strong>include<\/strong> \u7684\u8def\u5f84\uff08\u4e24\u4e2a\u82f1\u6587\u53e5\u70b9\u4ee3\u8868\u4e0a\u7ea7\u76ee\u5f55\uff09<br \/>\n\u6839\u636e\u81ea\u5df1\u7684\u9879\u76ee\u76ee\u5f55\u6765\uff0c\u6309\u7167\u6211\u8fd9\u91cc\u7684\u9879\u76ee\u7ed3\u6784\uff0c\u5728\u4e09\u4e2a\u4e0a\u7ea7\u76ee\u5f55\u4ee5\u4e0a\u624d\u662f <strong>include<\/strong><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708333402068.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 661px; --smush-placeholder-aspect-ratio: 661\/323;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708333374897.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 594px; --smush-placeholder-aspect-ratio: 594\/333;\" \/><\/p>\n<p>\u540c\u6837\u7684\u5728 \u94fe\u63a5\u5668 -&gt; \u5e38\u89c4 -&gt; \u9644\u52a0\u5e93\u76ee\u5f55 \u5199\u5165 <strong>lib<\/strong> \u8def\u5f84<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708333594678.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 585px; --smush-placeholder-aspect-ratio: 585\/186;\" \/><\/p>\n<p>\u5728 \u94fe\u63a5\u5668 -&gt; \u8f93\u5165 -&gt; \u9644\u52a0\u4f9d\u8d56\u9879 \u4e2d\u6dfb\u52a0\u4e0a\u9700\u8981\u4f7f\u7528\u7684\u5e93\u7684 lib \u6587\u4ef6<\/p>\n<p>\u4e0b\u9762\u7684\u6d4b\u8bd5\u6848\u4f8b\u4e2d\u9700\u8981\u7684\u5e93\u6587\u4ef6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708401902619.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 755px; --smush-placeholder-aspect-ratio: 755\/290;\" \/><\/p>\n<p>\u4e5f\u53ef\u4ee5\u4e0d\u5728\u5c5e\u6027\u91cc\u914d\u7f6e lib \u6587\u4ef6\uff0c\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5f15\u7528\u5934\u6587\u4ef6\u540e\u52a0\u4e0a\u5bf9\u5e94\u7684\u8bed\u53e5\uff0c\u6bd4\u5982\u8fd9\u91cc\u7684<\/p>\n<pre><code class=\"language-c\">#pragma comment(lib, &quot;avutil.lib&quot;)<\/code><\/pre>\n<p>\u5199\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u6d4b\u8bd5<br \/>\n\u5728\u524d\u9762\u65b0\u5efa\u7684 .c \u6587\u4ef6\u5199\u5165\u4e0b\u9762\u5185\u5bb9<\/p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\n#include &lt;libavutil\/avutil.h&gt;\n\nint main()\n{\n    printf(&quot;%s\\n&quot;, av_version_info());\n}<\/code><\/pre>\n<p>\u8c03\u8bd5\u8fd0\u884c<br \/>\n\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u663e\u793a\u5f53\u524d FFmpeg \u5e93\u7684\u7248\u672c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708336578290.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 194px; --smush-placeholder-aspect-ratio: 194\/67;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708350543366.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 295px; --smush-placeholder-aspect-ratio: 295\/101;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"32_%E5%88%9B%E5%BB%BA_CMake_%E9%A1%B9%E7%9B%AE%E6%BC%94%E7%A4%BA%EF%BC%88Visual_Studio_%E6%88%96_Visual_Studio_Code%EF%BC%89\"><\/span>3.2 \u521b\u5efa CMake \u9879\u76ee\u6f14\u793a\uff08Visual Studio \u6216 Visual Studio Code\uff09<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>VS \u9ed8\u8ba4\u9879\u76ee\u7ba1\u7406\u662f\u81ea\u5df1\u7684\u65b9\u5f0f\uff0cVS \u4e5f\u662f\u652f\u6301 CMake \u7684\uff0c\u5728\u6dfb\u52a0 C++ \u5f00\u53d1\u5de5\u5177\u65f6\uff0c\u91cc\u9762\u9ed8\u8ba4\u5c31\u5305\u542b\u4e86 CMake\uff0c\u5373\u53ef\u4ee5\u91c7\u7528 VS + CMake + MSVC \u7684\u7ec4\u5408\uff0c\u628a VS \u6362\u6210 VScode \u4e5f\u884c\u3002\u4ee5\u524d\u5728 Linux \u4e0b\u641e\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u6211\u57fa\u672c\u5c31\u662f\u7528 CMake \u7ba1\u7406\u9879\u76ee\uff0c\u91c7\u7528 VScode + CMake + GNU \u7684\u642d\u914d\uff0c\u6240\u4ee5\u6211\u662f\u6bd4\u8f83\u503e\u5411\u4e8e\u4f7f\u7528 CMake\u3002VS \u9879\u76ee\u7ba1\u7406\u5c5e\u6027\u91cc\u7684\u90a3\u4e00\u5806\u4e1c\u897f\u5c31\u5168\u90e8\u5728 CMakeLists.txt \u91cc\u914d\u7f6e\u4e86\uff0c\u4e0b\u9762\u6211\u7ed9\u51fa\u4e86\u4e00\u4e2a\u53c2\u8003\u6a21\u677f\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708428462104.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 561px; --smush-placeholder-aspect-ratio: 561\/182;\" \/><\/p>\n<p>CMakeLists.txt \u6587\u4ef6\u53c2\u8003<\/p>\n<pre><code class=\"language-cmake\">cmake_minimum_required (VERSION 3.8) # CMake \u6700\u4f4e\u7248\u672c\u8981\u6c42\nproject(test) # \u9879\u76ee\u540d\u79f0\nset(CMAKE_C_STANDARD 17) # C \u8bed\u8a00\u7f16\u8bd1\u6807\u51c6\uff08C17\uff09\nset(exe_name test) # \u81ea\u5b9a\u4e49\u53d8\u91cf\uff0c\u7528\u4e8e\u7edf\u4e00\u8bbe\u5b9a\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\u5b57\uff0c\u8fd9\u91cc\u8bbe\u5b9a\u4e3a test\uff0c\u5c31\u4f1a\u751f\u6210 test.exe \u6587\u4ef6\n\ninclude_directories(${CMAKE_SOURCE_DIR}\/..\/..\/include\/) # \u5934\u6587\u4ef6\u8def\u5f84 - \u8def\u5f84\u6ce8\u610f\u7528\u659c\u6760\uff0c\u4e0b\u540c\n# link_directories(${CMAKE_SOURCE_DIR}\/..\/..\/lib\/) # \u94fe\u63a5\u5e93\u65b9\u5f0f\u4e00\u3002\u8fd9\u79cd\u65b9\u5f0f\u6307\u5b9a\u5e93\u76ee\u5f55\uff0c\u6e90\u7801\u4e2d\u9700\u8981\u4f7f\u7528 #pragma \u94fe\u63a5\n\nset(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}\/build\/) # \u6307\u5b9a\u751f\u6210\u6587\u4ef6\u8def\u5f84\nadd_compile_options(\/GS-) # \u8fd9\u91cc\u586b\u5199\u7684\u53c2\u6570\u4f1a\u4f20\u9012\u7ed9\u7f16\u8bd1\u5668\u3002\/CG- \u7981\u7528\u5b89\u5168\u68c0\u67e5\n\n# \u94fe\u63a5\u5e93\u65b9\u5f0f\u4e8c\n# \u4e09\u6bb5\u53c2\u6570\uff1a\n# ffmpeg \u662f\u4e2a\u53d8\u91cf\uff0c\u5b58\u653e\u627e\u5230\u7684\u5e93\n# \u8981\u5bfb\u627e\u7684\u5e93\u6587\u4ef6\n# \u67e5\u627e\u7684\u8def\u5f84\nfind_library(ffmpeg avutil.lib ${CMAKE_SOURCE_DIR}\/..\/..\/lib\/)\naux_source_directory(src ${CMAKE_SOURCE_DIR}\/) # \u81ea\u52a8\u5bfb\u627e\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6e90\u6587\u4ef6\u3002${CMAKE_SOURCE_DIR} \u53d8\u91cf\u5b58\u50a8\u7740\u4e3b\u811a\u672c\u6587\u4ef6CMakeLists.txt\u81ea\u5df1\u6240\u5728\u8def\u5f84\uff0c\u5373\u672c\u6587\u4ef6\u540c\u7ea7\u76ee\u5f55\u3002\nadd_executable(${exe_name} main.c) # \u7f16\u8bd1\u6e90\u6587\u4ef6\ntarget_link_libraries(${exe_name} ${ffmpeg}) # \u5c06\u4e0a\u9762\u627e\u5230\u7684\u5e93\u6587\u4ef6\u94fe\u63a5\u5230\u7f16\u8bd1\u597d\u7684\u76ee\u6807\u6587\u4ef6\u4e2d\n\n# \u94fe\u63a5\u5e93\u65b9\u5f0f\u4e09\uff1a\u624b\u52a8\u6307\u5b9a\u94fe\u63a5\uff0c\u8fd9\u91cc\u5217\u51fa\u4e86\u6240\u6709 FFmpeg \u5e93\u6587\u4ef6\n# set(FFmpeg_LIB_PATH ${CMAKE_SOURCE_DIR}\/..\/..\/lib\/)\n# target_link_libraries(${exe_name} \n#     ${FFmpeg_LIB_PATH}\/avcodec.lib\n#     ${FFmpeg_LIB_PATH}\/avdevice.lib\n#     ${FFmpeg_LIB_PATH}\/avfilter.lib\n#     ${FFmpeg_LIB_PATH}\/avformat.lib\n#     ${FFmpeg_LIB_PATH}\/avutil.lib\n#     ${FFmpeg_LIB_PATH}\/postproc.lib\n#     ${FFmpeg_LIB_PATH}\/swresample.lib\n#     ${FFmpeg_LIB_PATH}\/swscale.lib\n# )<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708406220590.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 205px; --smush-placeholder-aspect-ratio: 205\/101;\" \/><\/p>\n<h1><span class=\"ez-toc-section\" id=\"4_%E4%B8%80%E4%BA%9B%E5%8F%AF%E8%83%BD%E7%94%A8%E5%88%B0%E7%9A%84\"><\/span>4 \u4e00\u4e9b\u53ef\u80fd\u7528\u5230\u7684<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"41_VS_%E7%A6%81%E6%AD%A2%E5%AE%89%E5%85%A8%E6%A3%80%E6%9F%A5\"><\/span>4.1 VS \u7981\u6b62\u5b89\u5168\u68c0\u67e5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Visual Studio \u975e\u5e38\u8ba8\u538c\u7684\u4e00\u70b9\u5c31\u662f\u9ed8\u8ba4\u5f3a\u5236\u4f7f\u7528\u5b89\u5168\u51fd\u6570\uff0c\u800c\u5176\u5b83\u7f16\u8bd1\u5668\u81f3\u5c11\u6211\u8fd8\u6ca1\u89c1\u8fc7\u652f\u6301\u7684\u3002\u5b9e\u9645\u4e0a\u5b89\u5168\u51fd\u6570\u4e0d\u4f1a\u7528\uff0c\u4e00\u6837\u4e0d\u5b89\u5168\uff0c\u6807\u51c6\u51fd\u6570\u7528\u597d\u4e86\u4e00\u6837\u5b89\u5168\uff0c\u8fd9\u4e2a\u662f\u770b\u4f7f\u7528\u8005\u3002<\/p>\n<p>\u5728\u9879\u76ee\u540d\u4e0a\uff0c\u53f3\u952e\u6253\u5f00\u5c5e\u6027\u3002\u70b9\u5f00 C\/C++ -&gt; \u4ee3\u7801\u751f\u6210 -&gt; \u5b89\u5168\u68c0\u67e5\uff0c\u9009\u62e9\u7981\u7528<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708345614174.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 681px; --smush-placeholder-aspect-ratio: 681\/414;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"42_%E6%96%87%E4%BB%B6%E9%80%89%E6%8B%A9\"><\/span>4.2 \u6587\u4ef6\u9009\u62e9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd9\u91cc\u5199\u4e00\u4e2a\u6587\u4ef6\u9009\u62e9\u7684 demo\uff0c\u57fa\u4e8e Windows API<\/p>\n<pre><code class=\"language-C\">#include &lt;Windows.h&gt;\n#include &lt;stdio.h&gt; \/\/ printf \u51fd\u6570\u7528\u5230\n\nint main()\n{\n    OPENFILENAME ofn; \/\/ \u6253\u5f00\u6587\u4ef6\u5bf9\u8bdd\u6846\u7ed3\u6784\u4f53\n    char file_name[MAX_PATH]; \/\/ \u5b58\u50a8\u6587\u4ef6\u8def\u5f84\u7684\u7f13\u51b2\u533a\uff0c\u6253\u5f00\u6587\u4ef6\u540e\u8def\u5f84\u5c31\u4fdd\u5b58\u5728\u8fd9\u91cc\n\n    \/\/ \u521d\u59cb\u5316\u586b\u5145\u4e3a 0\n    ZeroMemory(&amp;ofn, sizeof(ofn));\n    ZeroMemory(file_name, sizeof(file_name));\n\n    ofn.lStructSize = sizeof(ofn);\n    ofn.lpstrFile = file_name;\n    ofn.lpstrFile[0] = &#039;\\0&#039;;\n    ofn.nMaxFile = sizeof(file_name);\n    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;\n\n    if (GetOpenFileName(&amp;ofn)) \/\/ \u6253\u5f00\u6587\u4ef6\u5bf9\u8bdd\u6846\n    {\n        printf(&quot;\u4f60\u9009\u62e9\u7684\u8def\u5f84\u662f\uff1a&quot;);\n        WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), file_name, wcslen(file_name), NULL, NULL); \/\/ \u6253\u5370\u5230\u7ec8\u7aef\uff0c\u4e0d\u8981\u4f7f\u7528 printf\uff0c\u8fd9\u91cc\u662f\u5bbd\u5b57\u7b26\uff0cprintf \u4e0d\u80fd\u6b63\u5e38\u663e\u793a\n    }\n\n    return 0;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708347072742.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1561px; --smush-placeholder-aspect-ratio: 1561\/712;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708347480975.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 809px; --smush-placeholder-aspect-ratio: 809\/162;\" \/><\/p>\n<h1><span class=\"ez-toc-section\" id=\"5_FFmpeg_%E5%AE%98%E6%96%B9%E5%8F%82%E8%80%83%E6%A1%88%E4%BE%8B\"><\/span>5 FFmpeg \u5b98\u65b9\u53c2\u8003\u6848\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/ffmpeg.org\/documentation.html\">https:\/\/ffmpeg.org\/documentation.html<\/a><br \/>\n\u9009\u62e9 API \u7248\u672c\u8fdb\u5165\u5bf9\u5e94\u7684\u6587\u6863\uff0c\u5728 API \u6587\u6863\u4e2d Examples \u680f\u4e2d\u6709\u6848\u4f8b\u7a0b\u5e8f<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708351780421.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 710px; --smush-placeholder-aspect-ratio: 710\/750;\" \/><\/p>\n<p>\u6211\u6253\u7b97\u662f\u628a\u53c2\u8003\u6848\u4f8b\u7406\u4e00\u904d\u641e\u61c2\uff0c\u53ef\u80fd\u505a\u4e00\u5b9a\u529f\u80fd\u4fee\u6539\uff0c\u6dfb\u52a0\u4e2d\u6587\u6ce8\u91ca\uff0c\u518d\u653e\u5230\u4e0b\u6587\u4e2d\uff0c\u57fa\u4e8e API 6.0\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"51_%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F%E8%BD%AC%E6%8D%A2\"><\/span>5.1 \u89c6\u9891\u683c\u5f0f\u8f6c\u6362<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd9\u4e2a\u6848\u4f8b\u6765\u6e90\u4e8e <a href=\"https:\/\/ffmpeg.org\/doxygen\/6.0\/remux_8c-example.html\">remux.c<\/a><br \/>\n\u5355\u7eaf\u91cd\u65b0\u6253\u5305\u6587\u4ef6\u683c\u5f0f\uff0c\u4e0d\u4f1a\u91cd\u65b0\u7f16\u7801\u3002\u4f20\u5165\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u8f93\u5165\u89c6\u9891\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u8981\u751f\u6210\u7684\u89c6\u9891\u6587\u4ef6\u540d\uff0c\u7a0b\u5e8f\u901a\u8fc7\u6269\u5c55\u540d\u8bc6\u522b\u89c6\u9891\u683c\u5f0f\u3002<\/p>\n<p>\u76f8\u5f53\u4e8e\u547d\u4ee4<\/p>\n<pre><code>ffmpeg -i \u8f93\u5165\u89c6\u9891 -c:v copy \u8f93\u51fa\u89c6\u9891<\/code><\/pre>\n<pre><code class=\"language-c\">#include &lt;libavutil\/timestamp.h&gt;\n#include &lt;libavformat\/avformat.h&gt;\n\n\/**\n * @brief \u6253\u5370 AVPacket \u4fe1\u606f\n * @param fmt_ctx\n * @param pkt\n * @param tag\n *\/\nstatic void log_packet(const AVFormatContext* fmt_ctx, const AVPacket* pkt, const char* tag)\n{\n    AVRational* time_base = &amp;fmt_ctx-&gt;streams[pkt-&gt;stream_index]-&gt;time_base;\n\n    printf(&quot;%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\\n&quot;,\n        tag,\n        av_ts2str(pkt-&gt;pts), av_ts2timestr(pkt-&gt;pts, time_base),\n        av_ts2str(pkt-&gt;dts), av_ts2timestr(pkt-&gt;dts, time_base),\n        av_ts2str(pkt-&gt;duration), av_ts2timestr(pkt-&gt;duration, time_base),\n        pkt-&gt;stream_index);\n}\n\nint main(int argc, char** argv)\n{\n    if (argc &lt; 3)\n    {\n        printf(&quot;\u7528\u6cd5\uff1a%s \u8f93\u5165 \u8f93\u51fa\\n&quot;\n            &quot;\u4f7f\u7528 libavformat \u548c libavcodec \u8f6c\u6362\u89c6\u9891\u683c\u5f0f\\n&quot;\n            &quot;\u6839\u636e\u6587\u4ef6\u6269\u5c55\u540d\u63a8\u6d4b\u683c\u5f0f\\n&quot;, argv[0]);\n        return 1;\n    }\n\n    AVFormatContext* ifmt_ctx = NULL; \/\/ \u7528\u4e8e\u50a8\u5b58\u8f93\u5165\u683c\u5f0f\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\n    const char* in_filename = argv[1]; \/\/ \u4ece\u547d\u4ee4\u884c\u53c2\u6570\u5217\u8868\u83b7\u53d6\u8f93\u5165\u6587\u4ef6\u540d\n    int ret; \/\/ \u7528\u4e8e\u63a5\u53d7\u540e\u7eed\u591a\u4e2a\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u4ee5\u4fbf\u5224\u65ad\u5f02\u5e38\n    if ((ret = avformat_open_input(&amp;ifmt_ctx, in_filename, NULL, NULL)) &lt; 0)\n    {\n        fprintf(stderr, &quot;\u4e0d\u80fd\u6253\u5f00\u8f93\u5165\u6587\u4ef6\uff1a%s\\n&quot;, in_filename);\n        goto end;\n    }\n\n    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) &lt; 0)\n    {\n        fprintf(stderr, &quot;\u68c0\u7d22\u8f93\u5165\u6d41\u4fe1\u606f\u5931\u8d25\\n&quot;);\n        goto end;\n    }\n\n    av_dump_format(ifmt_ctx, 0, in_filename, 0); \/\/ \u6253\u5370\u8f93\u5165\u6587\u4ef6\u7684\u683c\u5f0f\u548c\u6d41\u4fe1\u606f\n\n    const char* out_filename = argv[2]; \/\/ \u4ece\u547d\u4ee4\u884c\u53c2\u6570\u5217\u8868\u83b7\u53d6\u8f93\u51fa\u6587\u4ef6\u540d\n    AVFormatContext* ofmt_ctx = NULL; \/\/ \u7528\u4e8e\u50a8\u5b58\u8f93\u51fa\u6587\u4ef6\u7684\u97f3\u89c6\u9891\u683c\u5f0f\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\n    avformat_alloc_output_context2(&amp;ofmt_ctx, NULL, NULL, out_filename);\n    if (!ofmt_ctx)\n    {\n        fprintf(stderr, &quot;\u4e0d\u80fd\u521b\u5efa\u8f93\u51fa\u683c\u5f0f\u4e0a\u4e0b\u6587\\n&quot;);\n        ret = AVERROR_UNKNOWN;\n        goto end;\n    }\n\n    unsigned int stream_mapping_size = ifmt_ctx-&gt;nb_streams; \/\/ \u83b7\u53d6\u8f93\u5165\u6587\u4ef6\u7684\u6d41\u4e2a\u6570\n    int* stream_mapping = av_calloc(stream_mapping_size, sizeof(int*));\n    if (!stream_mapping)\n    {\n        ret = AVERROR(ENOMEM);\n        goto end;\n    }\n\n    const AVOutputFormat* ofmt = ofmt_ctx-&gt;oformat; \/\/ \u83b7\u53d6\u8f93\u51fa\u683c\u5f0f\u4e0a\u4e0b\u6587\u7684\u683c\u5f0f\n\n    int stream_index = 0;\n\n    \/\/ \u904d\u5386\u8f93\u5165\u6587\u4ef6\u7684\u6bcf\u4e2a\u6d41\n    for (unsigned int i = 0; i &lt; stream_mapping_size; ++i)\n    {\n        AVStream* in_stream = ifmt_ctx-&gt;streams[i]; \/\/ \u8f93\u5165\u6d41\n        AVCodecParameters* in_codecpar = in_stream-&gt;codecpar; \/\/ \u83b7\u53d6\u8f93\u5165\u6d41\u7684\u7f16\u89e3\u7801\u53c2\u6570\n\n        if (in_codecpar-&gt;codec_type != AVMEDIA_TYPE_AUDIO &amp;&amp;\n            in_codecpar-&gt;codec_type != AVMEDIA_TYPE_VIDEO &amp;&amp;\n            in_codecpar-&gt;codec_type != AVMEDIA_TYPE_SUBTITLE) \/\/ \u8f93\u5165\u7c7b\u578b\u4e0d\u662f\u97f3\u9891\u3001\u89c6\u9891\u6216\u505a\u5b57\u5e55\u65f6\uff0c\u4e0d\u590d\u5236\u8be5\u6d41\n        {\n            stream_mapping[i] = -1;\n            continue;\n        }\n\n        stream_mapping[i] = stream_index++;\n\n        AVStream* out_stream = avformat_new_stream(ofmt_ctx, NULL);\n        if (!out_stream)\n        {\n            fprintf(stderr, &quot;\u521b\u5efa\u8f93\u51fa\u6d41\u5931\u8d25\\n&quot;);\n            ret = AVERROR_UNKNOWN;\n            goto end;\n        }\n\n        if ((ret = avcodec_parameters_copy(out_stream-&gt;codecpar, in_codecpar)) &lt; 0)\n        {\n            fprintf(stderr, &quot;\u590d\u5236\u8f93\u5165\u6d41\u7684\u7f16\u89e3\u7801\u53c2\u6570\u5230\u8f93\u51fa\u6d41\u5931\u8d25\\n&quot;);\n            goto end;\n        }\n        out_stream-&gt;codecpar-&gt;codec_tag = 0; \/\/ \u8bbe\u7f6e\u4e3a 0\uff0c\u8ba9 FFmpeg \u81ea\u5df1\u9009\u62e9\n    }\n\n    av_dump_format(ofmt_ctx, 0, out_filename, 1); \/\/ \u6253\u5370\u8f93\u51fa\u6587\u4ef6\u7684\u683c\u5f0f\u548c\u6d41\u4fe1\u606f\n\n    if (!(ofmt-&gt;flags &amp; AVFMT_NOFILE)) \/\/ \u662f\u5426\u9700\u8981\u8f93\u51fa\u6587\u4ef6\n    {\n        if ((ret = avio_open(&amp;ofmt_ctx-&gt;pb, out_filename, AVIO_FLAG_WRITE)) &lt; 0)\n        {\n            fprintf(stderr, &quot;\u6253\u5f00\u8f93\u51fa\u6587\u4ef6\u5931\u8d25: %s\\n&quot;, out_filename);\n            goto end;\n        }\n    }\n\n    if ((ret = avformat_write_header(ofmt_ctx, NULL)) &lt; 0)\n    {\n        fprintf(stderr, &quot;\u5728\u5199\u5165\u8f93\u51fa\u6587\u4ef6\u7684\u5934\u90e8\u4fe1\u606f\u65f6\u53d1\u751f\u9519\u8bef\\n&quot;);\n        goto end;\n    }\n\n    AVPacket* pkt = av_packet_alloc(); \/\/ \u5206\u914d\u7a7a\u95f4\uff0c\u7528\u4e8e\u5b58\u50a8\u538b\u7f29\u6570\u636e\uff08\u89c6\u9891\u3001\u97f3\u9891\uff09\u7684\u6570\u636e\u7ed3\u6784\n    if (!pkt)\n    {\n        fprintf(stderr, &quot;\u4e0d\u80fd\u521b\u5efa AVPacket\\n&quot;);\n        return 1;\n    }\n\n    while (1)\n    {\n        if ((ret = av_read_frame(ifmt_ctx, pkt)) &lt; 0)\n        {\n            break;\n        }\n\n        AVStream* in_stream = ifmt_ctx-&gt;streams[pkt-&gt;stream_index];\n        if (pkt-&gt;stream_index &gt;= stream_mapping_size ||\n            stream_mapping[pkt-&gt;stream_index] &lt; 0)\n        {\n            av_packet_unref(pkt);\n            continue;\n        }\n\n        pkt-&gt;stream_index = stream_mapping[pkt-&gt;stream_index];\n        AVStream* out_stream = ofmt_ctx-&gt;streams[pkt-&gt;stream_index];\n        log_packet(ifmt_ctx, pkt, &quot;in&quot;);\n\n        av_packet_rescale_ts(pkt, in_stream-&gt;time_base, out_stream-&gt;time_base);\n        pkt-&gt;pos = -1;\n        log_packet(ofmt_ctx, pkt, &quot;out&quot;);\n\n        if ((ret = av_interleaved_write_frame(ofmt_ctx, pkt)) &lt; 0)\n        {\n            fprintf(stderr, &quot;Error muxing packet\\n&quot;);\n            break;\n        }\n    }\n\n    av_write_trailer(ofmt_ctx);\n\nend:\n    av_packet_free(&amp;pkt);\n\n    avformat_close_input(&amp;ifmt_ctx);\n\n    if (ofmt_ctx &amp;&amp; !(ofmt-&gt;flags &amp; AVFMT_NOFILE))\n    {\n        avio_closep(&amp;ofmt_ctx-&gt;pb);\n    }\n    avformat_free_context(ofmt_ctx);\n\n    av_freep(&amp;stream_mapping);\n\n    if (ret &lt; 0 &amp;&amp; ret != AVERROR_EOF)\n    {\n        fprintf(stderr, &quot;\u53d1\u751f\u9519\u8bef\uff1a%s\\n&quot;, av_err2str(ret));\n        return 1;\n    }\n\n    return 0;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/02\/image-1708438531627.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1102px; --smush-placeholder-aspect-ratio: 1102\/469;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 \u524d\u8a00 \u4ee5\u524d\u53ea\u662f\u5355\u7eaf\u62ff FFmpeg \u547d\u4ee4\u884c\u5de5\u5177\u6765\u7f16\u7801\u89c6\u9891\uff08\u56fe\u7247\u5408\u6210\u89c6\u9891\u3001\u89c6\u9891\u683c\u5f0f\u8f6c\u6362\u3001\u7f16\u7801\u5668\u8f6c\u6362\uff09\uff0c\u5e76\u6ca1\u6709 [&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,589,610],"tags":[],"class_list":["post-13935","post","type-post","status-publish","format-standard","hentry","category-all","category-c-c","category-ffmpeg-"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/13935","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=13935"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/13935\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}