Skip to content
86% off$349 $48.86code BF2026

Guides

ffmpeg "Application provided duration" Is Invalid: Fix

Fix the ffmpeg error "Application provided duration ... in stream 3 is invalid" (-22) when muxing mov_text subtitles into MP4: find the stream and bad cue.

TroubleshootingUpdated 6 min read

On this page

You ran an ffmpeg command that adds an extra audio track and subtitles to an MP4, and it stopped with this:

text
Application provided duration: 2400480000 in stream 3 is invalid
Error code -22 (Invalid argument)

This page explains what that means, how to find the file responsible, and what to do when the fix isn't obvious.

Why ffmpeg says the duration is invalid

The MP4 muxer checks each packet's duration before writing it. If the value doesn't fit what the container can store, it refuses the packet and ffmpeg exits with -22 (Invalid argument).

The number in your message, 2400480000, is larger than 2,147,483,647, the largest signed 32-bit integer. A duration that large is almost never real. Likely causes, most common first:

  1. A subtitle cue with a bad end time. A typo in the last cue, a wrong hours field, or an end time far past the length of the video.
  2. A cue whose start is later than its end, which can produce a negative or overflowing duration.
  3. A timing problem in one of the other inputs, such as the extra audio file. Reports of this error involve several inputs at once, so we can't say which one is at fault in every case.
  4. A muxer quirk in your ffmpeg version. Behavior changes between releases. We have no confirmed example of this, so treat it as the last suspect.

This is not Mac-specific. The same command, ffmpeg version and inputs fail the same way on other systems.

Find which input is stream 3

The stream number is an output stream index, counted from 0 in the order ffmpeg lists streams under Output #0. Scroll up in the log to that block. Each stream appears with its index, for example Stream #0:3: Subtitle: mov_text.

In a typical command (video, main audio, extra audio, then two subtitle tracks), stream 3 is the first subtitle track. Your command may order things differently, so read your own log rather than assuming.

What stream 3 isLikely causeFirst thing to check
A subtitle trackBad cue timing in that .srtLast cues and longest cues in the file
The extra audio trackOdd duration metadata in that fileffprobe -hide_banner on the file
Something elseInput order differs from what you expectThe Output #0 listing in your log

Step-by-step fixes

1. Test each input on its own

Mux the video with a single subtitle file:

bash
ffmpeg -i video.mp4 -i first.srt -map 0 -map 1 -c copy -c:s mov_text test1.mp4

This copies the existing streams unchanged and converts the subtitle to mov_text, the text subtitle format MP4 accepts. It writes a new file and leaves your inputs alone. Repeat with the second subtitle file.

  • If one file fails alone, the problem is in that file. Go to fix 2.
  • If both work alone but fail together, go to fix 4.

2. Check the subtitle file for a bad cue

Open the .srt in a plain-text editor, not a word processor, and look for:

  • A cue whose end time is far later than the length of the video.
  • A typo in a time, such as a wrong hours or minutes field in the last cue.
  • Times that don't follow the hh:mm:ss,mmm --> hh:mm:ss,mmm pattern, or a start time later than its end time.

You can also list the longest cues with ffprobe. This only reads the file:

bash
ffprobe -v error -select_streams s:0 -show_entries packet=pts_time,duration_time -of csv=p=0 first.srt | sort -t, -k2 -n -r | head

Each line is a cue's start and duration in seconds, and the longest cues come first. A cue lasting minutes when the dialogue is a few seconds long is your culprit.

3. Correct the cue and mux again

Set the bad cue's end time to a few seconds after its start, save the file as UTF-8, and rerun the full command:

bash
ffmpeg -i video.mp4 -i extra-audio.m4a -i en.srt -i fr.srt -map 0 -map 1:a -map 2 -map 3 -c copy -c:s mov_text output.mp4

Each -i is an input, each -map picks what goes into the output, and -c copy leaves video and audio untouched. Only the subtitles are converted.

4. If both subtitle files work alone

When each file muxes fine by itself, the combination or order of inputs may be involved. We haven't confirmed which, so try these in turn:

  1. Mux in two passes: add the first subtitle, then use that output as the input for the second.
  2. Put the subtitle inputs before the extra audio input and update the -map lines to match.
  3. Remove the extra audio from the test. If the error disappears, inspect that file with ffprobe -hide_banner extra-audio.m4a and check its duration.

Note the exact combination that fails. You will want it for a bug report.

5. Update ffmpeg

If you installed ffmpeg with Homebrew, update it and retry:

bash
brew upgrade ffmpeg

This installs the newest ffmpeg formula Homebrew offers. We can't promise a newer version fixes this error, so treat it as a quick test after the steps above. Check what you have with ffmpeg -version.

6. Skip the MP4 mux

If you only need the subtitles to travel with the video, there are two simpler routes.

Write an MKV instead. Matroska stores text subtitles as they are, with no mov_text conversion:

bash
ffmpeg -i video.mp4 -i en.srt -i fr.srt -map 0 -map 1 -map 2 -c copy -c:s srt output.mkv

Keep the .srt next to the video. Some players load a subtitle file that sits beside the video with the same base name, so no mux is needed.

Checklist before you try again

  • You know which input is output stream 3, from your own log.
  • Each subtitle file muxes on its own.
  • No cue has an end time past the end of the video, or earlier than its start.
  • The subtitle files are saved as UTF-8 plain text.
  • Your -map lines match the order of your -i inputs.

If nothing works

Report it on the ffmpeg bug tracker or mailing list. Include:

  • Your exact command.
  • The full console output, not just the last line. Adding -report to the command writes a log file you can attach.
  • The output of ffmpeg -version.
  • The output of ffprobe -hide_banner for each input file.
  • The failing subtitle file, if you can share it.

A message you can adapt:

text
Muxing two mov_text subtitle tracks and an extra audio track into MP4 fails with:
"Application provided duration: 2400480000 in stream 3 is invalid"
"Error code -22 (Invalid argument)"

ffmpeg version: (paste ffmpeg -version)
OS: macOS (version)
Command: (paste full command)
Each input works alone: yes/no (say which ones fail)
Full log attached (-report), plus ffprobe output for each input.

Common questions

Why is the number so large?

2400480000 exceeds the 32-bit signed integer limit of 2,147,483,647. In practice it means a timestamp or end time was read wrongly or was far outside the file.

Will converting the subtitles to ASS or VTT first help?

We can't confirm that. MP4 needs mov_text either way, so a bad cue time would likely carry over. Fixing the timing in the source file is the reliable route.

Does -c copy cause this error?

Not by itself. It only means video and audio aren't re-encoded. The subtitle streams are still converted to mov_text, which is where the duration is computed.

Can Gizmojar fix it?

No. Gizmojar doesn't add subtitle tracks to videos. Its Transcribe tool can save an .srt file using on-device recognition, which you can use as a sidecar file or as an input for the commands above. See On-device AI in Gizmojar.

Every app.
One purchase.