Tuesday, August 11, 2020

#26 2019-11-20 01:21:09 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

byronheath wrote:

so the final out come will be 00:00:03:17 (the 17 will be represented in the frames)


You want to be formatted zero hours and zero minutes as 00:00 ? To be presented zeroes?

Last edited by KniazidisR (2019-11-20 01:22:13 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#27 2019-11-20 01:39:48 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

Yes

So if  the video was 1 hour 3 minutes 10sec and 17 frames it will be shown as 01:03:10:17

Or if the video was 1 minute 12 sec and 2 frames it would be shown as 00:01:12:02

If the video was 2 minute 5 seconds and 10 frames it would be shown as 00:02:05:10

Last edited by byronheath (2019-11-20 01:43:10 am)

Offline

 

#28 2019-11-20 02:15:07 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

As here?

Applescript:


use AppleScript version "2.5" -- 10.11 or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

-- get files
set theFolder to choose folder
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFolder)
set fileManager to current application's NSFileManager's defaultManager()
set {theFiles, theError} to fileManager's contentsOfDirectoryAtURL:theURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
-- eliminate non-video files
set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN %@" argumentArray:{{"mp4", "mov", "webm"}}
set vidFiles to theFiles's filteredArrayUsingPredicate:thePred

-- set up results array, formatter for duration
set theResults to current application's NSMutableArray's array()

-- lop through
repeat with aFile in vidFiles
   -- get localized name
   set {theResult, theName, theError} to (aFile's getResourceValue:(reference) forKey:(current application's NSURLLocalizedNameKey) |error|:(reference))
   -- create an AVAsset so you can get duration
   set theAsset to (current application's AVURLAsset's assetWithURL:aFile)
   set durationInfo to theAsset's duration() -- returns record like: {value:2911360, timescale:1000, flags:1, epoch:0}
   
   if durationInfo is missing value then
       set theTime to "unknown"
       set framesNumber to "unknown"
   else
       -- calculate duration in seconds and format as string
       set theSeconds to (value of durationInfo) / (timescale of durationInfo)
       
       -- Determine frames number here
       set theTracks to (get theAsset's tracks())
       repeat with i from 1 to count theTracks
           set aTrack to item i of theTracks
           if (aTrack's mediaType()) as string is "vide" then exit repeat
       end repeat
       set videoTrack to aTrack
       set frameRate to videoTrack's nominalFrameRate()
       set framesNumber to round ((theSeconds * frameRate) - (round (theSeconds * frameRate) rounding down))
   end if
   
   if framesNumber < 10 then
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":0" & framesNumber
   else
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":" & framesNumber
   end if
   (theResults's addObject:(current application's NSString's stringWithFormat_("%@ %@", theName's stringByDeletingPathExtension(), aDuration)))
end repeat

