{"id":6203,"date":"2017-09-09T10:53:12","date_gmt":"2017-09-09T09:53:12","guid":{"rendered":"http:\/\/idiolect.org.uk\/notes\/?p=6203"},"modified":"2017-09-09T11:00:14","modified_gmt":"2017-09-09T10:00:14","slug":"using-ffmpeg-to-convert-all-images-in-a-folder-to-video","status":"publish","type":"post","link":"https:\/\/idiolect.org.uk\/notes\/2017\/09\/09\/using-ffmpeg-to-convert-all-images-in-a-folder-to-video\/","title":{"rendered":"Using ffmpeg to convert all images in a folder to video"},"content":{"rendered":"<p>I take lots of photos on my phone, a daily record of the mundane and notable. These photos sit in folders, mostly unlooked at. Here&#8217;s one way to grok what you&#8217;ve been taking pictures of: make a video which shows them at a rate of 3 per second.<\/p>\n<p>Cribbing from this:<br \/>\nsuperuser.com: <a href=\"https:\/\/superuser.com\/questions\/335799\/how-to-transform-all-the-images-from-the-current-directory-to-a-video-in-ffmpeg\">How to transform all the images from the current directory to a video in FFmpeg?<\/a><br \/>\nand this:<br \/>\nsuperuser.com: <a href=\"https:\/\/superuser.com\/questions\/547296\/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player\/547406#547406\">Resizing videos with ffmpeg\/avconv to fit into static sized player<\/a> (comment)<\/p>\n<p>The thing that makes this slightly more complex is that the photos are different sizes (some are portrait, some are landscape) and I want them to maintain their aspect ratio in the video, which means padding the portrait photos with some black space for the output.<\/p>\n<p>In a terminal define output height and width variables (so, for photos from my phone):<\/p>\n<p style=\"margin-left: 40px\"><code><br \/>\nwidth=3264<br \/>\nheight=2448<\/code><\/p>\n<p>Then<\/p>\n<p style=\"margin-left: 40px\"><code>ffmpeg -framerate 3 -pattern_type glob -i '*.jpg' -vf \"scale=iw*min($width\/iw\\,$height\/ih):ih*min($width\/iw\\,$height\/ih), pad=$width:$height:($width-iw*min($width\/iw\\,$height\/ih))\/2:($height-ih*min($width\/iw\\,$height\/ih))\/2\" video.mp4<\/code><\/p>\n<p>Click <a href=\"https:\/\/explainshell.com\/explain?cmd=ffmpeg+-framerate+3+-pattern_type+glob+-i+%27*.jpg%27+-vf+%22scale%3Diw*min%28%24width%2Fiw%5C%2C%24height%2Fih%29%3Aih*min%28%24width%2Fiw%5C%2C%24height%2Fih%29%2C+pad%3D%24width%3A%24height%3A%28%24width-iw*min%28%24width%2Fiw%5C%2C%24height%2Fih%29%29%2F2%3A%28%24height-ih*min%28%24width%2Fiw%5C%2C%24height%2Fih%29%29%2F2%22+video.mp4\">here<\/a> to get a breakdown of what this is doing via <a href=\"https:\/\/explainshell.com\">explainshell.com<\/a>. People with longer attention spans may want to reduce the framerate (3 per second is nice if you have lots of photos of the same scene, but a bit quick for single photos).<\/p>\n<p>Obviously I have assumed you are using linux and have <a href=\"https:\/\/www.ffmpeg.org\/\">ffmpeg<\/a> installed<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I take lots of photos on my phone, a daily record of the mundane and notable. These photos sit in folders, mostly unlooked at. Here&#8217;s one way to grok what you&#8217;ve been taking pictures of: make a video which shows them at a rate of 3 per second. Cribbing from this: superuser.com: How to transform [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-6203","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5KQtW-1C3","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/posts\/6203"}],"collection":[{"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/comments?post=6203"}],"version-history":[{"count":8,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/posts\/6203\/revisions"}],"predecessor-version":[{"id":6211,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/posts\/6203\/revisions\/6211"}],"wp:attachment":[{"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/media?parent=6203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/categories?post=6203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idiolect.org.uk\/notes\/wp-json\/wp\/v2\/tags?post=6203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}