René's URL Explorer Experiment


Title: work with numpy · python-ffmpegio/python-ffmpegio · Discussion #37 · GitHub

Open Graph Title: work with numpy · python-ffmpegio/python-ffmpegio · Discussion #37

X Title: work with numpy · python-ffmpegio/python-ffmpegio · Discussion #37

Description: work with numpy

Open Graph Description: objective work with numpy to give filter in this example below is to make video in grayscale steps !wget -c https://cdn.creatomate.com/demo/mountains.mp4 !wget -c http://www.jsayles.com/music/sheep...

X Description: objective work with numpy to give filter in this example below is to make video in grayscale steps !wget -c https://cdn.creatomate.com/demo/mountains.mp4 !wget -c http://www.jsayles.com/music/sheep...

Opengraph URL: https://github.com/python-ffmpegio/python-ffmpegio/discussions/37

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"work with numpy","text":"\u003cp dir=\"auto\"\u003e\u003cstrong\u003eobjective\u003c/strong\u003e\u003cbr\u003e\nwork with numpy to give filter in this example below is to make video in grayscale\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003esteps\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"!wget -c https://cdn.creatomate.com/demo/mountains.mp4\n!wget -c http://www.jsayles.com/music/sheep.mp3\npip install -U ffmpegio\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003e!wget -c https://cdn.creatomate.com/demo/mountains.mp4\n!wget -c http://www.jsayles.com/music/sheep.mp3\npip install -U ffmpegio\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003ecode\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"import ffmpegio\nimport os\nimport subprocess\nimport numpy as np\nwith ffmpegio.open('mountains.mp4', 'rv') as fin, ffmpegio.open('temp.mp4', 'wv', rate_in = fin.rate, overwrite = True) as fout:\n    for frame in fin:\n        grayscale= np.dot(frame[0,...], [0.299, 0.587, 0.144] )\n        fout.write(grayscale)\nsubprocess.check_call(\n    [\n        \u0026quot;ffmpeg\u0026quot;,\n        \u0026quot;-y\u0026quot;,\n        \u0026quot;-i\u0026quot;,\n        'temp.mp4',\n        \u0026quot;-i\u0026quot;,\n        'sheep.mp3',\n        \u0026quot;-r\u0026quot;,\n        '10',\n        \u0026quot;-vcodec\u0026quot;,\n        \u0026quot;libx264\u0026quot;,\n        \u0026quot;-acodec\u0026quot;,\n        \u0026quot;copy\u0026quot;, # aac (smallest), libmp3lame, libtwolame (biggest), copy (faster because not reencoding)\n        \u0026quot;-shortest\u0026quot;,\n        'grayscale.mp4',\n    ]\n)\nos.remove(temp)\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003eimport ffmpegio\nimport os\nimport subprocess\nimport numpy as np\nwith ffmpegio.open('mountains.mp4', 'rv') as fin, ffmpegio.open('temp.mp4', 'wv', rate_in = fin.rate, overwrite = True) as fout:\n    for frame in fin:\n        grayscale= np.dot(frame[0,...], [0.299, 0.587, 0.144] )\n        fout.write(grayscale)\nsubprocess.check_call(\n    [\n        \"ffmpeg\",\n        \"-y\",\n        \"-i\",\n        'temp.mp4',\n        \"-i\",\n        'sheep.mp3',\n        \"-r\",\n        '10',\n        \"-vcodec\",\n        \"libx264\",\n        \"-acodec\",\n        \"copy\", # aac (smallest), libmp3lame, libtwolame (biggest), copy (faster because not reencoding)\n        \"-shortest\",\n        'grayscale.mp4',\n    ]\n)\nos.remove(temp)\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eresult\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"'\u0026lt;f8'\n---------------------------------------------------------------------------\nKeyError                                  Traceback (most recent call last)\n[/usr/local/lib/python3.10/dist-packages/ffmpegio/utils/__init__.py](https://localhost:8080/#) in guess_video_format(shape, dtype)\n    426     try:\n--\u0026gt; 427         pix_fmt = {\n    428             \u0026quot;|u1\u0026quot;: {1: \u0026quot;gray\u0026quot;, 2: \u0026quot;ya8\u0026quot;, 3: \u0026quot;rgb24\u0026quot;, 4: \u0026quot;rgba\u0026quot;},\n\nKeyError: '\u0026lt;f8'\n\nDuring handling of the above exception, another exception occurred:\n\nValueError                                Traceback (most recent call last)\n4 frames\n[/usr/local/lib/python3.10/dist-packages/ffmpegio/utils/__init__.py](https://localhost:8080/#) in guess_video_format(shape, dtype)\n    432     except Exception as e:\n    433         print(e)\n--\u0026gt; 434         raise ValueError(\n    435             f\u0026quot;dtype ({dtype}) and guessed number of components ({ncomp}) do not yield a pix_fmt.\u0026quot;\n    436         )\n\nValueError: dtype (\u0026lt;f8) and guessed number of components (1) do not yield a pix_fmt.\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003e'\u0026lt;f8'\n---------------------------------------------------------------------------\nKeyError                                  Traceback (most recent call last)\n[/usr/local/lib/python3.10/dist-packages/ffmpegio/utils/__init__.py](https://localhost:8080/#) in guess_video_format(shape, dtype)\n    426     try:\n--\u0026gt; 427         pix_fmt = {\n    428             \"|u1\": {1: \"gray\", 2: \"ya8\", 3: \"rgb24\", 4: \"rgba\"},\n\nKeyError: '\u0026lt;f8'\n\nDuring handling of the above exception, another exception occurred:\n\nValueError                                Traceback (most recent call last)\n4 frames\n[/usr/local/lib/python3.10/dist-packages/ffmpegio/utils/__init__.py](https://localhost:8080/#) in guess_video_format(shape, dtype)\n    432     except Exception as e:\n    433         print(e)\n--\u0026gt; 434         raise ValueError(\n    435             f\"dtype ({dtype}) and guessed number of components ({ncomp}) do not yield a pix_fmt.\"\n    436         )\n\nValueError: dtype (\u0026lt;f8) and guessed number of components (1) do not yield a pix_fmt.\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003ebest regards\u003c/p\u003e","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003eShort answer: \u003ccode class=\"notranslate\"\u003egrayscale= np.dot(frame[0,...], [0.299, 0.587, 0.144] ).astype(np.uint8)\u003c/code\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eYou're responsible to put the input Numpy array in the correct image pixel format. \u003ccode class=\"notranslate\"\u003effmpegio\u003c/code\u003e simply passes the numpy data bytes straight to FFmpeg. Assuming that the video is RGB24 (8-bit per color channel) your input data dtype must be either \u003ccode class=\"notranslate\"\u003e\"\u0026lt;u1\"\u003c/code\u003e or \u003ccode class=\"notranslate\"\u003enp.uint8\u003c/code\u003e.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eNow, if you're performing these fixed function (the same transform on every frame) read multiple frames at a time (as many as your system can handle). Looping one frame at a time significantly slows down the process.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eFinally, as I alluded in the other post of yours, I'm a big proponent of using the FFmpeg filters whenever possible. In this case, \u003ca href=\"https://ffmpeg.org/ffmpeg-filters.html#colorchannelmixer\" rel=\"nofollow\"\u003ecolorchennelmixer\u003c/a\u003e does the job with \u003ccode class=\"notranslate\"\u003effmpegio.transpose\u003c/code\u003e. Something along the line of\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"ffmpegio.transpose('mountains.mp4', 'temp.mp4', overwrite = True, vf='colorchannelmixer=0.299:0.587:0.144:00.299:0.587:0.144:00.299:0.587:0.144:0')\"\u003e\u003cpre class=\"notranslate\"\u003e\u003cspan class=\"pl-s1\"\u003effmpegio\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003etranspose\u003c/span\u003e(\u003cspan class=\"pl-s\"\u003e'mountains.mp4'\u003c/span\u003e, \u003cspan class=\"pl-s\"\u003e'temp.mp4'\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003eoverwrite\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003eTrue\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003evf\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e'colorchannelmixer=0.299:0.587:0.144:00.299:0.587:0.144:00.299:0.587:0.144:0'\u003c/span\u003e)\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eI have not tested this command, but you get the idea. If you want to apply multiple effects (to grayscale + flip) then you can chain multiple filters as needed.\u003c/p\u003e","upvoteCount":1,"url":"https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987"}}}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format)
route-controllervoltron_discussions_fragments
route-actiondiscussion_layout
fetch-noncev2:317c2e8a-2328-0b54-2224-fcb9bf58fd4d
current-catalog-service-hash9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be
request-idE40C:3073EF:277E8E:375B61:6AFD7390
html-safe-noncefd32c4015529a769860a04331dfb95743695b4bfac1700d4651df4a73237d5dd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDBDOjMwNzNFRjoyNzdFOEU6Mzc1QjYxOjZBRkQ3MzkwIiwidmlzaXRvcl9pZCI6IjQ5ODY4MDkxNzY4MTk1OTQxMjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace3345026c1a7813852d3bac43a4d91aa3f9b7fde0174e200a024bb84b4ca305d
hovercard-subject-tagdiscussion:6369214
github-keyboard-shortcutsrepository,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/discussions_fragments/discussion_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-ffmpegio/python-ffmpegio/37/discussion_layout
twitter:imagehttps://opengraph.githubassets.com/90f7acae59a642fa59239b987d44298127b701b067eb2d98b60b82f8f3818e74/python-ffmpegio/python-ffmpegio/discussions/37
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/90f7acae59a642fa59239b987d44298127b701b067eb2d98b60b82f8f3818e74/python-ffmpegio/python-ffmpegio/discussions/37
og:image:altobjective work with numpy to give filter in this example below is to make video in grayscale steps !wget -c https://cdn.creatomate.com/demo/mountains.mp4 !wget -c http://www.jsayles.com/music/sheep...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonee54006cf2b96d1ac260960edd10003132911469ccd1ec99c9803119fe2a4e032
turbo-cache-controlno-preview
go-importgithub.com/python-ffmpegio/python-ffmpegio git https://github.com/python-ffmpegio/python-ffmpegio.git
octolytics-dimension-user_id98168493
octolytics-dimension-user_loginpython-ffmpegio
octolytics-dimension-repository_id355600490
octolytics-dimension-repository_nwopython-ffmpegio/python-ffmpegio
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id355600490
octolytics-dimension-repository_network_root_nwopython-ffmpegio/python-ffmpegio
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5be0bf2b8cf26f8897d31e6bc3c232d328b12a54
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-ffmpegio%2Fpython-ffmpegio%2Fdiscussions%2F37
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-ffmpegio%2Fpython-ffmpegio%2Fdiscussions%2F37
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fdiscussions_fragments%2Fdiscussion_layout&source=header-repo&source_repo=python-ffmpegio%2Fpython-ffmpegio
Reloadhttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
Reloadhttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
Reloadhttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
python-ffmpegiohttps://github.com/python-ffmpegio
python-ffmpegiohttps://github.com/python-ffmpegio/python-ffmpegio
Codehttps://github.com/python-ffmpegio/python-ffmpegio
Issues4 (4)https://github.com/python-ffmpegio/python-ffmpegio/issues
Pull requests1 (1)https://github.com/python-ffmpegio/python-ffmpegio/pulls
Discussionshttps://github.com/python-ffmpegio/python-ffmpegio/discussions
Actionshttps://github.com/python-ffmpegio/python-ffmpegio/actions
Projectshttps://github.com/python-ffmpegio/python-ffmpegio/projects
Wikihttps://github.com/python-ffmpegio/python-ffmpegio/wiki
Security and qualityhttps://github.com/python-ffmpegio/python-ffmpegio/security
Insightshttps://github.com/python-ffmpegio/python-ffmpegio/insights
Answered https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987
tikuma-lsuhschttps://github.com/tikuma-lsuhsc
sugizo https://github.com/sugizo
Q&Ahttps://github.com/python-ffmpegio/python-ffmpegio/discussions/categories/q-a
work with numpy https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#top
sugizo https://github.com/sugizo
Answered https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987
tikuma-lsuhschttps://github.com/tikuma-lsuhsc
Return to tophttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37#top
Please reload this pagehttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
https://github.com/python-ffmpegio/python-ffmpegio/discussions/37
sugizo https://github.com/sugizo
Mar 13, 2024 https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussion-6369214
tikuma-lsuhsc https://github.com/tikuma-lsuhsc
Mar 13, 2024 https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987
c…https://ffmpeg.org/ffmpeg-filters.html#colorchannelmixer
View full answer https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987
Oldest https://github.com/python-ffmpegio/python-ffmpegio/discussions/37?sort=old
Newest https://github.com/python-ffmpegio/python-ffmpegio/discussions/37?sort=new
Top https://github.com/python-ffmpegio/python-ffmpegio/discussions/37?sort=top
Please reload this pagehttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
https://github.com/python-ffmpegio/python-ffmpegio/discussions/37
Please reload this pagehttps://github.com/python-ffmpegio/python-ffmpegio/discussions/37
https://github.com/python-ffmpegio/python-ffmpegio/discussions/37
tikuma-lsuhsc https://github.com/tikuma-lsuhsc
Mar 13, 2024 https://github.com/python-ffmpegio/python-ffmpegio/discussions/37#discussioncomment-8777987
colorchennelmixerhttps://ffmpeg.org/ffmpeg-filters.html#colorchannelmixer
sugizohttps://github.com/sugizo
Sign up for freehttps://github.com/join?source=comment-repo
Sign in to commenthttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-ffmpegio%2Fpython-ffmpegio%2Fdiscussions%2F37
🙏 Q&A https://github.com/python-ffmpegio/python-ffmpegio/discussions/categories/q-a
https://github.com/sugizo
https://github.com/tikuma-lsuhsc
https://github.com/python-ffmpegio/python-ffmpegio/discussions/37
https://github.com/settings/replies?return_to=1
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.