{"id":6886,"date":"2025-06-04T14:14:39","date_gmt":"2025-06-05T07:05:39","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6886"},"modified":"2025-06-05T14:14:39","modified_gmt":"2025-06-05T07:05:39","slug":"https-badgameshow-com-steven-119","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-119\/","title":{"rendered":"\u6700\u65b0 Swift \u5f71\u7247\u62cd\u651d\u6280\u8853\uff1a\u6df1\u5165\u4e86\u89e3 AVCaptureSession \ud83c\udfa5"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, AVCaptureSession, \u5f71\u7247\u62cd\u651d, iOS \u958b\u767c\"><\/p>\n<h1>\u6700\u65b0 Swift \u5f71\u7247\u62cd\u651d\u6280\u8853\uff1a\u6df1\u5165\u4e86\u89e3 AVCaptureSession \ud83c\udfa5<\/h1>\n<p>Swift \u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u958b\u767c\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Swift \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5229\u7528 <strong>AVCaptureSession<\/strong> \u6846\u67b6\u4f86\u62cd\u651d\u5f71\u7247\uff0c\u9019\u662f\u4e00\u500b\u975e\u5e38\u5be6\u7528\u7684\u529f\u80fd\uff0c\u7279\u5225\u662f\u5728\u79fb\u52d5\u8a2d\u5099\u4e0a\u9032\u884c\u5a92\u9ad4\u8655\u7406\u6642\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 AVCaptureSession<\/h2>\n<p>\u8981\u4f7f\u7528 AVCaptureSession\uff0c\u9996\u5148\u9700\u8981\u5efa\u7acb\u4e00\u500b AVCaptureSession \u7269\u4ef6\uff0c\u4e26\u8a2d\u5b9a\u62cd\u651d\u7684\u53c3\u6578\uff0c\u4f8b\u5982\u89e3\u6790\u5ea6\u3001\u8f38\u51fa\u683c\u5f0f\u7b49\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 AVCaptureSession \u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">import AVFoundation\n\nlet captureSession = AVCaptureSession()\ncaptureSession.sessionPreset = .high\n<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u60a8\u9700\u8981\u5efa\u7acb\u4e00\u500b <strong>AVCaptureDeviceInput<\/strong> \u7269\u4ef6\uff0c\u4e26\u6307\u5b9a\u4f7f\u7528\u7684\u62cd\u651d\u88dd\u7f6e\uff0c\u4f8b\u5982\u651d\u5f71\u6a5f\u6216\u9ea5\u514b\u98a8\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">guard let captureDevice = AVCaptureDevice.default(for: .video) else { return }\nlet deviceInput = try AVCaptureDeviceInput(device: captureDevice)\n<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u5c07 <strong>AVCaptureDeviceInput<\/strong> \u52a0\u5165\u5230 <strong>AVCaptureSession<\/strong> \u4e2d\uff0c\u4e26\u958b\u59cb\u62cd\u651d\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">captureSession.addInput(deviceInput)\ncaptureSession.startRunning()\n<\/code><\/pre>\n<h2>AVCaptureSession \u7684\u512a\u9ede<\/h2>\n<p>AVCaptureSession \u63d0\u4f9b\u4e86\u591a\u7a2e\u512a\u9ede\uff0c\u4f7f\u5176\u6210\u70ba\u62cd\u651d\u5f71\u7247\u7684\u7406\u60f3\u9078\u64c7\uff1a<\/p>\n<ul>\n<li><strong>\u81ea\u5b9a\u7fa9\u62cd\u651d\u53c3\u6578<\/strong>\uff1a\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u5f71\u7247\u7684\u89e3\u6790\u5ea6\u548c\u5176\u4ed6\u53c3\u6578\u3002<\/li>\n<li><strong>\u9ad8\u89e3\u6790\u5ea6\u62cd\u651d<\/strong>\uff1a\u652f\u6301\u9ad8\u89e3\u6790\u5ea6\u5f71\u7247\u62cd\u651d\uff0c\u78ba\u4fdd\u5f71\u7247\u8cea\u91cf\u3002<\/li>\n<li><strong>\u591a\u7a2e\u683c\u5f0f\u652f\u6301<\/strong>\uff1a\u80fd\u5920\u62cd\u651d\u591a\u7a2e\u683c\u5f0f\u7684\u5f71\u7247\uff0c\u4f8b\u5982 MP4\u3001MOV \u7b49\u3002<\/li>\n<\/ul>\n<h2>\u932f\u8aa4\u6392\u9664\u6280\u5de7<\/h2>\n<p>\u5728\u4f7f\u7528 AVCaptureSession \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u554f\u984c\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\uff1a<\/p>\n<ul>\n<li><strong>\u7121\u6cd5\u8a2a\u554f\u651d\u5f71\u6a5f\uff1a<\/strong>\u78ba\u4fdd\u5728 Info.plist \u4e2d\u6dfb\u52a0\u4e86\u5fc5\u8981\u7684\u96b1\u79c1\u6b0a\u9650\u63cf\u8ff0\uff0c\u4f8b\u5982 NSCameraUsageDescription\u3002<\/li>\n<li><strong>\u88dd\u7f6e\u521d\u59cb\u5316\u5931\u6557\uff1a<\/strong>\u6aa2\u67e5\u662f\u5426\u6b63\u78ba\u7372\u53d6\u4e86\u53ef\u7528\u7684\u651d\u5f71\u88dd\u7f6e\uff0c\u4e26\u78ba\u4fdd\u8a2d\u5099\u6c92\u6709\u88ab\u5176\u4ed6\u61c9\u7528\u4f54\u7528\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u5f71\u7247\u62cd\u651d\uff0cAVCaptureSession \u9084\u53ef\u4ee5\u7528\u65bc\u9304\u88fd\u97f3\u983b\u3001\u5be6\u6642\u5f71\u50cf\u8655\u7406\u7b49\u61c9\u7528\u5834\u666f\u3002\u958b\u767c\u8005\u53ef\u4ee5\u7d50\u5408 <strong>AVCaptureVideoDataOutput<\/strong> \u548c <strong>AVCaptureAudioDataOutput<\/strong> \u4f86\u5be6\u73fe\u66f4\u8907\u96dc\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u5373\u6642\u8996\u983b\u5206\u6790\u6216\u97f3\u983b\u8655\u7406\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>AVCaptureSession \u662f\u4e00\u500b\u5f37\u5927\u7684\u6846\u67b6\uff0c\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u5f71\u7247\u62cd\u651d\u529f\u80fd\u3002\u900f\u904e\u81ea\u5b9a\u7fa9\u8a2d\u5b9a\u548c\u9ad8\u54c1\u8cea\u7684\u62cd\u651d\u80fd\u529b\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5275\u5efa\u51fa\u8272\u7684\u5a92\u9ad4\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<ul>\n<li><strong>\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 AVCaptureSession\uff1f<\/strong><br \/>\u4f7f\u7528 AVCaptureSession \u9700\u8981\u9996\u5148\u5275\u5efa\u6703\u8a71\uff0c\u7136\u5f8c\u6dfb\u52a0\u8f38\u5165\u8a2d\u5099\uff0c\u6700\u5f8c\u958b\u59cb\u6703\u8a71\u4ee5\u958b\u59cb\u9304\u88fd\u5f71\u7247\u3002<\/li>\n<li><strong>AVCaptureSession \u652f\u6301\u54ea\u4e9b\u5f71\u7247\u683c\u5f0f\uff1f<\/strong><br \/>AVCaptureSession \u53ef\u4ee5\u62cd\u651d\u591a\u7a2e\u683c\u5f0f\u7684\u5f71\u7247\uff0c\u5305\u62ec MP4 \u548c MOV\u3002<\/li>\n<li><strong>\u5982\u4f55\u89e3\u6c7a\u7121\u6cd5\u8a2a\u554f\u651d\u5f71\u6a5f\u7684\u554f\u984c\uff1f<\/strong><br \/>\u8acb\u78ba\u8a8d\u60a8\u7684\u61c9\u7528\u5df2\u7372\u5f97\u651d\u5f71\u6a5f\u4f7f\u7528\u6b0a\u9650\uff0c\u4e26\u6aa2\u67e5 Info.plist \u4e2d\u7684\u8a2d\u7f6e\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5f71\u7247\u62cd\u651d\uff1aAVCaptureSession-\ud83c\udfa5_1675397687.1214101.webp\" alt=\"Swift \u5f71\u7247\u62cd\u651d\uff1aAVCaptureSession \ud83c\udfa5\" title=\"Swift, AVCaptureSession, \u5f71\u7247\u62cd\u651d, \u7a0b\u5f0f\u78bc, \u7bc4\u4f8b\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39Swift\u4e2d\u7684AVCaptureSession\ud83c\udfa5\u5f71\u7247\u62cd\u651d\uff0c\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u7684API\u4f86\u62cd\u651d\u5f71\u7247\uff0c\u4e26\u63d0\u4f9b\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\u4f9b\u53c3\u8003\u3002<\/p>\n","protected":false},"author":1,"featured_media":6885,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-6886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5f71\u7247\u62cd\u651d\uff1aAVCaptureSession-\ud83c\udfa5_1675397687.1214101.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1N4","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6886"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6886\/revisions"}],"predecessor-version":[{"id":13622,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6886\/revisions\/13622"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6885"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}