11 Mar 2016 @ 2:24 AM 

Previously, I wrote about Counting Lines of Code in a given directory. Recently, I had a similar curiousity- “how long are all the video files in this folder?” This seemed to be a good fit for a Python script.

The main question, then, is how do we determine the length of a video file in Python? Once we have that problem solved, we can effectively use the same code as the CodeCount and “sum” all the lengths together in much the same way that the Code Count script sums all the line counts.

The most straightforward approach I discovered was using ffmpeg to retrieve video information, redirecting the output to a temp file, and then finding the listed Duration in that temp file. We then take that determined duration and parse it, and create a Python TimeDelta. We can use that TimeDelta, and sum all the TimeDelta’s of the files in question to determine the total run time of all the videos in the specified folders.

A bit of checking code to allow for the use of *.* to total all ffmpeg compatible video files rounds this out- the syntax is the same as the Code Counter- VidLength.py <FileMask> <directory< and it will display all the files it analyzes and then a total duration.

Have something to say about this post? Comment!

Posted By: BC_Programming
Last Edit: 11 Mar 2016 @ 02:24 AM

EmailPermalink
Tags
Tags: , ,
Categories: Programming, Python, Scripting


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Tags
Comment Meta:
RSS Feed for comments

 Last 50 Posts
 Back
Change Theme...
  • Users » 43711
  • Posts/Pages » 364
  • Comments » 106
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

PP



    No Child Pages.

Windows optimization tips



    No Child Pages.

Software Picks



    No Child Pages.

BC’s Todo List



    No Child Pages.