2

I want to copy all the streams (including cover art) except the first video stream from one MP4 file to another, here is what I do :

$ time ffmpeg -hide_banner -i toto1.mp4 -map 0 -vn -c:v:1 copy -c copy toto2.mp4 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5655577ffd00] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'toto1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : LA GRACE by ISRAEL KINDOMBA
    artist          : Israel Kindomba
    comment         : Soyez édifiés par ces déclarations sur la grâce...
    date            : 20170421
    description     : http://www.youtube.com/watch?v=tt1yUlqoB-U
    encoder         : Lavf58.20.100
  Duration: 00:08:21.29, start: 0.000000, bitrate: 443 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 332 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
    Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:3(fra): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:4(spa): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:5(deu): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:6: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 480x360 [SAR 1:1 DAR 4:3], 90k tbr, 90k tbn, 90k tbc
Output #0, mp4, to 'toto2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : LA GRACE by ISRAEL KINDOMBA
    artist          : Israel Kindomba
    comment         : Soyez édifiés par ces déclarations sur la grâce...
    date            : 20170421
    description     : http://www.youtube.com/watch?v=tt1yUlqoB-U
    encoder         : Lavf58.20.100
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
    Stream #0:1(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:2(fra): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:3(spa): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:4(deu): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:2 -> #0:1 (copy)
  Stream #0:3 -> #0:2 (copy)
  Stream #0:4 -> #0:3 (copy)
  Stream #0:5 -> #0:4 (copy)
Press [q] to stop, [?] for help
size=    6026kB time=00:08:21.10 bitrate=  98.5kbits/s speed=1.18e+03x    
video:0kB audio:5873kB subtitle:44kB other streams:0kB global headers:0kB muxing overhead: 1.828688%

real    0m0.583s
user    0m0.524s
sys 0m0.060s

As you can see in the Stream mapping: the input Stream #0:6: Video: mjpeg stream has not been copied.

Can you help me ?

3 Answers 3

5

-map 0 will map all streams from the first input. A negative mapping can then be applied to disable an already mapped stream.

So,

ffmpeg -i toto1.mp4 -map 0 -map -0:v:0 -c copy toto2.mp4
1

As someone already replied, -map 0 is used to grab everything from the first given input, in your case -i toto1.mp4.

To achieve what you want you can remove a specific stream this way (notice the - sign):

-map -0:0 which removes the first stream of the input
or
-map -0:v:0 which removes the first video stream of the input

But if you need to remove the second video from the input:

-map -0:6 which removes the sixth stream of the input
or
-map -0:v:1 which remove the second video stream of the input


More info:

0

Found the answer, I had to remove -vn and explicitly select all the streams I wanted to copy except the one I didn't want :

$ ffmpeg -hide_banner -i toto1.mp4 -map 0:a -map 0:s -map 0:v:1 -c copy toto2.mp4
....
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:2 -> #0:1 (copy)
  Stream #0:3 -> #0:2 (copy)
  Stream #0:4 -> #0:3 (copy)
  Stream #0:5 -> #0:4 (copy)
  Stream #0:6 -> #0:5 (copy)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 Lsize=    6038kB time=00:08:21.10 bitrate=  98.7kbits/s speed=1.07e+03x    
video:12kB audio:5873kB subtitle:44kB other streams:0kB global headers:0kB muxing overhead: 1.825498%

The input Stream #0:6: Video: mjpeg has been copied :-)

2
  • -map 0 -map -0:v:0 will preserve original stream order if the other tracks are interspersed.
    – Gyan
    Commented Apr 7, 2019 at 7:19
  • @Gyan I LOVE your solution, can you please convert it to an answer ?
    – SebMa
    Commented Apr 7, 2019 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.