I recommend using json format, it's easier for parsing
ffprobe -i your-input-file.mp4 -v quiet -print_format json -show_format -show_streams -hide_banner { "streams": [ { "index": 0, "codec_name": "aac", "codec_long_name": "AAC (Advanced Audio Coding)", "profile": "HE-AACv2", "codec_type": "audio", "codec_time_base": "1/44100", "codec_tag_string": "[0][0][0][0]", "codec_tag": "0x0000", "sample_fmt": "fltp", "sample_rate": "44100", "channels": 2, "channel_layout": "stereo", "bits_per_sample": 0, "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/28224000", "duration_ts": 305349201, "duration": "10.818778", "bit_rate": "27734", "disposition": { "default": 0, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0 } } ], "format": { "filename": "your-input-file.mp4", "nb_streams": 1, "nb_programs": 0, "format_name": "aac", "format_long_name": "raw ADTS AAC (Advanced Audio Coding)", "duration": "10.818778", "size": "37506", "bit_rate": "27734", "probe_score": 51 } }
you can find the duration information in format section, works both for video and audio