80

How can I remove all metadata from all formats via FFmpeg?

I can just set special metadata for each format per man ffmpeg. Any option or method to clear all metadata and strip media from all metadata available on ffmpeg?

   -metadata key=value
       Set a metadata key/value pair.

       For example, for setting the title in the output file:

               ffmpeg -i in.avi -metadata title="my title" out.flv
0

4 Answers 4

119

Slightly modifying the command line by @izx, I got this:

ffmpeg -i in.mov -map_metadata -1 -c:v copy -c:a copy out.mov

The result is (again, checked with exiftool), a metadata record reduced from 81 to 52 lines. Note that you can't simply remove all metadata, some things will stay.

If you want to remove the newly added encoder field, add this to the command (before the output filename):

-fflags +bitexact -flags:v +bitexact -flags:a +bitexact

Thanks to @wisbucky for the hint.

However, I didn't get the creation date to change, which is strange because it seemed to work in the Ubuntu version. I posted on the FFmpeg mailing list, asking whether there were any updates or comments on that, but there was no answer.

8
  • 2
    In mov or mp4 files, creation date is an integer field in the movie header and track headers (expressed as seconds since 1904). Although you could set it to 0 or some other fixed value, there is no way to remove it and still have a valid mov or mp4 file.
    – mark4o
    Commented Dec 18, 2012 at 7:34
  • I know I couldn't remove it entirely, but changing wasn't possible for some reason.
    – slhck
    Commented Dec 18, 2012 at 7:39
  • 4
    Using the current ffmpeg, the creation time can be changed with -metadata creation_time=2012-12-17T21:30:00 (UTC).
    – mark4o
    Commented Dec 18, 2012 at 7:46
  • 1
    How can i modify this to remove the title too? Currently it sets the title to something automatically generated. I want to see the full filename as title in the end.
    – Rookie
    Commented Jun 15, 2014 at 11:26
  • 4
    @Rookie Then you need to set -metadata title="Some Value". Or, for a file, something like this for an MP4 file: ffmpeg -i "$file" -map_metadata -1 -c copy -metadata title="$file" "${file%%*.mp4}-new.mp4
    – slhck
    Commented Jun 15, 2014 at 13:25
17

NOTE: I have since updated ffmpeg (previously I had the outdated version of avconv from the Ubuntu repositories).

Now @slhck's -map_metadata -1 works perfectly.

I recommend @slhck's solution because it's less typing and up to date. I'm leaving this here for anyone using an outdated version.


The easiest way to do this is to set -map_metadata to use one of the input streams, rather than using global metadata. 99% of the time this should work. NOTE: I'm using avconv, because that's in the Ubuntu 12.04 repositories; this will probably be drop-in compatible with ffmpeg, since their syntax always is in my experience.

avconv -i input.mp4 -map 0 -map_metadata 0:s:0 -c copy output.mp4

This will take the metadata from the first data stream (normally the video stream) and use that to replace the global metadata of the container file. This works because most of the time, the data streams have no meaningful metadata written to them; however, sometimes they do, and you want to completely get rid of that metadata. Unfortunately, the only way I can think of to do this used a pipe and two avconv processes.

avconv -i input.mp4 -f wav - | avconv -i - -i input.mp4 -map 1 -map_metadata 0 -c copy output.mp4

This takes advantage of the fact that WAV files can't contain metadata (since the format was created before metadata tags existed).

Both of these methods blanked all metadata on a file I just tested them on - all that exiftool reported on was the codec information, and avprobe reported no metadata to me. Using a pipe for this is pretty ugly, and the first method will work in 99% of cases, so that should be preferred.

1
  • 3
    WAVE files, like other RIFF-based files (e.g. AVI) can actually contain metadata tags using a "INFO" list chunk. It's just not used very often.
    – blerontin
    Commented Sep 27, 2017 at 9:49
15

My solution to strip metadata, chapters, to change creation time and title. This way any metacontent should be different from the original file:

ffmpeg -y -i "test.mkv" -c copy -map_metadata -1 -metadata title="My Title" -metadata creation_time=2016-09-20T21:30:00 -map_chapters -1 "test.mkv"
1
  • 2
    That variant was useful to me, thank you. I'd wish the ffmpeg manual would show more examples like the above; stackoverflow, superuser etc... all do become very useful because they contain a lot of helpful information.
    – shevy
    Commented Dec 26, 2015 at 1:35
7

To strip metadata, I use -map_metadata:g -1 because I only strip the global metadata and keep the subtitles's metadata such as the track language names :

$ ffmpeg -hide_banner -i "$video" -map 0:v:0? -map 0:a? -map 0:s? -c copy -map_metadata:g -1 "$outputVideo"

The -map 0:...? option argument means that (according to man ffmpeg) :

A trailing "?" after the stream index will allow the map to be optional: if the map matches no streams the map will be ignored instead of failing.

3
  • Note that you probably want to quote those map options in case it were to match a filename (certainly very unlikely, but definitely possible). Commented Mar 20, 2021 at 17:03
  • Any way to strip out the Vendor ID as well?
    – ylluminate
    Commented Jun 2, 2022 at 23:05
  • @ylluminate I don't know. Is the Vendor ID metadata stored in the global metadata ? I don't have a video containing Vendor ID metadata to test the ffmpeg ... -map_metadata:g -1 ... command. Have you tried this command ?
    – SebMa
    Commented Jun 4, 2022 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .