4

I have a flac audio file with incorrect duration in the metadata. The audio has a length of 55 minutes but the metadata has a duration of 0. Is it possible to use an ffmpeg command to fix this?

Below are the outputs of an ffprobe:

  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Chognificent
  • 393
  • 6
  • 20
  • FLAC usually doesn't have a duration in the metadata. You can work out the duration from the sample count and sample rate in the StreamInfo metadata block. – greg-449 Mar 12 '20 at 12:22
  • 2
    hi @greg-449, all my other FLAC files have durations. Do you know of a way I could get the calculated duration into the metadata? – Chognificent Mar 12 '20 at 12:38
  • Try re-muxing: `ffmpeg -i input.flac -map 0 -c copy output.flac` – llogan Mar 12 '20 at 16:46
  • hi @llogan, the duration of output.flac is still N/A after the re-muxing. – Chognificent Mar 17 '20 at 10:20

1 Answers1

9

The FLAC header is missing or incomplete. Re-encoding will re-write it:

ffmpeg -i input.flac -c:v copy -c:a flac output.flac

There will be no quality loss as FLAC is lossless.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • 1
    For searchability: this ffmpeg fixed a broken flac file I had which `flac` itself could not fix. `flac` said: "ERROR: FLAC input has STREAMINFO with unknown total samples which is not supported" – olejorgenb Jul 23 '21 at 12:59