ffmpeg 给音频添加封面,ffmpeg对音视频metadata 相关操作

作者&投稿:戊宰 (若有异议请与网页底部的电邮联系)
~ ffmpeg 给音频添加封面,ffmpeg对音视频metadata 相关操作

ffmpeg给音频添加封面的功能找了很久。在官网的文档中找到了方法。

但是因为各种原因,失败了很多次。

这次终于完全理解了这个命令的使用。

首先我们看到这个选项 **-disposition[:stream_specifier]** value **(***output,per-stream***)**

这个disposition选项是用来调整文件布局用的,有以下这些选项:

我们可以看到,其中有一个attached_pic选项,这个就是我们加封面的时候要用的。

先看看官网给的其他例子

For example, to make the second audio stream the default stream:

To make the second subtitle stream the default stream and remove the default disposition from the first subtitle stream:

然后就是添加封面的命令了

To add an embedded cover/thumbnail:

Not all muxers support embedded thumbnails, and those who do, only support a few formats, like JPEG or PNG.

可以看到,只支持很少的图片格式,比如jpeg和png,webp就不知道了,以后有机会试一试。

这个方法可以给视频和音频加封面。

上面给的例子是给视频加封面。

如果我把后面视频的格式变成m4a,结果发现效果只是单纯拷贝一个视频而已。

然后使用的过程中各种红色的找不到codec错误。

首先我对map命令不是很熟悉。这个场景就是map命令的一个应用。视频和图片作为输入,只取视频中的音频。所以我们就要定位到音频的位置。如果不用map,按照默认配置来的话,音频和视频和图片都会加入到新的文件里,可以看到video stream有两个,分别是视频和图片。

用map就是手动选择stream。

ffmpeg -i in.mp4 -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4

上面这个例子, map 0是第一个整个视频,map1则是第二个图片,和不用map的结果差不多。

估计,用map是为了后面的disposition选择对应的图片流更稳定。

在我的需求里,就不一样了。我的需求是把一个视频和封面合成成具有封面的音乐,这样等于删除了视频流。节省空间,封面只是起到美化作用而已。

所以我的map是下面这样的
ffmpeg -i input.flv -i input.png -map 0:a -map 1:v

map后面的第一个数字代表 ffmpeg -i 输入的顺序,也就是程序实际读入stream的顺序。后面还可以定位,第一个是定位了stream文件,冒号后面的第二个则是定位具体的steam。可以用1,2之类的数字,用a,v则分别表示视频和音频,在只有一个视频和音频的情况下就等于选中一个特定的stream

再往后看, -c:v:1 png 选项,指定第二个视频的处理方式是png。 -c:v 就是用来指定视频编码器,后面再跟的数字,就是指定具体stream。这里1指的是第二条stream流。第一条指的是第一个视频的视频流了。如果要指定第一个视频的视频流则是 -c:v:0 。这里我们通常不指定也可以,反正ffmpeg也会有一些自动化处理的。

-disposition 后面冒号跟的也是一个steam选择的功能。

​ -disposition:v:1 attached_pic

然后我的实际转化命令就变成

这样就能达成目的了。

经过测试opus格式也是不支持,估计也就只有mp3和aac这两种格式能支持吧?

加过封面后,用播放器加载能够正确使用封面了,并且mp3tag这类的工具也可以看到。

关于metadata的修改,网上发现一份很不错的文档,这里就放在下面了。方便查看。

首先修改metadata关键看标签名对应到ffmpeg里面是什么键值,wiki上有这样一张表

The following table shows the metadata keys that FFmpeg honors when muxing a QuickTime file. The low-level identifier column lists the atom name that the format uses to encode the data on disc, which is not interesting to most readers. For the interested but uninitiated, the notation, e.g., '\251nam' indicates a 4-byte code consisting of the byte A9 in hexadecimal (or 251 in octal) followed by the ASCII characters 'n', 'a', and 'm'.

I have received so many requests from my previous article, “ID3 tags on Windows using ffmpeg”, asking how to add, create or write ID3 tags with ffmpeg that I wrote this article in response.

The option to write ‘tags’ to a file, known as metadata, is -metadata key=”value”. Here is a basic example:

You repeat the option once for each key/value pair you want to add to your file like this:

If you want to clear or delete a certain key/value pair, include the key but leave the value blank like this:

The examples shown above are the very basic. While they will work and will produce a file, there are more options that need to be included to achieve the desired results.

Adding, creating, deleting, or clearing ID3 tags in ffmpeg is very simple. The hard part is figuring out what items you want and what the ‘key’ names are. For example, in Windows you can right-click on the audio file, select ‘Properties’, then click on the ‘Details’ tab. There are several Property/Value pair items listed; “Title”, “Subtitle”, “Comments”, “Contributing artists”, “Album artist”, “Album”, etcetera. Similar information is available in iTunes by right-clicking on a name, choose ‘Get Info’, then click on the ‘Info’ tab. The following table may help you decide:

