How does ffprobe determine duration?

I use ffprobe to analyze media files stored on a remote server. This seems to work well, but for some files the duration is missing or incorrect (usually longer than it should be). In other cases, it accurately returns this information and does not seem to be related to the type of medium (codec, etc.).

Here is an example of a command that works:

ffprobe -v quiet -print_format json -show_streams -show_format http://host.com/file.aiff

 { "streams": [ { "index": 0, "codec_name": "pcm_s16be", "codec_long_name": "PCM signed 16-bit big-endian", "codec_type": "audio", "codec_time_base": "1/44100", "codec_tag_string": "[0][0][0][0]", "codec_tag": "0x0000", "sample_fmt": "s16", "sample_rate": "44100", "channels": 2, "bits_per_sample": 16, "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/44100", "start_pts": 0, "start_time": "0.000000", "duration_ts": 8494248, "duration": "192.613333", "bit_rate": "1411200", "nb_frames": "8494248", "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": "http://host.com/file.aiff", "nb_streams": 1, "nb_programs": 0, "format_name": "aiff", "format_long_name": "Audio IFF", "start_time": "0.000000", "duration": "192.613333", "probe_score": 100 } } 

Here is an example of one that does not:

ffprobe -v quiet -print_format json -show_streams -show_format "http://host.com/file.wav"

What generates this result:

 { "streams": [ { "index": 0, "codec_name": "pcm_s16le", "codec_long_name": "PCM signed 16-bit little-endian", "codec_type": "audio", "codec_time_base": "1/44100", "codec_tag_string": "[1][0][0][0]", "codec_tag": "0x0001", "sample_fmt": "s16", "sample_rate": "44100", "channels": 2, "bits_per_sample": 16, "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/44100", "bit_rate": "1411200", "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": "http://host.com/file.wav", "nb_streams": 1, "nb_programs": 0, "format_name": "wav", "format_long_name": "WAV / WAVE (Waveform Audio)", "bit_rate": "1411200", "probe_score": 99 } } 

These two examples are different formats, but I saw how it works and does not work, when the format is the same, I just do not have a suitable example.

I would like to know if there is something that I can change about the parameters that I use with ffprobe to provide a constant and accurate definition of the duration or any information that I can find regarding how ffprobe works, so I find out how can I change the input files, etc., so that they work correctly.

Alternatively, if there is another tool that works more reliably (it should be an open source Linux tool), any suggestions or recommendations are welcome.

+8
linux ffmpeg audio ffprobe
source share
2 answers

One simple solution is to use the -show_packets option

 ffprobe -i input.mp4 -show_packets > a.txt 

Now open the a.txt file and go to the last package and look at the dts_time value, which will be the exact duration of the file. If dts_time is not defined, check the value of pts_time.

+3
source share

Metadata may be incorrect. The most correct way is decoding the whole file:

 $ ffmpeg -i input.webm -f null - ... frame=206723 fps=1390 q=-0.0 Lsize=N/A time=00:57:28.87 bitrate=N/A speed=23.2x 

Source: https://trac.ffmpeg.org/wiki/FFprobeTips#Getdurationbydecoding

0
source share

All Articles