要獲取視頻的時長,可以使用FFmpeg的-i參數,后跟視頻文件的路徑。下面是獲取視頻時長的命令示例:
ffmpeg -i input.mp4
輸出示例:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':Metadata:major_brand : mp42minor_version : 0compatible_brands: isommp42creation_time : 2019-01-01T00:00:00.000000Zencoder : HandBrake 1.2.0 2018121700Duration: 00:01:23.45, start: 0.000000, bitrate: 2000 kb/sStream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1876 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)Metadata:creation_time : 2019-01-01T00:00:00.000000Zhandler_name : ISO Media file produced by Google Inc. Created on: 01/01/2019.Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 126 kb/s (default)Metadata:creation_time : 2019-01-01T00:00:00.000000Zhandler_name : ISO Media file produced by Google Inc. Created on: 01/01/2019.
在輸出中,可以查看"Duration"行,它會顯示視頻的時長,格式為"時:分:秒.毫秒"。
上述示例輸出中的Duration行顯示視頻時長為00:01:23.45。