Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG attach file as metadata

I have a set of images which I want to convert to a video using ffmpeg. The following command works perfectly fine:

ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 testout.mkv

I have some meta data in a binary file which I want to attach with the video. I tried doing the following, but it gives me an error:

ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 -attach mybinaryfile -metadata:s:2 mimetype=application/octet-stream testout.mkv

This is the error:

[matroska @ 0x656460] Codec for stream 1 does not use global headers but container format requires global headers
[matroska @ 0x656460] Attachment stream 1 has no mimetype tag and it cannot be deduced from the codec id.
Output #0, matroska, to 'testout.mkv':
  Metadata:
    encoder         : Lavf56.33.101
    Stream #0:0: Video: huffyuv (HFYU / 0x55594648), rgb24, 640x640, q=2-31, 200 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.39.100 huffyuv
    Stream #0:1: Attachment: none
    Metadata:
      filename        : 2ceb-1916-56bb-3e10
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> huffyuv (native))
  File 2ceb-1916-56bb-3e10 -> Stream #0:1
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

It would be wonderful if somebody can explain to me what am I doing wrong :)

like image 729
ahmadh Avatar asked May 29 '15 04:05

ahmadh


1 Answers

You need to specify your stream properly

Example:

ffmpeg -y -i frames/%06d.png -c:v huffyuv -pix_fmt rgb24 -attach mybinaryfile \
-metadata:s:t mimetype=application/octet-stream testout.mkv

This command will set the metadata for all attachment (t) streams (s). If you have more than one attachment, and the metadata are different, then you will have to be more specific, such as:

-metadata:s:t:0 mimetype=text/plain \
-metadata:s:t:1 mimetype=application/gzip

This will set the metadata for the first attachment as mimetype=text/plain, and the second as mimetype=application/gzip. Remember that the stream index starts at 0, so the first steam is labeled 0.

What was wrong with your command

Using -metadata:s:2 (which appears to have been copied verbatim from the documentation) sets the metadata for the third stream, regardless of stream type (because no specifier is present), but your output only contained two streams.

Attachment: None

You may see something like this:

Output #0, matroska, to 'output.mkv':
...
    Stream #0:1: Attachment: none
    Metadata:
      filename        : 2ceb-1916-56bb-3e10
      mimetype        : application/octet-stream

Attachment: none does not mean that there is no attachment, but that there is no format associated with it, so it can be ignored.

Also see

Stream specifiers and the ffmpeg documentation on -attach, -metadata, and -map_metadata for more details.

like image 115
llogan Avatar answered Sep 20 '22 14:09

llogan