Duration of mp3/mp4

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

Duration of mp3/mp4

Post by macroman » Sun Jun 12, 2016 11:21 am

It would be great if we can pull those durations from mp3s and mp4s that Windows already returning to us in the folder listing...

Code: Select all

MediaDuration>filemp4,mp4dur
this would be great :)

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Duration of mp3/mp4

Post by hagchr » Sun Jun 12, 2016 3:03 pm

You can eg download/install the free tool ExifTool and then the following would give the duration:

http://owl.phy.queensu.ca/~phil/exiftoo ... ml#running

Code: Select all

//Your audio/video file
Let>file="C:\Users\...\xxxxxx.m4a"

//Temporary file to store result
Let>file2=%TEMP_DIR%tmpexif.txt

Let>RP_WAIT=1
Run>cmd /c c:\windows\exiftool.exe %file% > %file2%

ReadFile>%file2%,strres

//Extract duration information 
RegEx>(?m-s)^Duration.+?(?=\d)\K.+,strres,0,m,nm,0
If>nm>0
    MDL>Duration: %m_1%
Endif

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Duration of mp3/mp4

Post by hagchr » Sun Jun 12, 2016 3:56 pm

Just to add in case anyone is new to this. The file you get contains a lot of metadata, in this case only Duration was extracted. For a video you would get something like this (depending on format/make):

Code: Select all

ExifTool Version Number         : 10.19
File Name                       : P1010131.MP4
Directory                       : D:/London Dec 2014/DCIM/101_PANA
File Size                       : 65 MB
File Modification Date/Time     : 2014:12:06 11:10:37+01:00
File Access Date/Time           : 2014:12:11 22:21:44+01:00
File Creation Date/Time         : 2014:12:11 22:21:44+01:00
File Permissions                : rw-rw-rw-
File Type                       : MP4
File Type Extension             : mp4
MIME Type                       : video/mp4
Major Brand                     : MP4 v2 [ISO 14496-14]
Minor Version                   : 0.0.1
Compatible Brands               : mp42, avc1
Movie Header Version            : 0
Time Scale                      : 360000
Duration                        : 7.00 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 4
Track Header Version            : 0
Track Create Date               : 2014:12:06 11:10:37
Track Modify Date               : 2014:12:06 11:10:37
Track ID                        : 1
Track Duration                  : 7.00 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 3840
Image Height                    : 2160
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 3840
Source Image Height             : 2160
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Color Representation            : nclx 1 1 1
Video Frame Rate                : 24
Time Code                       : 3
Balance                         : 0
Audio Format                    : twos
Audio Vendor ID                 : Panasonic
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 48000
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2014:12:06 11:10:37
Media Modify Date               : 2014:12:06 11:10:37
Media Time Scale                : 360000
Media Duration                  : 7.00 s
Media Language Code             : und
Handler Type                    : Time Code
Other Format                    : tmcd
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Panasonic
Camera Model Name               : AG-GH4
Orientation                     : Horizontal (normal)
Resolution Unit                 : inches
Software                        : Ver.1.1
Modify Date                     : 0000:00:00 00:00:00
Y Cb Cr Positioning             : Co-sited
Exposure Time                   : 1/50
F Number                        : 14.0
Exposure Program                : Manual
Exif Version                    : 0230
Date/Time Original              : 2014:12:06 11:10:37
Create Date                     : 2014:12:06 11:10:37
Components Configuration        : Y, Cb, Cr, -
Compressed Bits Per Pixel       : 2
Exposure Compensation           : 0
Max Aperture Value              : 2.8
Metering Mode                   : Multi-segment
Light Source                    : Unknown
Flash                           : Off, Did not fire
Focal Length                    : 12.0 mm
Image Quality                   : 4k Movie
Firmware Version                : 0.1.1.0
White Balance                   : Auto
Focus Mode                      : Manual
AF Area Mode                    : 1-area
Image Stabilization             : On, Mode 1
Macro Mode                      : Off
Shooting Mode                   : Movie Preview
Audio                           : Stereo
Data Dump                       : (Binary data 8 bytes, use -b option to extract)
Flash Bias                      : 0
Internal Serial Number          : (X15) 2014:09:04 no. 0029
Panasonic Exif Version          : 0407
Color Effect                    : Off
Time Since Power On             : 00:04:45.87
Burst Mode                      : Off
Sequence Number                 : 0
Contrast Mode                   : Unknown (0x18)
Noise Reduction                 : Unknown (65531)
Self Timer                      : Off
AF Assist Lamp                  : Disabled and Not Required
Color Mode                      : Normal
Optical Zoom Mode               : Standard
Conversion Lens                 : Off
Travel Day                      : n/a
World Time Location             : Home
Program ISO                     : 200
Advanced Scene Type             : 10
Faces Detected                  : 0
Color Temp Kelvin               : 5600
Bracket Settings                : No Bracket
WB Shift AB                     : 0
WB Shift GM                     : 0
Flash Curtain                   : n/a
Long Exposure Noise Reduction   : On
Panasonic Image Width           : 0
Panasonic Image Height          : 0
AF Point Position               : none
Num Face Positions              : 0
Lens Type                       : LUMIX G VARIO 12-35/F2.8
Lens Serial Number              : 14081201228
Accessory Type                  : NO-ACCESSORY
Accessory Serial Number         : 0000000
Lens Firmware Version           : 0.1.2.0
Faces Recognized                : 0
Title                           : 
Baby Name                       : 
Location                        : 
Country                         : 
State                           : 
City                            : 
Landmark                        : 
Intelligent Resolution          : Off
Burst Speed                     : 0
Intelligent D-Range             : Off
Clear Retouch                   : Off
City 2                          : 
Photo Style                     : Unknown (8)
Shading Compensation            : Off
Accelerometer Z                 : 276
Accelerometer X                 : -8
Accelerometer Y                 : -7
Camera Orientation              : Normal
Roll Angle                      : -0.7
Pitch Angle                     : 2.9
Timer Recording                 : Off
Internal ND Filter              : 0
HDR                             : Off
Shutter Type                    : Mechanical
Clear Retouch Value             : undef
Touch AE                        : Off
Maker Note Version              : 0147
Scene Mode                      : Off
WB Red Level                    : 2501
WB Green Level                  : 1024
WB Blue Level                   : 1878
Flash Fired                     : No
Text Stamp                      : Off
Baby Age                        : (not set)
Sub Sec Time                    : 201
Sub Sec Time Original           : 201
Sub Sec Time Digitized          : 201
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 3840
Exif Image Height               : 2160
Interoperability Index          : R98 - DCF basic file (sRGB)
Interoperability Version        : 0100
Sensing Method                  : One-chip color area
File Source                     : Digital Camera
Scene Type                      : Directly photographed
Custom Rendered                 : Custom
Exposure Mode                   : Auto
Digital Zoom Ratio              : 0
Focal Length In 35mm Format     : 26 mm
Scene Capture Type              : Standard
Gain Control                    : Low gain up
Contrast                        : Low
Saturation                      : Low
Sharpness                       : Soft
PrintIM Version                 : 0250
Compression                     : JPEG (old-style)
Thumbnail Offset                : 10652
Thumbnail Length                : 0
Movie Data Size                 : 67596824
Movie Data Offset               : 262152
Advanced Scene Mode             : Unknown (0 10)
Aperture                        : 14.0
Avg Bitrate                     : 77.3 Mbps
Blue Balance                    : 1.833984
Image Size                      : 3840x2160
Lens ID                         : LUMIX G VARIO 12-35mm F2.8
Megapixels                      : 8.3
Red Balance                     : 2.442383
Rotation                        : 0
Scale Factor To 35 mm Equivalent: 2.2
Shutter Speed                   : 1/50
Create Date                     : 2014:12:06 11:10:37.201
Date/Time Original              : 2014:12:06 11:10:37.201
Modify Date                     : 0000:00:00 00:00:00.201
Circle Of Confusion             : 0.014 mm
Field Of View                   : 69.4 deg
Focal Length                    : 12.0 mm (35 mm equivalent: 26.0 mm)
Hyperfocal Distance             : 0.74 m

macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

Re: Duration of mp3/mp4

Post by macroman » Sun Jun 12, 2016 7:44 pm

hagchr wrote:You can eg download/install the free tool ExifTool and then the following would give the duration:

http://owl.phy.queensu.ca/~phil/exiftoo ... ml#running

Code: Select all

//Your audio/video file
Let>file="C:\Users\...\xxxxxx.m4a"

//Temporary file to store result
Let>file2=%TEMP_DIR%tmpexif.txt

Let>RP_WAIT=1
Run>cmd /c c:\windows\exiftool.exe %file% > %file2%

ReadFile>%file2%,strres

//Extract duration information 
RegEx>(?m-s)^Duration.+?(?=\d)\K.+,strres,0,m,nm,0
If>nm>0
    MDL>Duration: %m_1%
Endif
Thank you for this! Works great!

macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

Re: Duration of mp3/mp4

Post by macroman » Fri Oct 28, 2016 4:29 am

After many tries, i finally discovered that this tool is reading mp3 files duration incorrectly. Both winamp and VLC player is telling me my mp3 is 22 minutes but exiftool is telling me it's 43 minutes long...

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Duration of mp3/mp4

Post by CyberCitizen » Fri Oct 28, 2016 4:54 am

What about something like this?

Haven't tested it as I am at work and I Spotify so no audio files.

http://superuser.com/questions/1087109/ ... -directory
FIREFIGHTER

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts