{"id":253,"date":"2016-09-18T08:44:47","date_gmt":"2016-09-18T07:44:47","guid":{"rendered":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=253"},"modified":"2016-11-27T00:31:13","modified_gmt":"2016-11-26T23:31:13","slug":"how-to-crop-and-split-a-movie","status":"publish","type":"post","link":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=253","title":{"rendered":"How to crop and split a movie"},"content":{"rendered":"<h3>Cropping<\/h3>\n<p>I just leaned about a very valuable feature of mplayer: you can graphically determine the crop region with -vf rectangle!<\/p>\n<p>To do so, create a new config file with this:<\/p>\n<pre class=\"file\">RIGHT change_rectangle 2  10\r\nLEFT  change_rectangle 2 -10\r\nUP    change_rectangle 3 -10\r\nDOWN  change_rectangle 3  10\r\nKP6   change_rectangle 0  10\r\nKP4   change_rectangle 0 -10\r\nKP8   change_rectangle 1  10\r\nKP2   change_rectangle 1 -10<\/pre>\n<p>Then view the movie with<\/p>\n<pre>$ mplayer -vf rectangle\u00a0-input conf=&lt;\/path\/to\/conf&gt; &lt;movie_file&gt;<\/pre>\n<p>You&#8217;ll see a white rectangle in the view area. Change the size with the keypad and the position with the cursor keys. The keypad down key\u00a0enlarges the height, keypad down reduces it. Keypad left reduces the width, keypad right enlarges it.<\/p>\n<p>Once you&#8217;re done, quit mplayer and use the rectangle geometry as crop parameter for ffmpeg:<\/p>\n<pre>$ ffmpeg -vf crop=&lt;rectangle_data&gt; ...<\/pre>\n<h3>Splitting<\/h3>\n<p>Splitting isn&#8217;t as easy as it seems. You need 2 parameters:<\/p>\n<ul>\n<li>-ss hh:mm:ss<\/li>\n<li>-t hh:mm:ss<\/li>\n<\/ul>\n<p>The latter is <strong>not<\/strong> a position in the file, but a duration! So, if you want to cut out everything from position 00:33:42 to 00:46:43, use -ss 00:33:42 -t 00:13:01 (33:42 + 13:02 = 46:43).<\/p>\n<p>Also, -ss is a positional parameter. Use it as an input parameter, i.e. <strong>before<\/strong> -i if you don&#8217;t want silence and a black screen up front!<\/p>\n<h3>Example<\/h3>\n<p>Split out 13:02 minutes from position 33:42:<\/p>\n<pre>$ mplayer -ss 00:33:42 -t 00:13:02 -i &lt;source&gt; -acodec copy -vcodec copy out.file<\/pre>\n<p>Use the rectangle feature:<\/p>\n<pre>$ mplayer -vf rectangle -input conf=&lt;\/path\/to\/conf&gt; in.file<\/pre>\n<p>Reencode the split movie to mkv with the rectangle data:<\/p>\n<pre>$ ffmpeg -i &lt;in.file&gt; -acodec copy -vcodec\u00a0libx264 -preset slow -threads 0 -x264opts fast_pskip=0:crf=21 &lt;out.mkv&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Cropping I just leaned about a very valuable feature of mplayer: you can graphically determine the crop region with -vf rectangle! To do so, create a new config file with this: RIGHT change_rectangle 2 10 LEFT change_rectangle 2 -10 UP change_rectangle 3 -10 DOWN change_rectangle 3 10 KP6 change_rectangle 0 10 KP4 change_rectangle 0 -10 &hellip; <a href=\"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=253\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to crop and split a movie<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[64,48,65,66],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-transcoding","tag-crop","tag-ffmpeg","tag-mplayer","tag-split"],"_links":{"self":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=253"}],"version-history":[{"count":2,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}