Skip to content
TheChatArchiveThe Chat Archive
o4-mini-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

I'm using ffmpeg to splt and merge streams. I create videos with multiple audio streams…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    I'm using ffmpeg to splt and merge streams. I create videos with multiple audio streams and no player allows me to mix those streams in the output, so I have to extract all but one, to use it in my web-based mixer, since JS currently cannot handle multiple audio tracks in a video file. The basic command is ffmpeg -i something.mkv -map 0:2 -c copy something_2.aac -map 0:3 -c copy something_3.aac to extract audio #2 and #3 into separate files On the other hand I sometimes assemble a single media file from multiple single stream files where I just copy together the streams. This command I don't quite remember but does not contain -map, but does contain -c:a Both commands were tried and worked. Since I'm using them quite often it is time for me to understand these command line options and what can one do with them, what they mean. Your task is to explain . Do not extend the task I'm just interested in no-reencoding disassemlbe and assemle operations.

  2. Assistant

    Here’s a concise breakdown of the two “no‐reencode” workflows you described—“disassemble” (extract streams) and “assemble” (mux streams)—and what the key ffmpeg options actually do.


    1. Disassemble (extract individual streams)

    You already use:

    ffmpeg -i something.mkv \
      -map 0:2 -c copy something_2.aac \
      -map 0:3 -c copy something_3.aac
    

    What’s going on here?

    • -i something.mkv
    your input file (index 0).

    • -map 0:2
    “take stream 2 from input 0.”
    Streams are zero-based; you can also list them via ffprobe something.mkv.

    • -c copy
    “codec = copy” — no re-encode, just dump the stream as‐is.
    (Equivalent to -codec copy or more specifically for audio: -c:a copy.)

    • something_2.aac
    the output filename/format. ffmpeg infers container/codec from the extension.

    Repeat for each stream you want to pull out.


    2. Assemble (mux multiple single-stream files into one container)

    Assume you have:

    • video.h264
    • audio_eng.aac
    • audio_jpn.aac

    You can merge them like this:

    ffmpeg \
      -i video.h264 \
      -i audio_eng.aac \
      -i audio_jpn.aac \
      -map 0:0 \        # video from input 0
      -map 1:0 \        # first audio from input 1
      -map 2:0 \        # second audio from input 2
      -c copy merged.mkv
    

    What’s new here?

    • Multiple -i: you list each source file (each becomes input 0, 1, 2 …).

    • -map X:0:
    “take the first (0-th) stream from input X.”
    (If your files contain only one stream each, that’s always stream 0.)

    • A single -c copy after all your -map lines tells ffmpeg to copy every mapped stream (video and audio) without re-encoding.


    A few extra tips

    1. “Copy all streams from input N”
      You can shortcut -map N:0 -map N:1 … by doing
      -map N   # means “map every stream from input N”
      
    2. Selective codecs
      If you ever want to mix copying and re-encoding (not in your current use case), you can do:
      -c:v copy    # copy video
      -c:a aac     # re-encode audio to AAC
      
    3. Default mapping
      If you omit all -map options, ffmpeg grabs “one of each type” from the first input—usually not what you want for precise stream control.

    Quick‐reference summary

    OptionMeaning
    -i fileinput file (assigned an input-index: 0,1,2…)
    -map i:jpick stream #j from input #i
    -map ipick all streams from input #i
    -c copycopy every mapped stream (no re-encode)
    -c:v copycopy only video streams
    -c:a copycopy only audio streams

    With just these few flags you can disassemble any container into its raw streams and re-assemble them into a new container, all without touching the bit-streams themselves. 🎬🎧

    Let me know if you’ve got follow-up questions!

  3. User

    Now I try to remember the assembly command line ffmpeg -i just_video.mp4 -i just_audio.aac -c:a copy -c:v copy assembled.mkv Can i be correct? Also there was some deliberation of which container format to use for the output if I insist on copying without reencoding. Expand on that.

  4. Assistant

    Your recall is basically spot-on. If you have a video-only MP4 and a raw AAC file and just want to “glue” them together without re-encoding, something like this will work:

    ffmpeg \
      -i just_video.mp4 \
      -i just_audio.aac \
      -map 0:v        \   # take the video stream from input #0
      -map 1:a        \   # take the audio stream from input #1
      -c:v copy      \    # copy video as-is
      -c:a copy      \    # copy audio as-is
      assembled.mkv
    

    Notes:

    1. Explicit -map is good practice—even if there’s only one stream in each file—so you know exactly what’s going into your output.
    2. We chose .mkv here because it’s the most forgiving container for “raw” streams.

    Container-vs-codec compatibility

    Not every container will accept every codec in copy-mode. Below is a quick compatibility guide:

    ContainerVideo CodecsAudio CodecsRemarks
    MKVH.264/AVC, HEVC/H.265, VP9, MPEG-2…AAC, MP3, AC-3, DTS, Opus…Very flexible
    MP4/MOVH.264/AVC, HEVC/H.265, MPEG-4 Part 2…AAC, MP3, AC-3 (limited)…Ubiquitous for web & devices
    WebMVP8, VP9, AV1Opus, VorbisGoogle-centric, no AAC/AC3
    AVIMPEG-4 Part 2, MJPEG…MP3, AC-3 (experimental)Ancient—limited modern codec support
    MPEG-TSH.264/AVC, HEVC/H.265AAC, MP3, AC-3, DTSStreaming; subtitle support clunky

    Why MKV is the safest “copy” container

    • It’ll happily mux raw H.264, raw AAC (.aac in ADTS), AC-3, DTS, Opus, you name it.
    • No need for extra bitstream filters.

    When using MP4/MOV

    • If your .aac is in ADTS format (most raw .aac files are), MP4 wants “MP4-style” AAC frames.

    • You must run the AAC ADTS→MP4 bitstream filter:

      ffmpeg -i just_video.mp4 -i just_audio.aac \
        -map 0:v -map 1:a \
        -c:v copy -c:a copy \
        -bsf:a aac_adtstoasc \
        assembled.mp4
      
    • Without -bsf:a aac_adtstoasc, you’ll get errors or a silent track.


    Quick take-aways

    • Your “copy” command is correct—just pick a container that supports both your streams.
    • Use MKV if you don’t want to worry about bitstream filters.
    • If you do insist on MP4 and your audio is raw ADTS AAC, add -bsf:a aac_adtstoasc.

    Let me know if you need more on any of these containers or bitstream filters! 😃

  5. User

    I suppose the container format is then inferred from the extension of the output. Correct? For every actually existing file is there any inference, or I can use confusing extensions without adverse effects?

  6. Assistant

    Yes—by default ffmpeg will pick the “muxer” (container format) based on your output‐filename extension. If it sees “.mkv” it loads matroska, “.mp4”/“.mov” it picks the MOV/MP4 muxer, “.ts” the MPEG-TS muxer, etc.

    You can always override that with -f format_name. Conversely, if you give an extension ffmpeg doesn’t recognize, it will complain:

    Could not deduce output format from file extension ".xyz"
    

    and you’ll need to add something like -f matroska (or whatever) to force it.

    —

    How ffmpeg chooses (and how to override)

    1. You name your file:
      ffmpeg … assembled.mkv
    2. ffmpeg looks up “.mkv” → muxer “matroska” → writes Matroska streams.
    3. If the extension is unknown, it errors out:
      ffmpeg -i in.mp4 out.weirdext
      # → “Could not deduce output format from file extension ‘.weirdext’ (use -f?).”
      
    4. To force a format, add -f before the output name:
      ffmpeg -i in.mp4 -f matroska out.weirdext
      # now it will happily write Matroska data into out.weirdext
      

    You can also explicitly choose a different container than the extension implies. For example:

    ffmpeg -i just_video.mp4 -i just_audio.aac \
      -map 0:v -map 1:a \
      -c copy \
      -f mp4 assembled.mkv
    

    That will write an MP4‐style file (with .mkv extension) unless your players get confused.

    —

    Common extension → muxer mapping

    Extension(s)Muxer nameTypical codecs
    .mkvmatroskaH.264, H.265, VP9, AAC, AC-3, DTS, Opus, …
    .mp4, .movmov/mp4H.264, H.265, MPEG-4, AAC, MP3 (limited), …
    .webmwebmVP8/VP9/AV1 + Opus/Vorbis
    .ts, .m2tsmpegtsH.264/H.265 + AAC/MP3/AC-3/DTS
    .aviaviMPEG-4 Part 2, MJPEG + MP3 (partial)
    .flvflvFLV1, H.264 + AAC/Vorbis
    .mpg, .mpegmpegMPEG-1/2 video + MP2 audio
    .ogg, .ogvogg/oggTheora/VP8 + Vorbis
    .wavwavPCM, ADPCM
    .mp3mp3MP3

    If you stick to an obvious pairing (e.g. .mkv with Matroska codecs, .mp4 with H.264 + AAC), ffmpeg “just works.” If you choose a “weird” extension or a mismatch, either:

    • You’ll get an error (unknown extension) → add -f.
    • Or ffmpeg will happily write the chosen format into a file whose name doesn’t match its contents (which may confuse players or other tools).

    —
    Bottom line:
    • Yes, extension → container is inferred automatically.
    • You can use any extension, but if ffmpeg doesn’t know it you must supply -f.
    • Mismatched extension vs actual format won’t break ffmpeg, but might break other players.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.