You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FFmpeg通过文件传递元数据的-map_metadata参数用法问询

Using -map_metadata and File-Based Metadata in FFmpeg

Great question—using files to handle metadata is a smart way to keep your FFmpeg commands clean, especially when dealing with lots of parameters. Let’s break down both how to use -map_metadata properly and an alternative method for custom metadata files.

Understanding -map_metadata Syntax

The official syntax outfile[,metadata]:infile[,metadata] looks a bit intimidating, but it’s simpler when you break it down:

  • infile is the index of your input file (starting at 0 for the first input)
  • outfile is the index of your output file (also starting at 0, useful if you’re exporting multiple outputs)
  • The optional [,metadata] part lets you target specific streams (video, audio, subtitles) instead of the entire file.

Common -map_metadata Examples

Let’s start with the most useful cases:

  1. Copy all metadata from the first input to the output
    This is the simplest use case—pulls every metadata field (title, artist, etc.) from your input media to the output:

    ffmpeg -i input.mp4 -map_metadata 0 -c copy output.mp4
    

    The 0 here refers to the first input file; -c copy copies streams without re-encoding (faster).

  2. Pull metadata from a separate "metadata source" file
    If you have a dedicated media file (like a dummy audio/video file with all your desired metadata) you want to reuse, point -map_metadata to that input index:

    ffmpeg -i raw_video.mp4 -i metadata_template.mp4 -map_metadata 1 -c copy final_video.mp4
    

    Here, 1 targets the second input (your metadata template), so the output gets its metadata from that file while using the video from the first input.

  3. Target specific stream metadata
    If you only want to copy metadata from, say, the audio stream of your input, use stream specifiers (:s:a for audio streams, :s:v for video):

    ffmpeg -i input.mp4 -map_metadata:s:a 0:s:a -c copy output.mp4
    

    This copies only the audio stream’s metadata (like artist or track number) to the output’s audio stream.

Alternative: Load Custom Metadata from a Text File

If you’re creating entirely custom metadata (not copying from another media file), the @ flag lets you load a text file full of -metadata parameters. This is perfect for long lists of metadata fields.

  1. Create a metadata.txt file with your parameters:
    -metadata title="My Travel Vlog 2024"
    -metadata artist="Jane Smith"
    -metadata year="2024"
    -metadata description="A week exploring the Italian countryside"
    -metadata genre="Travel"
    -metadata copyright="© 2024 Jane Smith"
    
  2. Reference this file in your FFmpeg command:
    ffmpeg -i input.mp4 @metadata.txt -c copy output.mp4
    
    FFmpeg will read all the -metadata lines from the file just like you typed them directly in the CLI.

Key Notes

  • When using -map_metadata, if metadata fields overlap between inputs, the later input (or the one specified in -map_metadata) will overwrite earlier ones.
  • The @file method works for any FFmpeg parameters, not just metadata—you can put your entire command (except the ffmpeg start) in a text file if you want!

内容的提问来源于stack exchange,提问作者Alejandro Galera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:06:49