I am trying to develop a software that can automatically search and download the correct subtitle for my movies. I need to compare the fps rates. How can i find the fps of a movie in java ?

Dani AI

Generated

Short summary tied to the thread: needs an FPS value to choose the correct subtitle file; is correct that the container stores metadata and was right to point toward libraries. A reliable solution is to read container-level metadata (preferred) or, when needed, compute FPS from frame count and duration. Also beware fractional rates (29.97, 23.976 = 30000/1001 or 24000/1001) and variable-frame-rate (VFR) material — both are common and break naive approaches.

A practical workflow:

  • Use a metadata tool (ffprobe) or MediaInfo to read the video stream fields avg_frame_rate, r_frame_rate, nb_frames and duration. avg_frame_rate may be a fraction like 30000/1001; divide numerator/denominator to get a double.
  • If avg_frame_rate is missing, use fps = nb_frames / duration (if nb_frames and duration exist).
  • If the file is VFR, prefer PTS-based resync (map subtitle timestamps to presentation timestamps) rather than a single FPS.

ffprobe example command:

ffprobe -v error -select_streams v:0 \
  -show_entries stream=avg_frame_rate,r_frame_rate,nb_frames,duration \
  -of json "movie.mkv"

Simple Java approach: run ffprobe with ProcessBuilder, capture stdout, parse the JSON (or the avg_frame_rate string), split on '/' and compute fps = num / den. If you prefer not to use an external binary, consider a pure-Java parser like JCodec to inspect stream headers.

Conversion formulas:

  • Parse rational FPS: fps = numerator / denominator.
  • Convert frame-based subtitle frames from source FPS to target FPS:
    new_frame = round(old_frame * target_fps / source_fps).
  • Convert frames to milliseconds: ms = frame * 1000 / fps.

Cautions and tips:

  • Treat fractional NTSC rates as rational values to avoid rounding drift.
  • If subtitles are time-based (SRT), FPS is usually irrelevant.
  • Test on sample files; for VFR files, decoding timestamps (PTS) is the only robust method.

References: ffprobe documentation ([ffprobe])(https://ffmpeg.org/ffprobe.html), MediaInfo ([MediaInfo])(https://mediaarea.net/en/MediaInfo), JCodec ([JCodec])(https://github.com/jcodec/jcodec).

Recommended Answers

All 3 Replies

Do you have the layout of a movie file and know where in the file the data you want is located? Given that we can help you read the file and extract the data.

Are you using jmf, quicktime, or what? Each of these have methods to return all the characteristics of a movie.

Thanks. I wasn't aware ofJMF or QuickTime before. QuickTime won't work for Linux, so I am left with JMF. It has a getRate() method, to get the fps.

Norm1 said to give the layout of the movie file. Sorry, I don't know where to find that ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.