{"id":785,"date":"2011-05-02T00:47:15","date_gmt":"2011-05-02T05:47:15","guid":{"rendered":"http:\/\/yourLinuxGuy.com\/?p=785"},"modified":"2011-04-24T20:38:13","modified_gmt":"2011-04-25T01:38:13","slug":"blackberry-sized-copies-of-dvd-chapters","status":"publish","type":"post","link":"https:\/\/yourLinuxGuy.com\/?p=785","title":{"rendered":"Blackberry-sized copies of DVD chapters in AVI format&#8230;"},"content":{"rendered":"<p>If you:<\/p>\n<ul>\n<li>Have a Blackberry<\/li>\n<li>Have a computer running Linux (preferably a recent suse-based distro)<\/li>\n<li>Have a DVD player in that computer<\/li>\n<li>Need to make mini copies of individual chapters of any given DVD<\/li>\n<\/ul>\n<p>&#8230;then this post is for you.\u00a0 Of course, I know this post will be of interest to about 5 people in the world besides me, but I&#8217;m going to do it anyway&#8230;.\u00a0 \ud83d\ude09<\/p>\n<p>I occasionally have a need to entertain a small child with some favorite children&#8217;s videos, featuring a particular small blue cartoon dog from a now-defunct children&#8217;s show.\u00a0 I don&#8217;t carry around a DVD player with me everywhere, but I *do* carry my Blackberry everywhere.\u00a0 So I created a script that will loop through a DVD and make individual AVI movies for each chapter on the DVD, so I can transfer them to my Blackberry and have them available any time I need them.\u00a0 I want to share that script with you.<\/p>\n<p>(Please note that I&#8217;ve been doing this on Opensuse 11.3 in the past, and now 11.4; so if you have a different version or distro, make sure to modify anything necessary to suit.)<\/p>\n<p>First, some pre-requisites&#8230;<\/p>\n<p><strong>Region<\/strong><\/p>\n<p>You may or may not have DVD region issues with your DVD player and discs, depending upon where you are located.\u00a0 I install and use a handy little <code>regionset<\/code> tool like this:<strong><br \/>\n<\/strong><\/p>\n<p><code>rpm -Uvh http:\/\/linvdr.org\/download\/regionset\/regionset-0.2-de.rpm<\/code><\/p>\n<p>&#8230;then run the <code>regionset<\/code> command and set your zone appropriately.\u00a0 Just know that the entire dialog is in German, and &#8220;j&#8221;=ja\/yes and &#8220;n&#8221;=nine\/no.<\/p>\n<p><strong>MPlayer\/Mencoder<\/strong><\/p>\n<p>You need to have the <code>mencoder<\/code> utility installed.\u00a0 This means you have to have the <code>MPlayer<\/code> package installed, and you probably need the Packman software repository set up.\u00a0 It&#8217;s hard for me to offer advice on how to go about this, because there are bunch of ways.\u00a0 Let me just give you the link to the &#8220;Restricted Formats&#8221; setup page:<\/p>\n<p><code>http:\/\/opensuse-community.org\/Restricted_formats\/11.4<\/code><\/p>\n<p>&#8230;and assume you have done the work necessary to have the <code>mencoder<\/code> utility.<\/p>\n<p><strong>lsdvd<\/strong><\/p>\n<p>I use the <code>lsdvd<\/code> utility to be able to know how many &#8220;chapters&#8221; there are for each DVD.\u00a0 Unfortunately, some DVDs have tiny little (one or two second) useless &#8220;chapters&#8221; that end up getting converted in this process, that you just delete later.\u00a0 But you still need to know how many chapters that the DVD itself shows are there.\u00a0 This is where the <code>lsdvd<\/code> utility comes in handy.\u00a0 You just install it with the following command:<\/p>\n<p><code>zypper in lsdvd<\/code><\/p>\n<p>&#8230;and run it with a simple <code>lsdvd<\/code> command.\u00a0 The results seem to be quite different from DVD to DVD, so I apparently cannot automate the parsing of the result for the script; and human parsing of the results is apparently mandatory.\u00a0 Oh well, one human step is not bad&#8230;.<\/p>\n<p><strong>The Mencoder Loop Script<\/strong><\/p>\n<p>Now that you&#8217;ve done all the leg work, let&#8217;s have some fun.\u00a0 Save the following script, *read it over*, do a <code>chmod +x<\/code> against it, and run it&#8230;<\/p>\n<pre><code>#!\/bin\/bash\r\n# Dont touch these variables\r\nDATE=`date +%Y%m%d%H%M%S`\r\nx=0\r\n# Get some input\r\nlsdvd\r\necho \"Look at the lsdvd output above to figure out the chapter count.\"\r\necho \"How many chapters are there?\"\r\nread CHAPTERS\r\necho \"Give me a short name (no spaces) to reference this dvd by...\"\r\nread SHORTNAME\r\n# Build the working folder\r\nWORKDIR=\"\/tmp\/dvd.$SHORTNAME.$DATE\"\r\nmkdir \"$WORKDIR\"\r\n# Now do the work\r\nwhile [ $x -lt $CHAPTERS ]\r\ndo\r\nlet x=x+1\r\necho \"Now dumping Chapter $x...\"\r\nmencoder dvd:\/\/1 -chapter $x-$x -vf crop=704:464:8:6,scale=320:240 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -alang en -oac mp3lame -lameopts br=96:cbr:vol=1 -o \"\/$WORKDIR\/$SHORTNAME-chapter$x-phone.avi\"\r\nsleep 1\r\ndone\r\n# All done!\r\neject cdrom<\/code><\/pre>\n<p>So to summarize the script:\u00a0 It asks you how many chapters (to determine how many times to loop) and for a logical name (for naming the work folder and filenames); it builds the work folder; then it loops through all the chapters on the DVD, encoding them in AVI format in a small size that should be perfect for BlackBerries.<\/p>\n<p>Of course, all the magic is really in the <code>mencoder<\/code> line, and there are a lot of options I&#8217;ve settled on over time&#8230; like small Blackberry screen size, and volume at 1 or 2 (depending on what I&#8217;m converting), etc.;\u00a0 I strongly encourage you to jump in and read the docs to be sure you tune it to taste.<\/p>\n<p>And that should do it&#8230;\u00a0 Happy viewing!<\/p>\n<p>\ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you: Have a Blackberry Have a computer running Linux (preferably a recent suse-based distro) Have a DVD player in that computer Need to make mini copies of individual chapters of any given DVD &#8230;then this post is for you.\u00a0&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/yourLinuxGuy.com\/?p=785\">Read more<\/a><\/p>\n","protected":false},"author":5,"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":""},"categories":[12,104,105],"tags":[],"class_list":["post-785","post","type-post","status-publish","format-standard","hentry","category-advanced","category-blackberry","category-mencoder"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnjn1-cF","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=785"}],"version-history":[{"count":10,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}