{"id":4049,"date":"2024-12-10T18:09:21","date_gmt":"2024-12-10T15:09:21","guid":{"rendered":"https:\/\/demensdeum.com\/blog\/2024\/12\/10\/stabilize-video-ffmpeg\/"},"modified":"2024-12-16T22:32:10","modified_gmt":"2024-12-16T19:32:10","slug":"stabilize-video-ffmpeg","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/2024\/12\/10\/stabilize-video-ffmpeg\/","title":{"rendered":"Video stabilization with ffmpeg"},"content":{"rendered":"<p>If you want to stabilize your video and remove camera shake, the `ffmpeg` tool offers a powerful solution. Thanks to the built-in `vidstabdetect` and `vidstabtransform` filters, you can achieve professional results without using complex video editors.<\/p>\n<h2>Preparing for work<\/h2>\n<p>Before you begin, make sure your `ffmpeg` supports the `vidstab` library. On Linux, you can check this with the command:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"bash\"><code>bash  \nffmpeg -filters | grep vidstab  \n<\/code><\/pre>\n<\/div>\n<p>If the library is not installed, you can add it:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"bash\"><code>sudo apt install ffmpeg libvidstab-dev  \n<\/code><\/pre>\n<\/div>\n<p>Installation for macOS via brew:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"bash\"><code>brew install libvidstab\nbrew install ffmpeg\n<\/code><\/pre>\n<\/div>\n<p>Now let&#8217;s move on to the process.<\/p>\n<p>Step 1: Movement Analysis<\/p>\n<p>First, you need to analyze the video motion and create a file with stabilization parameters.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"bash\"><code>ffmpeg -i input.mp4 -vf vidstabdetect=shakiness=10:accuracy=15 transfile=transforms.trf -f null -  \n<\/code><\/pre>\n<\/div>\n<p>Parameters:<\/p>\n<p>shakiness: The level of video shaking (default 5, can be increased to 10 for more severe cases).<br \/>\naccuracy: Analysis accuracy (default 15).<br \/>\ntransfile: The name of the file to save the movement parameters.<\/p>\n<p>Step 2: Applying Stabilization<\/p>\n<p>Now you can apply stabilization using the transformation file:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"bash\"><code>ffmpeg -i input.mp4 -vf vidstabtransform=input=transforms.trf:zoom=5 output.mp4\n<\/code><\/pre>\n<\/div>\n<p>Parameters:<\/p>\n<p>input: Points to the file with transformation parameters (created in the first step).<br \/>\nzoom: Zoom factor to remove black edges (e.g. 5 &#8211; automatically zooms in until artifacts are removed).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to stabilize your video and remove camera shake, the `ffmpeg` tool offers a powerful solution. Thanks to the built-in `vidstabdetect` and `vidstabtransform` filters, you can achieve professional results without using complex video editors. Preparing for work Before you begin, make sure your `ffmpeg` supports the `vidstab` library. On Linux, you can check<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/2024\/12\/10\/stabilize-video-ffmpeg\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Video stabilization with ffmpeg&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[],"class_list":["post-4049","post","type-post","status-publish","format-standard","hentry","category-blog","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/comments?post=4049"}],"version-history":[{"count":6,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4049\/revisions"}],"predecessor-version":[{"id":4055,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/posts\/4049\/revisions\/4055"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/media?parent=4049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/categories?post=4049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/wp-json\/wp\/v2\/tags?post=4049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}