ImportsubprocessImportOSImport TimedefGetTime (flvpath,fid):#file_str = ' 1.flv 'File_str =Flvpath WG= subprocess. Popen (['Ffmpeg.exe','- I.', File_str], stdout=subprocess. PIPE, stderr=subprocess. STDOUT) (standardout, junk)=wg.communicate () ans=STR (standardout) Num= Ans.find ("Duration:") out= ans[num+10:num+18] Fid.write (file_str+"<| Time is |>"+out) Fid.write ("\ r \ n")defGetFileName (path, warp):#f_list = os.listdir (path) #RootDir = OS.GETCWD ()RootDir =Path LogName= warp[1:] +'_log.txt'FID= Open (LogName,'W') for(Dirpath, Dirnames, filenames)inchOs.walk (rootdir): forFileNameinchFilenames:pathname=os.path.join (dirpath, filename)ifOs.path.splitext (pathname) [1].lower () = =warp:gettime (Pathname,fid) fid.close ()if __name__=="__main__": Print("Begin Time:"+ Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())) RootDir="d:\\mooc\\ Video Material"Warp=". flv"GetFileName (RootDir, warp) warp=". mp4"GetFileName (RootDir, Warp)Print("End Time:"+ Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()))
[Original] Get video file length by cooperating with Ffmpeg.exe