set aText to (theResults's componentsJoinedByString:linefeed) as text

tell application "Finder" to set folderName to name of theFolder
set filepath to (POSIX path of theFolder) & folderName & ".txt"
set openfile to open for access filepath with write permission
set eof of openfile to 0
write aText as «class utf8» to openfile
close access openfile

on secondsToHMS from theSeconds
   tell theSeconds
       tell {it div hours, it mod hours div minutes, it mod minutes}
           return "" & ((item 1) div 10) & ((item 1) mod 10) & ":" & ((item 2) div 10) & ((item 2) mod 10) & ":" & ((item 3) div 10) & ((item 3) mod 10)
       end tell
   end tell
end secondsToHMS

RESULT: ---> file_example_MP4_1920_18MG    00:00:31:00

I tested with 1 mp4 file in the chosen folder

Last edited by KniazidisR (2019-11-20 03:50:14 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#29 2019-11-20 03:09:43 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

Thank you

Thank you everything works perfect except the frames sad

it still doesn't represent the frames I am looking for

I have noticed get info in Mac rounds off the frames to closest second instead of showing the frames

I don't want it to round off the frame but show the actual frame number

For get info to round off the second from the frames it must be receiving that information

If you download the video I sent via Vimeo then the final timecode you see on the video would be
00:00:03:17 . The script now sees that clips duration as 00:00:04:00

I would like it show the actual duration of 00:00:03:17

Offline

 

#30 2019-11-20 03:48:16 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

I updated the last script as found 1 error. Need rounding down instead of rounding as integer. Try now.

NOTE: I can't download your video from Vimeo

Last edited by KniazidisR (2019-11-20 04:40:41 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#31 2019-11-20 05:59:44 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

Yes sorry I haven't explained myself properly

I don't want it round down or round off

Want the frame number that get info doesn't show

if the frame rate is 25fps then the timecode will roll over to the next second after the 24 frame

everything is great except I don't see the frames

Offline

 

#32 2019-11-20 06:09:32 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

if you download the Vimeo linked video I sent and get 00:00:03:17 that timecode from the script then that is what I am trying to achieve

That is the exact duration of the video clip

Ultimately that's what I am trying to get ... the exact duration down to the frame of the video in the folder

Offline

 

#33 2019-11-20 06:39:34 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

byronheath wrote:

Ultimately that's what I am trying to get ... the exact duration down to the frame of the video in the folder


I updated the script. You tried it? As I see, no. My script rounds as it is necessary, because doesn't exist half frame or 1.3 frame, but exists 1 frame, or 2 frames. It is integer value. And script shows it now. Get info rounds to nearest second, but my script rounds to the nearest whole number of frames. As it should be.

And I repeat, I can't download your Vimeo file to test. I already said that above.

So, open the last script from here and run. Not the script you have on your computer but that updated script from here. Say what you get in the text file.

Last edited by KniazidisR (2019-11-20 07:00:04 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#34 2019-11-20 07:00:01 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

Sorry I missed the part you said you couldn't download video file , my bad

Below is the result is get from the .txt file

TEST2_1    00:04:21:00
TEST1_1    00:02:09:00
Comp 1    00:00:03:00
TEST3_1    00:01:38:01

When I take each video files into editing software and look at actual duration they are as follows



TEST2_1    00:04:21:05
TEST1_1    00:02:09:11
Comp 1    00:00:03:17
TEST3_1    00:01:38:03

I was aking is your script rounding off the frame to the nearest 0 , is that's why all frames are displayed as 00 instead of the frame number of the file ?

the minute and seconds are displayed perfectly but the frames are not

when you had the frames of the entire duration displayed in previous script and I took that into frame calculator that converted back to (hh)(mm)(ss)(ff) it covered to exact timecode

Thank you for you time and effort into trying to help me figure this out

Last edited by byronheath (2019-11-20 07:00:37 am)

Offline

 

#35 2019-11-20 08:22:35 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

I changed little the script to get frames number simpler. This should work:

Applescript:


use AppleScript version "2.5" -- 10.11 or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

-- get files
set theFolder to choose folder
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFolder)
set fileManager to current application's NSFileManager's defaultManager()
set {theFiles, theError} to fileManager's contentsOfDirectoryAtURL:theURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
-- eliminate non-video files
set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN %@" argumentArray:{{"mp4", "mov", "webm"}}
set vidFiles to theFiles's filteredArrayUsingPredicate:thePred

-- set up results array, formatter for duration
set theResults to current application's NSMutableArray's array()

-- lop through
repeat with aFile in vidFiles
   -- get localized name
   set {theResult, theName, theError} to (aFile's getResourceValue:(reference) forKey:(current application's NSURLLocalizedNameKey) |error|:(reference))
   -- create an AVAsset so you can get duration
   set theAsset to (current application's AVURLAsset's assetWithURL:aFile)
   set durationInfo to theAsset's duration() -- returns record like: {value:2911360, timescale:1000, flags:1, epoch:0}
   
   if durationInfo is missing value then
       set theTime to "unknown"
       set framesNumber to "unknown"
   else
       -- calculate duration in seconds and format as string
       set theSeconds to (value of durationInfo) / (timescale of durationInfo)
       
       -- Determine frames number here
       set theTracks to (get theAsset's tracks())
       repeat with i from 1 to count theTracks
           set aTrack to item i of theTracks
           if (aTrack's mediaType()) as string is "vide" then exit repeat
       end repeat
       set videoTrack to aTrack
       set frameRate to videoTrack's nominalFrameRate()
       set aMod to theSeconds - (round theSeconds rounding down)
       set framesNumber to round (aMod * frameRate) rounding down
   end if
   
   if framesNumber < 10 then
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":0" & framesNumber
   else
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":" & framesNumber
   end if
   (theResults's addObject:(current application's NSString's stringWithFormat_("%@ %@", theName's stringByDeletingPathExtension(), aDuration)))
end repeat

set aText to (theResults's componentsJoinedByString:linefeed) as text

tell application "Finder" to set folderName to name of theFolder
set filepath to (POSIX path of theFolder) & folderName & ".txt"
set openfile to open for access filepath with write permission
set eof of openfile to 0
write aText as «class utf8» to openfile
close access openfile

on secondsToHMS from theSeconds
   tell theSeconds
       tell {it div hours, it mod hours div minutes, it mod minutes}
           return "" & ((item 1) div 10) & ((item 1) mod 10) & ":" & ((item 2) div 10) & ((item 2) mod 10) & ":" & ((item 3) div 10) & ((item 3) mod 10)
       end tell
   end tell
end secondsToHMS

Last edited by KniazidisR (2019-11-20 08:23:13 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#36 2019-11-20 08:49:28 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

Oh my dude , you did it !!

THANK YOU , all of the videos clips are 1 frame out except one is perfect but I can live with that smile

Its probably just discrepancy with the video editing programs displaying the duration on timeline , its only 1 frame smile

Not sure where an extra frame was picked up but all is good

YAY

Thank you
Thank you
Thank you

Offline

 

#37 2019-11-20 10:34:11 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

byronheath wrote:

all of the videos clips are 1 frame out except one is perfect


Hi, byronheath.
Tell me - is one frame missing or is there an extra frame? If one frame is missing, then this inaccuracy is most likely to be corrected if you replace this:

Applescript:

set framesNumber to round (aMod * frameRate) rounding down

with this:

Applescript:

set framesNumber to round (aMod * frameRate) rounding up

Last edited by KniazidisR (2019-11-20 10:36:04 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#38 2019-11-20 11:41:47 pm

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

It had an extra frame

I seemed to fix it by replacing the script below

set framesNumber to round (aMod * frameRate) rounding down

with

set framesNumber to round (aMod * frameRate) - 1

and it seems to work perfectly

I also realised it would be less accurate if I had mixed frame rates in the folder I was trying to get durations from

Thank You so much

I was also wandering if it was possible and how I would go about it if I wanted each video clip in the folder to have its own text document with the text file name set to that of the video with title and duration

what would be the best way to go about this ?

Offline

 

#39 2019-11-20 11:59:50 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1262

Re: File metadata information

byronheath wrote:

I was also wandering if it was possible and how I would go about it if I wanted each video clip in the folder to have its own text document with the text file name set to that of the video with title and duration

what would be the best way to go about this ?


As here?

Applescript:


use AppleScript version "2.5" -- 10.11 or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

-- get files
set theFolder to choose folder
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFolder)
set fileManager to current application's NSFileManager's defaultManager()
set {theFiles, theError} to fileManager's contentsOfDirectoryAtURL:theURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
-- eliminate non-video files
set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN %@" argumentArray:{{"mp4", "mov", "webm"}}
set vidFiles to theFiles's filteredArrayUsingPredicate:thePred

-- set up results array, formatter for duration
set theResults to current application's NSMutableArray's array()

-- lop through
repeat with aFile in vidFiles
   -- get localized name
   set {theResult, theName, theError} to (aFile's getResourceValue:(reference) forKey:(current application's NSURLLocalizedNameKey) |error|:(reference))
   -- create an AVAsset so you can get duration
   set theAsset to (current application's AVURLAsset's assetWithURL:aFile)
   set durationInfo to theAsset's duration() -- returns record like: {value:2911360, timescale:1000, flags:1, epoch:0}
   
   if durationInfo is missing value then
       set theTime to "unknown"
       set framesNumber to "unknown"
   else
       -- calculate duration in seconds and format as string
       set theSeconds to (value of durationInfo) / (timescale of durationInfo)
       
       -- Determine frames number here
       set theTracks to (get theAsset's tracks())
       repeat with i from 1 to count theTracks
           set aTrack to item i of theTracks
           if (aTrack's mediaType()) as string is "vide" then exit repeat
       end repeat
       set videoTrack to aTrack
       set frameRate to videoTrack's nominalFrameRate()
       set aMod to theSeconds - (round theSeconds rounding down)
       set framesNumber to round (aMod * frameRate) - 1
   end if
   
   if framesNumber < 10 then
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":0" & framesNumber
   else
       set aDuration to (secondsToHMS from (round theSeconds rounding down)) & ":" & framesNumber
   end if
   set aText to (current application's NSString's stringWithFormat_("%@ %@", theName's stringByDeletingPathExtension(), aDuration)) as text
   
   tell application "Finder" to set folderName to name of theFolder
   set filepath to (POSIX path of theFolder) & aText & ".txt"
   set openfile to open for access filepath with write permission
   set eof of openfile to 0
   write aText as «class utf8» to openfile
   close access openfile
end repeat


on secondsToHMS from theSeconds
   tell theSeconds
       tell {it div hours, it mod hours div minutes, it mod minutes}
           return "" & ((item 1) div 10) & ((item 1) mod 10) & ":" & ((item 2) div 10) & ((item 2) mod 10) & ":" & ((item 3) div 10) & ((item 3) mod 10)
       end tell
   end tell
end secondsToHMS


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#40 2019-11-21 11:18:47 am

byronheath
Member
Registered: 2019-11-16
Posts: 13

Re: File metadata information

KniazidisR I can't thank you enough smile
THANK YOU

I combined both set aText to script part so I get both indvidual text files and all in one .

Thank you

You are to cool

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)