Edit "Media Duration" metadata on MP4 file

7,197

Solution 1

I found a solution. Rather than editing the metadata, I re-encoded the files using ffmpeg, in such a way that the video and audio content was simply copied and wrapped in a new, error-free MP4 container. Here's the command:

ffmpeg -i video_1.mp4 -vcodec copy -acodec copy video_1_fixed.mp4

Solution 2

There are two reasons why the listed exiftool command didn't work.

First, "Media Duration" isn't the name of a tag, it's the description. From ExifTool FAQ #2

…by default it prints descriptions, not tag names, for the information it extracts. … Note that descriptions often contain spaces between words, but tag names never do. Also, tag names are always English, regardless of the -lang setting. To print the tag names instead instead of descriptions, use the -s option when extracting information

The second problem is that the MediaDuration tag isn't a writable tag (see the QuickTime MediaHeader Tags).

Share:
7,197

Related videos on Youtube

Sam Kauffman
Author by

Sam Kauffman

Updated on September 18, 2022

Comments

  • Sam Kauffman
    Sam Kauffman almost 2 years

    I have some video files which were converted to MP4, but not quite correctly. When I examine one with exiftool, I see these metadata values:

    Duration                        : 0:11:23
    Track Duration                  : 0:11:23
    Media Duration                  : 0:04:13
    

    That last one is incorrect. In VLC media player, the videos play fine, but the tool I'm using to play them in a web app (Flowplayer) takes the "Media Duration" value seriously and truncates the video.

    To fix the metadata I tried

    exiftool -"Media Duration"="0:11:23" video_1.mp4
    

    But I got

    Warning: Sorry, Media is not writable
    Nothing to do.
    

    Sudo didn't help. According to its man page and web site, exiftool can read and write metadata on MP4 files, but "ExifTool will not rewrite a file if it detects a significant problem with the file format."

    How can I fix those files?


    EDIT: I've had no luck with ffmpeg or mediainfo.

  • SSS
    SSS over 5 years
    Just wanted to say, thanks a lot, this helped me right now.
  • StarGeek
    StarGeek over 4 years
    Admittedly, this is a necro-post answer, but I thought I should bring up the reasons why the original exiftool command didn't work.
  • Utku Özdemir
    Utku Özdemir almost 4 years
    worked like a charm, thank you.