{"id":605,"date":"2021-03-10T09:28:28","date_gmt":"2021-03-10T14:28:28","guid":{"rendered":"https:\/\/www.unliterate.net\/?p=605"},"modified":"2021-03-10T09:28:28","modified_gmt":"2021-03-10T14:28:28","slug":"smaller-mkv-with-ffmpeg","status":"publish","type":"post","link":"https:\/\/www.unliterate.net\/index.php\/2021\/03\/10\/smaller-mkv-with-ffmpeg\/","title":{"rendered":"Smaller mkv with ffmpeg"},"content":{"rendered":"\n<p>When you run a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.plex.tv\/\" target=\"_blank\">Plex Media Server<\/a> you know that family and friends ask for specific content to be placed on it so they can watch it. It comes down that a &#8220;popular&#8221; series just finished up all 9 of their episodes and the wanted it to exist on our Plex. I was able to find the asked content, but was a bit surprised when the video content was a spectacular 1080p but the audio content defaulted to Brazilian Portuguese.<\/p>\n\n\n\n<p>Lucky for me there was an English audio stream as well, but I felt it annoying that if I wanted to start watching this and have to swap to the secondary audio track every time. With the power of <a rel=\"noreferrer noopener\" href=\"https:\/\/www.ffmpeg.org\/\" target=\"_blank\">ffmpeg<\/a>[<a href=\"https:\/\/johnvansickle.com\/ffmpeg\/\" target=\"_blank\" rel=\"noreferrer noopener\">static<\/a>] and a couple smart command-line parameters I was able to re-make my videos with English as the default language and cut out all the unnecessary data.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>First thing was to run ffprobe on the file and see the output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ffprobe Filename.mkv\r\nffprobe version 4.2.1-static https:\/\/johnvansickle.com\/ffmpeg\/  Copyright (c) 2007-2019 the FFmpeg developers\r\n  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516\r\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\r\n  libavutil      56. 31.100 \/ 56. 31.100\r\n  libavcodec     58. 54.100 \/ 58. 54.100\r\n  libavformat    58. 29.100 \/ 58. 29.100\r\n  libavdevice    58.  8.100 \/ 58.  8.100\r\n  libavfilter     7. 57.100 \/  7. 57.100\r\n  libswscale      5.  5.100 \/  5.  5.100\r\n  libswresample   3.  5.100 \/  3.  5.100\r\n  libpostproc    55.  5.100 \/ 55.  5.100\r\nInput #0, matroska,webm, from 'Filename.mkv':\r\n  Metadata:\r\n    title           : Filename\r\n    creation_time   : 2021-01-15T09:31:57.000000Z\r\n    ENCODER         : Lavf58.29.100\r\n  Duration: 00:26:33.02, start: 0.000000, bitrate: 2591 kb\/s\r\n    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1920x1080 &#91;SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 180k tbc (default)\r\n    Metadata:\r\n      DURATION        : 00:26:33.013000000\r\n    Stream #0:1(por): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb\/s (default)\r\n    Metadata:\r\n      title           :\r\n      DURATION        : 00:26:33.024000000\r\n    Stream #0:2(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb\/s\r\n    Metadata:\r\n      title           :\r\n      DURATION        : 00:26:33.024000000\r\n    Stream #0:3(por): Subtitle: ass\r\n    Metadata:\r\n      title           : Brazilian Portuguese\r\n      DURATION        : 00:26:30.679000000\r\n<\/code><\/pre>\n\n\n\n<p>The output shows me 4 streams: 1 video stream, 2 audio streams, and 1 subtitle stream.<\/p>\n\n\n\n<p>ffmpeg allows us to be able to &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/trac.ffmpeg.org\/wiki\/Map\" target=\"_blank\">map<\/a>&#8221; specific streams between input and output, and with this we&#8217;ll tell ffmpeg to use stream 0 for our &#8220;video&#8221;, steam 2 (index 1) as our audio stream, and that we do not want the Portuguese subtitles.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ffmpeg -i Filename.mkv -vcodec copy -acodec copy -map 0:v:0 -map 0:a:1 -sn new-Filename.mkv<\/code><\/pre>\n\n\n\n<p>This happens very fast since the data is already there and we&#8217;re telling ffmpeg not to transcode it in any way.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ffprobe new-Filename.mkv\r\nffprobe version 4.2.1-static https:\/\/johnvansickle.com\/ffmpeg\/  Copyright (c) 2007-2019 the FFmpeg developers\r\n  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516\r\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\r\n  libavutil      56. 31.100 \/ 56. 31.100\r\n  libavcodec     58. 54.100 \/ 58. 54.100\r\n  libavformat    58. 29.100 \/ 58. 29.100\r\n  libavdevice    58.  8.100 \/ 58.  8.100\r\n  libavfilter     7. 57.100 \/  7. 57.100\r\n  libswscale      5.  5.100 \/  5.  5.100\r\n  libswresample   3.  5.100 \/  3.  5.100\r\n  libpostproc    55.  5.100 \/ 55.  5.100\r\nInput #0, matroska,webm, from 'new-Filename.mkv':\r\n  Metadata:\r\n    title           : COMANDO.TO\r\n    ENCODER         : Lavf58.29.100\r\n  Duration: 00:26:33.02, start: 0.000000, bitrate: 2397 kb\/s\r\n    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1920x1080 &#91;SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 180k tbc (default)\r\n    Metadata:\r\n      DURATION        : 00:26:33.012000000\r\n    Stream #0:1(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb\/s\r\n    Metadata:\r\n      title           :\r\n      DURATION        : 00:26:33.024000000<\/code><\/pre>\n\n\n\n<p>In regards to saving space with removing all the junk data I had to do the same conversion over 9 files. The smallest and largest file before\/after was the following:<\/p>\n\n\n\n<p>Smallest before: 516,127,446, after: 477,507,693, savings of 38,619,753 or <strong>7.4%<\/strong><\/p>\n\n\n\n<p>Largest before: 2,806,175,671, after: 2,716,594,097, savings of 89,581,574 or <strong>3.1%<\/strong><\/p>\n\n\n\n<p>Any space saved is a blessing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you run a Plex Media Server you know that family and friends ask for specific content to be placed on it so they can watch it. It comes down that a &#8220;popular&#8221; series just finished up all 9 of their episodes and the wanted it to exist on our Plex. I was able to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,17],"tags":[],"class_list":["post-605","post","type-post","status-publish","format-standard","hentry","category-geek-instructions","category-linux"],"_links":{"self":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/comments?post=605"}],"version-history":[{"count":1,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/605\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/605\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/media?parent=605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/categories?post=605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/tags?post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}