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]
相关推荐
_oP_i14 小时前
FFmpeg 如何与ai结合剪辑出效果好的视频
人工智能·ffmpeg·音视频
四方云1 天前
电销系统中FreeSWITCH桥接播放自定义振铃:被叫接听后振铃持续问题解决
ffmpeg
花花鱼2 天前
将 MP4 转为 886×1920(竖屏)使用ffmpeg处理
ffmpeg
杨云龙UP2 天前
Oracle RAC/ODA环境下如何准确查询PDB表空间已分配大小?一次说清Oracle表空间逻辑大小和ASM三副本实际占用_2026-05-19
linux·运维·数据库·sql·oracle·ffmpeg
DogDaoDao3 天前
Android 播放器开发:从零构建全功能视频播放器
android·ffmpeg·音视频·播放器·mediacodec·编解码
学Linux的语莫4 天前
FFmpeg和流媒体服务器
ffmpeg
星原望野4 天前
JAVA集合:List、Set和Map
java·开发语言·list·set·map·集合
太阳风暴5 天前
fftools/graph-FFmpeg Filtergraph 打印系统文档
ffmpeg·滤镜图
!chen5 天前
Oracle Deep Data Security (Deep Sec) 初体验
数据库·oracle·ffmpeg
wyw00006 天前
FFmpeg实现带颜色MXF转mp4
python·ffmpeg