Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg not copying all audio streams

I'm having trouble getting ffmpeg to copy all audio streams from a .mp4 file. After hours of searching online, it appears this should copy all streams (as shown in example 4 here):

ffmpeg -i in.mp4 -map 0 -c copy out.mp4 

in.mp4 contains 3 streams:

  • Video
  • Audio track 1
  • Audio track 2

out.mp4 (which should be identical to in.mp4) contains only 2 streams:

  • Video
  • Audio track 1

FFmpeg does appear to correctly identify all 3 streams, but doesn't copy all of them over. Output from FFmpeg:

Stream mapping:   Stream #0:0 -> #0:0 (copy)   Stream #0:1 -> #0:1 (copy)   Stream #0:2 -> #0:2 (copy) 

Edit: Output from ffmpeg -v 9 -loglevel 99 -i in.mp4:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from in.mp4':   Metadata:     major_brand     : isom     minor_version   : 512     compatible_brands: isomiso2avc1mp41     encoder         : Lavf57.36.100   Duration: 00:00:06.03, start: 0.000000, bitrate: 5582 kb/s     Stream #0:0(und), 1, 1/15360: Video: h264 (Main), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, left), 1920x1080 (0x0) [SAR 1: 1 DAR 16:9], 0/1, 5317 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)     Metadata:       handler_name    : VideoHandler     Stream #0:1(und), 1, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,  stereo, fltp, 128 kb/s (default)     Metadata:       handler_name    : SoundHandler     Stream #0:2(und), 1, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,  stereo, fltp, 128 kb/s     Metadata:       handler_name    : SoundHandler Successfully opened the file. At least one output file must be specified [AVIOContext @ 0000000001c2b9e0] Statistics: 153350 bytes read, 2 seeks 

Edit 2 (solved): I managed to find the correct syntax from this ticket. For any others that are interested, the correct syntax is:

ffmpeg -i in.mp4 -vcodec copy -c:a copy -map 0 out.mp4

This will copy all streams.

like image 820
Dotl Avatar asked Jun 14 '16 19:06

Dotl


People also ask

How do I copy a FFmpeg stream?

-map 0 tells ffmpeg to all streams from input 0 (the first input) in the output file. -c:a copy -c:s copy will copy over any audio and subtitle streams present.

Does FFmpeg have audio?

ffmpeg has a default stream selection behavior that will select 1 stream per stream type (1 video, 1 audio, 1 subtitle, 1 data).

What does Copy do in FFmpeg?

-c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.

What is FFmpeg command?

FFmpeg MOV to MP4 (Convert Video/Audio to Another Format) FFmpeg is extremely useful to convert your video file to another format. For example, to convert MOV to MP4 with FFmpeg, run the command below. ffmpeg -i input.mov output.mp4. Similarly, you can transcode audio files with FFmpeg by specifying the output format.


1 Answers

FFmpeg have option to map all streams to output, you have to use option -map 0 to map all streams from input to output.

In full line it might look like:

ffmpeg -i in.mp4 -c copy -map 0 out.mp4 

For more info see the documentation on stream selection and the -map option.

like image 75
PRIHLOP Avatar answered Oct 08 '22 11:10

PRIHLOP