I suggest you experiment with the different keys to find what works best for you.

Lets look at some more advanced options you can use to manipulate metadata. For example, if you want to clear or delete all the global metadata in a file. You could use the examples above and include the key and a blank value for each item but that could make your command line very long. Instead you can use -map_metadata -1 instead. Here it is in a command line:

Setting -map_metadata to -1 (negative one) tells ffmpeg to use a non-existent input thereby clearing or deleting all the global metadata.

You can get the metadatainformation for a media file by including a input file with no output file like this:

FFmpeg is also able to dump metadata from media files into a simple UTF-8 encoded INI-like text file and then load it back using the metadata muxer/demuxer. Use a command line like the following to create the text file:

The file format is as follows:

A ffmetadata file might look like this:

You can edit the ffmetadata text file to include, change, or remove metadata by loading it into your media file.

To load the file and include the metadata in the output file, use -map_metadata like this:

The inputs -i in ffmpeg are counted zero-based. What that means is the first input from the command line example above -i in.mp3 is input number zero. The next input -i metadata.txt is input number one. So using -map_metadata 1 we are telling ffmpeg to map the metadata from input one, our text file, to the global metadata of the output file.

If you are planning on using the media files with metadata on Windows, DO NOT forget to use these options in your command line:

As shown in Example 7 above.


高明区13912102029: 用ffmpeg给视频加水印问题 -
斐鲁双黄: ffmpeg 加水印,不是所有的版本都支持的,要0.5以前的版本,还需要带vhook里watermarter.dll 再用ffmpeg 命令行就可以了.当然整个过程很复杂 建议你用 影音转霸2009 2.5 专业视频加水印工具

高明区13912102029: 怎么在ffmpeg中添加自己的解码器 -
斐鲁双黄: 实现一个AVCodec结构, 然后用avcodec_register()注册它.可参照已有的AVCodec如ff_aac_decoder,ff_h264_decoder等.

高明区13912102029: 要怎么给HTML的音乐播放器添加背景图片? -
斐鲁双黄: 参考如下: 载入音乐基本语法: <*EMBED SRC=\"音乐文件地址\"> 常用属性如下: SRC=\"FILENAME\" 设定音乐文件的路径 AUTOSTART=TRUE/FALSE 是否要音乐文件传送完就自动播放,TRUE是要,FALSE是不要,默认为...

高明区13912102029: 如何在Android用FFmpeg+SDL2.0之同步音频 -
斐鲁双黄: 您好,很高兴为您解答,方法如下:/* * SDL_Lesson.c * * Created on: Aug 12, 2014 * Author: clarck */#include #include #include "SDL.h"#include "SDL_thread.h"#include "SDL_events.h"#include "../include/logger.h"#include "../...

高明区13912102029: ffmpeg 最大允许多大文件 -
斐鲁双黄: 基本选项: -formats 输出所有可用格式 -f fmt 指定格式(音频或视频格式) -i filename 指定输入文件名,在linux下当然也能指定:0.0(屏幕录制)或摄像头 -y 覆盖已有文件 -t duration 记录时长为t -fs limit_size 设置文件大小上限 -ss time_off 从指...

高明区13912102029: 用ffmpeg给视频加水印问题
斐鲁双黄: 建议你到官网上下一个完整的ffmpeg

高明区13912102029: ffmpeg ffmplay没有 -
斐鲁双黄: 如果需要视频摄像头支持,一定要有ffmpeg,在./configure的时候你可以看一下ffmpeg检查是否通过.对于非视频方面的函数,ffmpeg存在与否没有影响.

高明区13912102029: 如何在MAC上编译FFMpeg - CSDN论坛 -
斐鲁双黄: 编译mac 上基于ffmepg的软件需要先下载两个程序:iFrameExractor和ffmpeg 编译步骤:1、在终端下: cd /iFrameExtractor/ffmpeg 建议开始就执行 sudo -s (获取权限命令)2、在终端下输入 ./configure --prefix=/iFrameExtractor/ffmpeg --libdir=...

高明区13912102029: 编译 ffmpge libpostproc库没有 -
斐鲁双黄: ffmpeg是音视频的分离,转换,编码解码及流媒体的完全解决方案,其中最重要的就是libavcodec库.它被mplayer或者xine使用作为解码器.还有,国内比较流行的播放器影音风暴或MyMPC的后端ffdshow也是使用ffmpeg的解码库的.ffmpeg软...

高明区13912102029: ffmpeg 编码h264 profile如何设置为baseline的问题 -
斐鲁双黄: 使用最新版ffmpeg-0.11 libx264-125,使用默认编码时,用Eyecard发现profile-idc一直是PROFILE_H264_HIGH (profile-idc=100),但是项目要求是baseline,设置了AVCodecContext的->profile=FF_PROFILE_H264_BASELINE也没用,经过多方...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网