how to save custom data into header in movie file using ffmpeg?

Solution 1:

You don't mention which container format you want this facility for, since some don't allow custom tags.

FFmpeg's Matroska muxer allows random tags, so

ffmpeg -i input -c copy
       -metadata key1=value1
       -metadata:s:v key2=value2
       -metadata:s:a:0 key3=value3
out.mkv

The first metadata options set a global value, the 2nd is applied to all video streams, and the third to the 1st audio stream only.

Mediainfo and ffprobe can show these values.

Solution 2:

got it.. after doing some digging on same line -metadata found this amazing post - https://jmesb.com/how_to/create_id3_tags_using_ffmpeg this will do any format I believe.

ffmpeg supports few tags which can be manipulated like title, comments, artists, album, track

ffmpeg32 -i out.mov-metadata publisher="Publishers Info" -metadata artist="my metadata" -metadata album="another data" -metadata TIT3="more data" out2.mov

this way I could able to add custom data into metadata, though TIT3 is for subtitles, we at work never use it, so I could able to hack through this attribute.