ffmpeg -map 是什么意思?


author: hjjdebug

date: 2025年 12月 10日 星期三 17:17:44 CST

descrip: ffmpeg -map 是什么意思?


  1. -map 选项: 是每一个文件对应的选项,用于指定输出流对应的输入流.
    用ffmpeg -h long |grep map
    可以看到帮助:
cpp 复制代码
Advanced per-file options:
-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]  set input stream mapping

这个帮助信息,来源于ffmpeg_opt.c 中有一项map 的描述.

cpp 复制代码
    { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map },
        "set input stream mapping",
        "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },

我们跟踪一下函数执行代码 opt_map, 可知道它到底干了什么.

从map 的value 中可得到file_index, 可得到stream_index, 把这个流或这些流都添加到optctx中,供以后打开输出文件时使用

  1. 举例
    例如: ffmpeg 执行如下命令:
cpp 复制代码
$ ffmpeg -i 1.ts -filter_complex "[0]split[out1][out2]" -map "[out1]" output1.ts -map "[out2]" output2.ts -v debug -y

打开output1.ts 有选项 -map "[out1]", "[" 说明数据来源是filter

打开输出文件时,会分析输出文件的选项, 见map选项 write_option 时要执行

static int opt_map(void* optctx, const char* opt, const char* arg)

其中optctx 就是OptionsContext 对象, OptionsContext* o = (OptionsContext *)optctx;

opt="map",

arg="[out1]"

该函数执行后要在o->stream_maps 上 重新分配出一个map 对象. 上面写上:

cpp 复制代码
p *m
$7 = {
  disabled = 0,
  mp_file_index = 0,
  stream_index = 0,
  linklabel = 0x51b340 "out1"
}

在打开文件时会用到OptionsContext o,

ret = open_file(&o, g->arg); //g->arg 就是output1.ts

具体代码还是挺复杂的,看看它的log输出吧. (verbose)

cpp 复制代码
Opening an output file: output1.ts.
20251017 16:47:49.906 [out#0/mpegts @ 0x4f63c0] Adding streams from explicit maps...
20251017 16:49:45.213 [out#0/mpegts @ 0x4f63c0] Creating output stream from an explicitly mapped complex filtergraph 0, output [out1]
20251017 16:51:28.857 [vost#0:0/mpeg2video @ 0x6c9bc0] Created video stream from complex filtergraph 0:[split]
相关推荐
活捉一个坏小孩6 天前
Nvidia FFmpeg安装说明
ffmpeg
WF_YL7 天前
如何删除 Oracle 过期 key / 数据,删除目的的key
ffmpeg
浩瀚之水_csdn7 天前
avcodec_find_decoder函数详解
ffmpeg
浩瀚之水_csdn10 天前
avcodec_parameters_copy详解
linux·人工智能·ffmpeg
ShineWinsu12 天前
对于C++中map和multimap的详细介绍
c++·面试·stl·笔试·map·红黑树·multimap
不吃鱼的猫74814 天前
【ffplay 源码解析系列】02-核心数据结构详解
c++·ffmpeg·音视频
不吃鱼的猫74814 天前
【ffplay 源码解析系列】01-开篇-ffplay整体架构与启动流程
c++·架构·ffmpeg·音视频
REDcker16 天前
FFmpeg开发者快速入门
ffmpeg
不吃鱼的猫74816 天前
【从零手写播放器:FFmpeg 音视频开发实战】04-封装格式与多媒体容器
c++·ffmpeg·音视频
燃于AC之乐16 天前
深入解剖STL map/multimap:接口使用与核心特性详解
开发语言·c++·stl·面试题·map·multimap