Changes between Initial Version and Version 1 of Map


Ignore:
Timestamp:
Aug 2, 2012, 11:43:42 AM (7 years ago)
Author:
burek
Comment:

Created the page

Legend:

Unmodified
Added
Removed
Modified
  • Map

    v1 v1  
     1= Introduction =
     2
     3The best way to understand [http://ffmpeg.org/ffmpeg.html#Advanced-options -map option] is to think of it like a way to tell FFmpeg which streams do you want to select/copy from input to output.
     4
     5'''The order of -map options, specified on cmd line, will create the same order of streams in the output file.'''
     6
     7Here are several examples.
     8
     9== Input file ==
     10
     11In all following examples, we will use an example input file like this one:
     12
     13{{{
     14# fmpeg -i input.mkv
     15
     16ffmpeg version ... Copyright (c) 2000-2012 the FFmpeg developers
     17...
     18Input #0, matroska,webm, from 'input.mkv':
     19  Duration: 01:39:44.02, start: 0.000000, bitrate: 5793 kb/s
     20    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x800, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
     21    Stream #0:1(ger): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
     22    Stream #0:2(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
     23    Stream #0:3(ger): Subtitle: text (default)
     24At least one output file must be specified
     25
     26#
     27}}}
     28
     29== Example 1 ==
     30
     31Now, let's say we wan't to:
     32- copy video stream
     33- encode german audio stream to mp3 (128kbps) and aac (96kbps) (creating 2 audio streams in the output)
     34- drop english audio stream
     35- copy subtitle stream
     36
     37This can be done using the following FFmpeg command line:
     38
     39{{{
     40ffmpeg -i input.mkv \
     41    -map 0:0 -map 0:1 -map 0:1 -map 0:3 \
     42    -c:v copy \
     43    -c:a:0 libmp3lame -b:a:0 128k \
     44    -c:a:1 libfaac -b:a:1 96k \
     45    -c:s copy \
     46    output.mkv
     47}}}
     48
     49''Note there is no "-map 0:2" and that "-map 0:1" has been specified twice.''
     50
     51Using "-map 0:0 -map 0:1 -map 0:1 -map 0:3" we told FFmpeg to select/map specified input streams to output in that order.
     52
     53So, our output will now have the following streams:
     54
     55{{{
     56Output #0, matroska, to 'output.mkv':
     57    Stream #0:0(eng): Video ...
     58    Stream #0:1(ger): Audio ...
     59    Stream #0:2(ger): Audio ...
     60    Stream #0:3(ger): Subtitle ...
     61}}}
     62
     63After we selected which streams we would like in our output, using "-map" option, we specified codecs for each stream in our output.
     64
     65Video and subtitle stream have just been copied and german audio stream has been encoded to 2 new audio streams, mp3 and aac.
     66
     67We used "-c:a:0" to specify codec for the output's first AUDIO stream and "-c:a:1" to specify codec for the output's second AUDIO stream.
     68
     69''Note that "a:0" refers to the output's first AUDIO stream (`#`0:1 in our case), "a:1" refers to the output's 2nd AUDIO stream (`#`0:2 in our case), etc.''
     70
     71The result will be:
     72
     73{{{
     74Output #0, matroska, to 'output.mkv':
     75    Stream #0:0(eng): Video ...
     76    Stream #0:1(ger): Audio ...
     77    Stream #0:2(ger): Audio ...
     78    Stream #0:3(ger): Subtitle ...
     79Stream mapping:
     80  Stream #0:0 -> #0:0 (copy)
     81  Stream #0:1 -> #0:1 (dca -> libmp3lame)
     82  Stream #0:2 -> #0:2 (dca -> libfaac)
     83  Stream #0:3 -> #0:3 (copy)
     84}}}
     85
     86== Example 2 ==
     87
     88Let's say that we want to reorder input streams backwards, so that we have output like this:
     89
     90{{{
     91    Stream #0:0(ger): Subtitle: text (default)
     92    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
     93    Stream #0:2(ger): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
     94    Stream #0:3(eng): Video: h264 (High), yuv420p, 1920x800, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
     95}}}
     96
     97This can simply be done using the following command line:
     98
     99{{{
     100ffmpeg -i input.mkv -map 0:3 -map 0:2 -map 0:1 -map 0:0 -c copy output.mkv
     101}}}
     102
     103''Note that we specified all the input streams, but in the reverse order, which causes that order to be respected in the output.''
     104
     105The option "-c copy" tells FFmpeg to use "copy" on all streams.
     106
     107== Example 3 ==
     108
     109If we want to extract only audio streams, from input file, then we can do it like this:
     110
     111{{{
     112ffmpeg -i input.mkv -map 0:1 -map 0:2 -c copy output.mkv
     113}}}