Discussion: How to use ffprobe to retrieve duration?

Author: jay-ramaniCreated Dec 6, 2025Updated Dec 9, 2025

Not really an issue, but a question. Raising here, since there's no discussion tab.

How do I use this library to retrieve only the duration (while suppressing every other output) of a video stream (at index zero) to standard output with ffprobe? While we could achieve this with the Python subprocess module as below

python
subprocess.run(
	(
		"path_to_ffprobe",
		"-v",
		"quiet",
		"-select_streams",
		"v:0",
		"-show_entries",
		"format=duration",
		"-print_format",
		"default=noprint_wrappers=1:nokey=1",
		"-i",
		input_file
	)
)

, this would require to know the path to ffprobe. I'm trying to achieve the above using a ffmpeg library without relying on an external path in my code.

Any tips and pointers would be appreciated.

Thanks and cheers.