6 ms·
Go CLI to calculate total media duraton in directories
- mddysr 3y agoAzmena let's you show total duration of media files in directories and sub-directories.
- abdusco 3y agoWhat are the possible use cases for this tool? Why would I want to find out the total runtime of all videos in a directory? Also, you might wanna limit concurrency[0] instead of spawning many ffprobe instances at the ~same time. [0]: https://github.com/sourcegraph/conc https://github.com/sourcegraph/conc In another note, ChatGPT suggests this shell command to do the same thing. It doesn't process files in parallel though. find . -name "*.mp4" -print0 | \ xargs -0 -I {} ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 {} | \ awk '{sum += $1} END {print sum}'
- iruoy 3y agoThis way it will output time in H:MM:SS find . -type f -print0 | \ xargs -0 -I {} ffprobe -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 {} | \ awk '{s += $1} END {printf "%d:%.2d:%.2d\n", s/3600, s%3600/60, s%3600%60}'
- deleted 3y ago[deleted]
- metadat 3y agoSimply adding the `-P 10` flag to xargs will make it run 10 (or however many processes you want) in parallel.
- o1y32 3y agoOne use case is that if you have a folder of (presumably legitimately acquired, or you know what I mean) movie files, you can figure out how long it will take you to finish them. Although number of video files * 2 hours/file is also likely a very good estimate. Although I seriously doubt data hoarders care about that. A movie will be eventually watched someday. If they run out of space, they'll get another drive. Storage is cheap.
- forgotpwd16 3y ago>Why would I want to find out the total runtime of all videos in a directory? You wanna know how long will it take you to finish that lecture playlist you just downloaded. You're a teacher and want to show some videos but you're limited in time. You want to know how many hours of music you've got.
- mddysr 3y agoi am checking the `conc` package. thanks for the suggestion :) As for the too use cases, I made it primarily to see how long a playlist or a course will take me to complete, but it can be used for other scenarios i guess.
- d0mine 3y agoIn Python: https://stackoverflow.com/questions/17185348/how-to-get-avi-files-length https://stackoverflow.com/questions/17185348/how-to-get-avi-...
- netmare 3y agoAs long as we're golfing: In PowerShell, using my personal script library: F:films> ls -rec -file | gec video | gvi | ndur 372:18:09 where: - `ls -rec -file` gets all files recursively under CWD (F:films) - `gec video` selects video files via extension (gec -> Get-ExtensionCategory) - `gvi` uses FFPROBE to get video info in custom object (gvi -> Get-VideoInfo) - `ndur` sums Duration property of objects and converts seconds to 'hhh:mm:ss' Most people I've shown this have found the syntax and aliases confusing and non-intuitive. They prefer the find/xargs/awk incantations, which, I'm told, are more elegant, correct and precise. After that, I'm usually speechless.
- forgotpwd16 3y ago>using my personal script library That's like those hacking scenes where they do: $ ./hack Are those `gec`, `gvi`, certainly `ndur` isn't, part of pwsh default installation? If not how much works it needs to implement them? You may quickly find out why peeps prefer the Unix incantations. (Also will assume only one of those two approaches come with manuals for commands run.)
- netmare 3y agoThese are all my scripts. They're object-oriented, self-documented, tab-completable and a `hg clone` away. They're simply more polished versions of what I could do on Windows with built-in PowerShell (and FFPROBE of course): F:films> filter probe_format { ffprobe $_.fullname -v error -show_entries format=duration -of json | convertfrom-json | % format } F:films> ls -file -rec | ? extension -in .mp4,.avi,.mkv | probe_format | measure -sum duration | % { New-TimeSpan -Seconds $_.sum } | % tostring 15.12:18:09 # same result as before (15days+12hours, etc.) Even this makes much more sense to me than the Unix equivalent. I realize that Bash/AWK was better than CMD.EXE batch files, but, come on...
- DerekL 3y agoTitle is misspelled, it should be “duration”.
- mddysr 3y agomy bad. blame anxiety :)
- SushiHippie 3y agoOff topic question: I saw in the gif that you use arabic directory names. Would it be more convenient for you to have a RTL terminal than a LTR? Never thought about this, also don't know if this is a dumb question.