使用之前

iKOA账户与额度

代理服务与代理客户端

查询作品CID


软件的入门使用指南

使用之前与软件介绍

DMF入门使用指南

Vodka入门使用指南

ASQ入门使用指南


常见问题

常用链接

阿狸的FFmpeg小课堂

由于不时有人问我ffmpeg的命令,我尝试写了一个不完整的小指南(如下)—— 阿狸 @kuresu#9260

Adding a cover image with FFmpeg

Note that .mkv files only allows .jpg and .png image files. FFmpeg also only accepts .jpg and .png files when embedding images in .mp4 containers.

Add an embedded thumbnail to a .mp4 container (as a mjpeg video stream)

ffmpeg -iINPUT_VIDEO.mp4 -iINPUT_COVER.jpg -map 0 -map 1 -c copy-disposition:v:1 attached_picOUTPUT.mp4

Each input file in FFmpeg is specified with the option -i

The option -map is used to map where each input (and optionally which stream inside that input) will be located as a stream inside the output file. In particular, the first appearance of the option -map (...) means that it is referring to INPUT #0 while the number that follows means (in case of -map 0 it's 0) that it will be the first output stream. Note that if a video file has both a video and an audio track, FFmpeg will automatically select both. Mapping can also be more selective eg. -map 0:v:0 would mean only pick the first (0) v(ideo) stream of INPUT #0.

The second occurrence is -map 1 which means that the second input (the cover image) will be considered as the second stream in output. The .jpg image will be converted by FFmpeg into an mjpeg video stream that serves as an image.

Finally -disposition:v:1 attached_pic tells FFmpeg that the second video stream (v:1) has to be used as a thumbnail image.

If the input file only has 2 tracks (one video and one audio) it would look like this:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'INPUT_VIDEO.mp4':
  Metadata:
    ...
  Duration: ...
    Stream #0:0(und): Video: h264 ... (default)
    Stream #0:1(und): Audio: aac ... (default)

After embedding the image:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'COVER_VIDEO.mp4':
  Metadata:
    ...
  Duration: ...
    Stream #0:0(und): Video: h264 ... (default)
    Stream #0:1(und): Audio: aac ... (default)
    Stream #0:2: Video: mjpeg ... (attached pic)

Add embedded thumbnails to .mkv container

In .mkv files the name of the image to use as a thumbnail specifies which roles it serves: up to 4 cover images can be added in total. See: https://www.matroska.org/technical/attachments.html

Name Description
cover.jpg Portrait or square (600px on smallest side)
small_cover.jpg Portrait or square (120px on smallest side)
cover_land.jpg Landscape (600px on smallest side)
small_cover_land.jpg Landscape (120px on smallest side)

The role of the image is specified by the filename=... option in FFmpeg. If we want to add 2 covers, one for the thumbnail and one as a poster the command will be:

ffmpeg -i INPUT_VIDEO.mkv -attach INPUT_NORMAL_COVER.jpg -attach INPUT_SMALL_COVER.jpg -c copy -metadata:s:t mimetype=image/jpg -metadata:s:t:0 filename=cover.jpg -metadata:s:t:1 filename=small_cover.jpg out.mkv

Note that in this case the matroska specification wants the "normal" cover image appearing first.

Appendix: extra options

Add language metadata (japanese):

ffmpeg -i INPUT(s) (-map ...)-metadata:s:v:0 language=jpn -metadata:s:a:0 language=jpn (-c copy) (...)

Remove (sound and video) handler metadata:

ffmpeg -i INPUT(s)-empty_hdlr_name 1 (...) (-c copy) (...)

which removes:

Metadata:
    handler_name    : (Video|Sound)Handler

Add faststart for mpeg-4 (moves moov atom at the beginning of the file):

ffmpeg -i VIDEO.mp4 (...) (-c copy) (...)-movflags +faststart OUTPUT.mp4

← 上一页

常见链接

回到首页 →

首页