{"id":1184,"date":"2012-02-17T01:14:00","date_gmt":"2012-02-16T21:14:00","guid":{"rendered":"http:\/\/sandalov.org\/blog\/?p=1184"},"modified":"2012-02-17T11:35:23","modified_gmt":"2012-02-17T07:35:23","slug":"convert-video-to-html5-in-ubuntu","status":"publish","type":"post","link":"https:\/\/sandalov.org\/blog\/1184\/","title":{"rendered":"Convert Video to HTML5 in Ubuntu"},"content":{"rendered":"<div class=\"2d836d85a73757df15d0de19d7bef594\" data-index=\"1\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-2287684400845931\";\r\n\/* valerymorozov *\/\r\ngoogle_ad_slot = \"5606708872\";\r\ngoogle_ad_width = 728;\r\ngoogle_ad_height = 90;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n<p>I wanted an easy way to convert videos to HTML5 formats (mp4\/ogg\/webm). With Linux, I could easily create a bash script to do all three and even create a screencap for the poster attribute.<\/p>\n<p>The install process is a bit tedious and time consuming, but after it\u2019s all installed you\u2019re good to run the script for all your videos. The script uses ffmpeg to convert to all 3 formats, and it supports most any video format. The script also uses ffmpeg to generate a random screenshot, and even writes the HTML5 code for you.<\/p>\n<p><strong>Installation<\/strong><\/p>\n<p>For the most part, this portion of the tutorial was derived from the <a href=\"http:\/\/ubuntuforums.org\/showpost.php?p=9868359&amp;postcount=1289\" target=\"_blank\">Ubuntu Forums<\/a>.<\/p>\n<ol>\n<li>Uninstall Old Versions<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get remove ffmpeg x264 libx264-dev yasm<\/pre>\n<li>Install Dependencies and Install Tools<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get update\r\nsudo apt-get install build-essential git-core checkinstall texi2html libfaac-dev \\\r\n    libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev \\\r\n    libvorbis-dev libx11-dev libxfixes-dev zlib1g-dev<\/pre>\n<li>Install Yasm<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd ~\/Downloads\r\nwget http:\/\/www.tortall.net\/projects\/yasm\/releases\/yasm-1.2.0.tar.gz\r\ntar xzvf yasm-1.2.0.tar.gz\r\ncd yasm-1.2.0\r\n.\/configure\r\nmake\r\nsudo checkinstall --pkgname=yasm --pkgversion=&quot;1.2.0&quot; --backup=no --deldoc=yes --default<\/pre>\n<li>Install x264<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd ~\/Downloads\r\ngit clone git:\/\/git.videolan.org\/x264\r\ncd x264\r\n.\/configure --enable-static\r\nmake\r\nsudo mkdir \/usr\/local\/lib\/pkgconfig\r\nsudo checkinstall --pkgname=x264 --default --pkgversion=&quot;3:$(.\/version.sh | \\\r\n    awk -F'&#x5B;&quot; ]' '\/POINT\/{print $4&quot;+git&quot;$5}')&quot; --backup=no --deldoc=yes<\/pre>\n<li>Install LAME<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get remove libmp3lame-dev\r\nsudo apt-get install nasm\r\ncd ~\/Downloads\r\nwget http:\/\/downloads.sourceforge.net\/project\/lame\/lame\/3.99\/lame-3.99.tar.gz\r\ntar xzvf lame-3.99.tar.gz\r\ncd lame-3.99\r\n.\/configure --enable-nasm --disable-shared\r\nmake\r\nsudo mkdir \/usr\/local\/share\/doc\r\nsudo mkdir \/usr\/local\/share\/doc\/lame\r\nsudo checkinstall --pkgname=lame-ffmpeg --pkgversion=&quot;3.99&quot; --backup=no --default \\\r\n    --deldoc=yes<\/pre>\n<li>Install libvpx<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd ~\/Downloads\r\ngit clone http:\/\/git.chromium.org\/webm\/libvpx.git\r\ncd libvpx\r\n.\/configure\r\nmake\r\nsudo checkinstall --pkgname=libvpx --pkgversion=&quot;$(date +%Y%m%d%H%M)-git&quot; --backup=no \\\r\n    --default --deldoc=yes<\/pre>\n<li>Install ffmpeg<\/li>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd ~\/Downloads\r\ngit clone --depth 1 git:\/\/source.ffmpeg.org\/ffmpeg\r\ncd ffmpeg\r\n.\/configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \\\r\n    --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx \\\r\n    --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab\r\nmake\r\nsudo checkinstall --pkgname=ffmpeg --pkgversion=&quot;$(date +%Y%m%d%H%M)-git&quot; --backup=no \\\r\n    --deldoc=yes --default<\/pre>\n<p>The part that will take the longest is the ffmpeg, so be prepared to wait.<\/p>\n<p><strong>The Script<\/strong><\/p>\n<p>Usage:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">.\/convertHTML5 video-file.ext<\/pre>\n<p>The script will output \u201cvideo-file.ogv\u201d, \u201cvideo-file.webm\u201d, \u201cvideo-file.mp4\u2033, and \u201cvideo-file.html\u201d while keeping the original video intact. The HTML document just has the plain &#60;video&#62; code with nothing else, easily copied and pasted.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#!\/bin\/bash\r\n\r\nif &#x5B;&#x5B; $1 ]]\r\nthen\r\n    filename=$(basename &quot;$1&quot;)\r\n    filename=${filename%.*}\r\n    directory=$(dirname &quot;$1&quot;)\r\n\r\n    duration=$(ffmpeg -i &quot;$1&quot; 2&gt;&amp;1 | grep Duration | awk '{print $2}' | tr -d ,)\r\n    minutes=${duration%:*}\r\n    hours=${minutes%:*}\r\n    minutes=${minutes##*:}\r\n    seconds=${duration##*:}\r\n    seconds=${seconds%.*}\r\n\r\n    hours=$((hours*3600))\r\n    minutes=$((minutes*60))\r\n\r\n    total=$(expr $hours + $minutes + $seconds)\r\n    number=$RANDOM\r\n    let &quot;number %= $total&quot;\r\n\r\n    echo &quot;Generating thumbnail&quot;\r\n    ffmpeg -i &quot;$1&quot; -deinterlace -an -ss $number -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg &quot;$directory\/$filename.jpg&quot; 2&gt;&amp;1\r\n    echo &quot;Converting $filename to ogv&quot;\r\n    ffmpeg -i &quot;$1&quot; -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k &quot;$directory\/$filename.ogv&quot;\r\n    echo &quot;Finished ogv&quot;\r\n\r\n    echo &quot;Converting $filename to webm&quot;\r\n    ffmpeg -i &quot;$1&quot; -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k &quot;$directory\/$filename.webm&quot;\r\n    echo &quot;Finished webm&quot;\r\n\r\n    echo &quot;Converting $filename to h264&quot;\r\n    ffmpeg -i &quot;$1&quot; -acodec libfaac -ab 96k -vcodec libx264 -level 21 -refs 2 -b 345k -bt 345k -threads 0 &quot;$directory\/$filename.mp4&quot;\r\n    echo &quot;Finished h264&quot;\r\n\r\n    echo &quot;Writing HTML...&quot;\r\n\r\n    echo &quot;&lt;\/pre&gt;\r\n&lt;video width=&quot;320&quot; height=&quot;240&quot; controls=&quot;controls&quot; poster=&quot;\\&amp;quot;$filename.jpg\\&amp;quot;&quot; preload=&quot;&quot;&gt;&lt;source src=&quot;\\&amp;quot;$filename.ogv\\&amp;quot;&quot; type=&quot;\\&amp;quot;video\/ogg\\&amp;quot;&quot; \/&gt;&lt;source src=&quot;\\&amp;quot;$filename.webm\\&amp;quot;&quot; type=&quot;\\&amp;quot;video\/webm\\&amp;quot;&quot; \/&gt;&lt;source src=&quot;\\&amp;quot;$filename.mp4\\&amp;quot;&quot; type=&quot;\\&amp;quot;video\/mp4\\&amp;quot;&quot; \/&gt;&quot; &gt; &quot;$directory\/$filename.html&quot;\r\n echo &quot; &quot; &gt;&gt; &quot;$directory\/$filename.html&quot;\r\n echo &quot; &quot; &gt;&gt; &quot;$directory\/$filename.html&quot;\r\n echo &quot; &quot; &gt;&gt; &quot;$directory\/$filename.html&quot;\r\n echo &quot; Sorry, your browser does not support HTML5 video&quot; &gt;&gt; &quot;$directory\/$filename.html&quot;\r\n echo &quot;&lt;\/video&gt;\r\n&lt;pre&gt;&quot; &gt;&gt; &quot;$directory\/$filename.html&quot;\r\n\r\n    echo &quot;All Done!&quot;\r\nelse\r\n    echo &quot;Usage: &#x5B;filename]&quot;\r\nfi<\/pre>\n<p>Credits: <a href=\"http:\/\/jaswin.net\/code\/convert-video-to-html5-in-ubuntu\/\" target=\"_blank\">McSwindler<\/a><\/p>\n<div class=\"2d836d85a73757df15d0de19d7bef594\" data-index=\"1\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-2287684400845931\";\r\n\/* valerymorozov *\/\r\ngoogle_ad_slot = \"5606708872\";\r\ngoogle_ad_width = 728;\r\ngoogle_ad_height = 90;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I wanted an easy way to convert videos to HTML5 formats (mp4\/ogg\/webm). With Linux, I could easily create a bash script to do all three and even create a screencap for the poster attribute. The install process is a bit tedious and time consuming, but after it\u2019s all installed you\u2019re &hellip; <a class=\"continue-reading-link\" href=\"https:\/\/sandalov.org\/blog\/1184\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","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":[1],"tags":[181,240,241,40,242,243,244,379,245,246],"class_list":["post-1184","post","type-post","status-publish","format-standard","hentry","category-unsorted","tag-ffmpeg","tag-h264","tag-html5","tag-linux","tag-mp4","tag-ogg","tag-theora","tag-ubuntu","tag-video","tag-webm"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/1184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/comments?post=1184"}],"version-history":[{"count":17,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/1184\/revisions"}],"predecessor-version":[{"id":1203,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/posts\/1184\/revisions\/1203"}],"wp:attachment":[{"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/media?parent=1184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/categories?post=1184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sandalov.org\/blog\/wp-json\/wp\/v2\/tags?post=1184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}