{"id":225,"date":"2014-04-02T19:36:42","date_gmt":"2014-04-02T18:36:42","guid":{"rendered":"http:\/\/www.anginf.de\/?p=225"},"modified":"2014-07-28T11:58:06","modified_gmt":"2014-07-28T09:58:06","slug":"extract-images-from-a-website-and-produce-a-video-out-of-them","status":"publish","type":"post","link":"https:\/\/www.anginf.de\/?p=225","title":{"rendered":"Extract Images from a website and produce a video out of them"},"content":{"rendered":"<p>I had a big website with a lot of images embedded inside, which were dynamically added by users. The pictures were all of the same size, so I thought it would be easy to create a video out of it. Here are the steps to reproduce it:<\/p>\n<h2>Step 0 &#8211; Prerequisites<\/h2>\n<ul>\n<li>You&#8217;ll need python and <a title=\"youtube-upload.py\" href=\"http:\/\/code.google.com\/p\/youtube-upload\/downloads\/list\" target=\"_blank\">http:\/\/code.google.com\/p\/youtube-upload\/downloads\/list<\/a> to upload the video directly from the server. If you want to upload yourself, ignore this line and step 5.<\/li>\n<li>md5sum<\/li>\n<li>avconv &#8211; on ubuntu, this is available through <code>sudo apt-get install libav-tools<\/code><\/li>\n<\/ul>\n<h2>Step 1 &#8211; Extract the images<\/h2>\n<p>Save the website you&#8217;re about to process to a local file, you only need the html part. (This only works with embedded pictures, for static pictures, try downloading the website with <code>wget -m<\/code>). Call the following script with the filename of the saved HTML-file.<\/p>\n<pre lang=\"bash\">#!\/bin\/bash\r\nfile=${1}\r\nmkdir -p result\r\necho \"Processing ${file}.\"\r\ncat ${file} | sed -e 's\/>\/>\\n\/g; s\/<img\/\\n<img\/g; s\/^$\/\/g' | grep 'data:image\/jpeg;base64' | sed -e 's\/<img decoding=\"async\" src=\"data:image\\\/jpeg;base64,\/\/; s\/\" .*\/\/' >out\r\ncount=0\r\nwhile read line\r\ndo\r\nlet \"count+=1\"\r\necho ${line} | base64 -d >$(printf \"result\/%05d.jpg\\n\" ${count})\r\ndone <out<\/pre>\n<h2>Step 2 - Images should be unique<\/h2>\n<p>We must delete all the files that are twice in our results.<\/p>\n<pre lang=\"bash\">#!\/bin\/bash\r\ndeclare -a list=( .\/* );\r\ndeclare -a sums;\r\ncnt=${#list[@]}\r\n\r\necho \"creating md5sum list\"\r\nfor ((x = 0; x < $cnt -1; x++))\r\ndo\r\n    sums[$x]=`md5sum ${list[$x]} | cut -d ' ' -f 1`\r\ndone\r\n\r\necho \"doing compare\"\r\nfor ((x = 0; x < $cnt -1; x++))\r\ndo\r\n  for ((y = x+1; y < $cnt; y++))\r\n  do\r\n    if [ \"${sums[$x]}\" == \"${sums[$y]}\" ];then\r\n      if [ ${list[$x]} != ${list[$y]} ];then\r\n        #remove '#' in next line to enable\r\n        echo \"Delete file ${list[$y]}\" # &#038;&#038; rm -f ${list[$y]}\r\n      fi\r\n    fi\r\n  done\r\ndone<\/pre>\n<h2>Step 3 - Renumber<\/h2>\n<p>The avconv-Tool can arrange all the images, but they must start with 00000.jpg and strongly increasing numbers. Therefore, we renumber all the jpg-Files accordingly.<\/p>\n<pre lang=\"bash\">#!\/bin\/bash\r\nfind . -type f -iname '*.jpg' | sort -n >filelist\r\nseq=0\r\nwhile read line\r\ndo\r\n        mv ${line} $(printf \"%05d.jpg\\n\" ${seq})\r\n        let \"seq+=1\"\r\ndone <filelist<\/pre>\n<h2>Step 4 - Create the video<\/h2>\n<p>We want to output a video with 25 fps and want to simulate that the images are a video with 3 fps. If you want slower changes in the images, increase the \"-r 3\" to your wishes. If you want it quicker, you can decrease it down to \"-r 1\".<\/p>\n<pre lang=\"bash\">avconv -f image2 -r 3 -i %05d.jpg -r 25 out.mpg<\/pre>\n<h2>Step 5 - Upload to youtube<\/h2>\n<p>Make sure that you have the correct username and a channel created. This part is quite tricky, if you keep getting the 403-Error, make sure that you've logged in into youtube and you don't get any Captchas.<\/p>\n<pre lang=\"bash\">python youtube_upload.py --email=USERLOGIN --password=PASSWORD --title=\"The title\" --description=\"The description\" --category=Comedy --keywords=\"keywords\" out.mpg<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I had a big website with a lot of images embedded inside, which were dynamically added by users. The pictures were all of the same size, so I thought it would be easy to create a video out of it. Here are the steps to reproduce it: Step 0 &#8211; Prerequisites You&#8217;ll need python and &hellip; <a href=\"https:\/\/www.anginf.de\/?p=225\" class=\"more-link\"><span class=\"screen-reader-text\">Extract Images from a website and produce a video out of them<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":17,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}