You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

is there any way to change the metadata of a file without COPYING (not reencoding!) in ffmpeg

is there any way to change the metadata of a file without COPYING (not reencoding!) in ffmpeg

Hey folks, let me lay out my problem clearly: I need to batch reset the rotation metadata on a bunch of video files, and I’m trying to avoid copying the entire file (even the no-reencoding copy feels way too slow for large batches). I’ve seen tons of posts about changing metadata without reencoding, but nearly all of them involve creating a new file—is there a way to just edit the original file's metadata in place, without touching the actual video bits?

I tried this ffmpeg command first:

ffmpeg -i 0003.MP4 -c copy -metadata:s:v:0 rotate=0 0003_fixed.MP4

It fixes the rotation issue, but copying the whole file is way too slow for my needs. On top of that, I noticed it’s stripping some metadata compared to a file that never needed rotation—specifically, the encoder: GoPro AVC encoder entry in the video stream metadata is gone.

Here's a side-by-side of the metadata to show what I mean:

Unmodified original file metadata:

libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '0002.MP4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.3.100
  Duration: 00:41:41.62, start: 0.000000, bitrate: 45201 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 45000 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
    Metadata:
      handler_name    : GoPro AVC
      encoder         : GoPro AVC encoder
      timecode        : 17:01:09:16
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      handler_name    : GoPro AVC
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      handler_name    : GoPro AVC
      timecode        : 17:01:09:16

Modified file metadata (using the ffmpeg command above):

libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '0003_fixed.MP4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:35:23.14, start: 0.000000, bitrate: 45201 kb/s
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 45000 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
    Metadata:
      handler_name    : GoPro AVC
      timecode        : 17:43:43:04
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      handler_name    : GoPro AAC
  Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      handler_name    : GoPro AVC
      timecode        : 17:43:43:04

So to sum up what I need:

  • A way to modify just the rotation metadata (no copying the entire file, in-place if possible)
  • Keep all other existing metadata intact (don't strip the GoPro encoder info)
  • Preferably using ffmpeg, but open to other tools if needed

Solution

First, a quick reality check: ffmpeg doesn't support in-place file editing. Its core design is to read an input file, process it, and write to a new output file—even with -c copy (stream copy mode), it still has to rewrite the entire file structure, which is why it's slow for large files.

That said, if you want to stick with ffmpeg and preserve all metadata, you can tweak your command to explicitly copy all input metadata to the output. Just add the -map_metadata 0 flag, which tells ffmpeg to copy all global and stream-level metadata from the input (file index 0) to the output:

ffmpeg -i 0003.MP4 -c copy -map_metadata 0 -metadata:s:v:0 rotate=0 0003_fixed.MP4

This should keep the encoder: GoPro AVC encoder entry and all other metadata intact, while still fixing the rotation.

If you truly want in-place editing (no file copying at all), you'll need a dedicated metadata tool like exiftool. It modifies only the metadata sections of the file, so it's blazingly fast even for large videos. Here's the command to set rotation to 0 and overwrite the original file directly:

exiftool -overwrite_original -Rotation=0 0003.MP4

The -overwrite_original flag skips creating a backup file (you can omit it if you want a safety backup), and it will preserve all other metadata exactly as it was.

备注:内容来源于stack exchange,提问作者Daneolog

火山引擎 最新活动