{"id":3455,"date":"2022-03-19T20:47:43","date_gmt":"2022-03-19T15:17:43","guid":{"rendered":"http:\/\/myprojectideas.com\/?p=3455"},"modified":"2025-11-01T11:53:41","modified_gmt":"2025-11-01T11:53:41","slug":"play-a-video-in-python-with-opencv-module","status":"publish","type":"post","link":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/","title":{"rendered":"Play A Video In Python With OpenCV Module"},"content":{"rendered":"<h2><strong>Introduction of the Project<\/strong><\/h2>\n<p>Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to <a href=\"https:\/\/docs.opencv.org\/4.x\/\">Open source Computer Vision<\/a>. It\u2019s a library that helps in performing various tasks related to image processing &amp; computer vision. Here, we demonstrated a code that uses the OpenCV module to pause and play the video. For this action to process, the OpenCV has several elements, and we are trying to capture the frames to proceed with this.<\/p>\n<p>So let\u2019s write code for it!<\/p>\n<h2><strong>Requirements<\/strong><\/h2>\n<p>1. You need Python to run the code. You can use VSCode or any python IDE.<\/p>\n<p>2. OpenCV and Numpy modules must be installed on your system.<\/p>\n<p>3. A demo video for it to process the given commands through code (here playing a video).<\/p>\n<h2><strong>Steps To <\/strong><strong>Play A Video In Python With OpenCV Module<\/strong><\/h2>\n<p><strong>Step 1: <\/strong>Install OpenCV if you haven&#8217;t it in your system.<\/p>\n<p>Paste the below line of command in your command prompt and press enter.<\/p>\n<p><strong><em>pip install opencv-python<\/em><\/strong><\/p>\n<p><strong>Step 2: <\/strong>Now copy this source code into your editor\/IDE.<\/p>\n<h2><strong>Source Code<\/strong><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># Import OpenCV module\r\n\r\nimport cv2\r\n\r\n\r\n\r\n\r\n# Capture the video from its path\r\n\r\ncapture = cv2.VideoCapture('videos\/sampleVideo.mp4')\r\n\r\n\r\n\r\n\r\nwhile True:\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0 # Read each frame of the video\r\n\r\n\u00a0\u00a0\u00a0 ret_val, frame = capture.read()\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0 # Resize the output video frame\r\n\r\n\u00a0\u00a0\u00a0 video = cv2.resize(frame,(600,700))\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0 # Dispay the frames of the video\r\n\r\n\u00a0\u00a0\u00a0 cv2.imshow('Playing video using OpenCV in python', video)\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0 # Plays video and waits for a pressed key\r\n\r\n\u00a0\u00a0\u00a0 if cv2.waitKey(1) == 27:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 break\u00a0\r\n\r\n\r\n\r\n\r\n# Destroys all of the HighGUI windows\r\n\r\ncv2.destroyAllWindows()<\/pre>\n<h2><strong>Explanation Of The Code<\/strong><\/h2>\n<p>In the beginning, we imported the OpenCV module.<\/p>\n<p>1. At first, we are capturing the video from its path.<\/p>\n<p>2. After this, we read and resize each frame using the resize() function.<\/p>\n<p>3. Then, we display each video frame using the imshow() function.<\/p>\n<p>4. Finally, we are destroying the video window.<\/p>\n<h2><strong>Output<\/strong><\/h2>\n<p>The below picture shows the video played using the OpenCV module in python;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-18421 size-full\" src=\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2022\/03\/Play-A-Video-In-Python-With-OpenCV-Module.webp\" alt=\"Play A Video In Python With OpenCV Module\" width=\"602\" height=\"728\" \/><\/p>\n<h2><strong>Things to Remember\u00a0<\/strong><\/h2>\n<ul>\n<li>Install the OpenCV module prior to pasting the code.<\/li>\n<li>Write the name of the module in lowercase only.<\/li>\n<li>Set the path of the video according to your video path.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.<\/p>\n","protected":false},"author":1,"featured_media":8386,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[7,5],"tags":[18,21,22],"class_list":["post-3455","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-projects","category-python","tag-computer-science","tag-opencv","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Play A Video In Python With OpenCV Module - RUDE LABS<\/title>\n<meta name=\"description\" content=\"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Play A Video In Python With OpenCV Module - RUDE LABS\" \/>\n<meta property=\"og:description\" content=\"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\" \/>\n<meta property=\"og:site_name\" content=\"RUDE LABS\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-19T15:17:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-01T11:53:41+00:00\" \/>\n<meta name=\"author\" content=\"rudelabs.ai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rudelabs_in\" \/>\n<meta name=\"twitter:site\" content=\"@rudelabs_in\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rudelabs.ai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\"},\"author\":{\"name\":\"rudelabs.ai\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894\"},\"headline\":\"Play A Video In Python With OpenCV Module\",\"datePublished\":\"2022-03-19T15:17:43+00:00\",\"dateModified\":\"2025-11-01T11:53:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\"},\"wordCount\":284,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage\"},\"thumbnailUrl\":\"\",\"keywords\":[\"computer science\",\"OpenCV\",\"Python\"],\"articleSection\":[\"Coding Projects\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\",\"name\":\"Play A Video In Python With OpenCV Module - RUDE LABS\",\"isPartOf\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2022-03-19T15:17:43+00:00\",\"dateModified\":\"2025-11-01T11:53:41+00:00\",\"description\":\"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.\",\"breadcrumb\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/rudelabs.ai\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Play A Video In Python With OpenCV Module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#website\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/\",\"name\":\"RUDE LABS\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/rudelabs.ai\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#organization\",\"name\":\"RUDE LABS\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp\",\"contentUrl\":\"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp\",\"width\":2459,\"height\":414,\"caption\":\"RUDE LABS\"},\"image\":{\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/rudelabs_in\",\"https:\/\/www.linkedin.com\/company\/ru-delabs\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894\",\"name\":\"rudelabs.ai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g\",\"caption\":\"rudelabs.ai\"},\"sameAs\":[\"https:\/\/rudelabs.ai\/blogs\"],\"url\":\"https:\/\/rudelabs.ai\/blogs\/author\/rudelabs-ai\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Play A Video In Python With OpenCV Module - RUDE LABS","description":"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/","og_locale":"en_US","og_type":"article","og_title":"Play A Video In Python With OpenCV Module - RUDE LABS","og_description":"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.","og_url":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/","og_site_name":"RUDE LABS","article_published_time":"2022-03-19T15:17:43+00:00","article_modified_time":"2025-11-01T11:53:41+00:00","author":"rudelabs.ai","twitter_card":"summary_large_image","twitter_creator":"@rudelabs_in","twitter_site":"@rudelabs_in","twitter_misc":{"Written by":"rudelabs.ai","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#article","isPartOf":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/"},"author":{"name":"rudelabs.ai","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894"},"headline":"Play A Video In Python With OpenCV Module","datePublished":"2022-03-19T15:17:43+00:00","dateModified":"2025-11-01T11:53:41+00:00","mainEntityOfPage":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/"},"wordCount":284,"commentCount":0,"publisher":{"@id":"https:\/\/rudelabs.ai\/blogs\/#organization"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage"},"thumbnailUrl":"","keywords":["computer science","OpenCV","Python"],"articleSection":["Coding Projects","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/","url":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/","name":"Play A Video In Python With OpenCV Module - RUDE LABS","isPartOf":{"@id":"https:\/\/rudelabs.ai\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage"},"thumbnailUrl":"","datePublished":"2022-03-19T15:17:43+00:00","dateModified":"2025-11-01T11:53:41+00:00","description":"Today, we will learn how to Play a Video in Python with OpenCV Module. OpenCV refers to Open source Computer Vision.","breadcrumb":{"@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/rudelabs.ai\/blogs\/play-a-video-in-python-with-opencv-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rudelabs.ai\/blogs\/"},{"@type":"ListItem","position":2,"name":"Play A Video In Python With OpenCV Module"}]},{"@type":"WebSite","@id":"https:\/\/rudelabs.ai\/blogs\/#website","url":"https:\/\/rudelabs.ai\/blogs\/","name":"RUDE LABS","description":"","publisher":{"@id":"https:\/\/rudelabs.ai\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rudelabs.ai\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/rudelabs.ai\/blogs\/#organization","name":"RUDE LABS","url":"https:\/\/rudelabs.ai\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp","contentUrl":"https:\/\/rudelabs.ai\/blogs\/wp-content\/uploads\/2025\/09\/RUDE-LABS.webp","width":2459,"height":414,"caption":"RUDE LABS"},"image":{"@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/rudelabs_in","https:\/\/www.linkedin.com\/company\/ru-delabs\/"]},{"@type":"Person","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/560bad88bae03cae99a326a46af0c894","name":"rudelabs.ai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rudelabs.ai\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d9f672e72f97294dfb6fac3d78e9f0bb5421a701cd2141cf2a2e540b4d67191?s=96&d=mm&r=g","caption":"rudelabs.ai"},"sameAs":["https:\/\/rudelabs.ai\/blogs"],"url":"https:\/\/rudelabs.ai\/blogs\/author\/rudelabs-ai\/"}]}},"_links":{"self":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/3455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/comments?post=3455"}],"version-history":[{"count":1,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/3455\/revisions"}],"predecessor-version":[{"id":18422,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/posts\/3455\/revisions\/18422"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/media?parent=3455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/categories?post=3455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rudelabs.ai\/blogs\/wp-json\/wp\/v2\/tags?post=3455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}