How can I organize my videos in folders according to year-month-day

Started by lamola, September 12, 2019, 11:13:11 AM

Previous topic - Next topic

lamola

Hello,

I want to organize my home video collection into directories according to the year-month-day (directory name = yyyy-mm-dd).
The videos are in avi and code dv format, or mp4 format and h264 format.
Is it possible to do it with exiftool? Or, do I need another program?

On the other hand, in my previous video editing program (Edius) I could superimpose the date and time on the edited videos but in my current video editor (Kdenlive) it is not possible (or maybe I don't know how to do it)

Thank you very much for your help.

StarGeek

Quote from: lamola on September 12, 2019, 11:13:11 AM
I want to organize my home video collection into directories according to the year-month-day (directory name = yyyy-mm-dd).
The videos are in avi and code dv format, or mp4 format and h264 format.
Is it possible to do it with exiftool? Or, do I need another program?

There are plenty of examples in the docs. Here's one on the Writing "FileName" and "Directory" tags page and another in the main docs under renaming examples.

The basic command for .MP4 files would be
exiftool -d "/path/to/new/directory/%Y-%m-%d" "-Directory<CreateDate" <FileOrDir>
Replace /path/to/new/directory/ with the correct path to where you want the file located.

With AVI files, they may not have embedded timestamps, as it's an older filetype.  You would first run
exiftool -time:all -a -s -ext AVI <File>
on one of the files to figure out if they have a timestamp you can use.  If you find one, you could then replace CreateDate in the above command with the name of that tag.  You would also have to add -ext AVI because exiftool doesn't normally process avi files by default (see FAQ #16).

QuoteOn the other hand, in my previous video editing program (Edius) I could superimpose the date and time on the edited videos but in my current video editor (Kdenlive) it is not possible (or maybe I don't know how to do it)

I'm not sure of your question here, but exiftool can't modify a video stream, so it can't do this.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lamola

Thanks StarGeek,

I have executed the command you tell me and also another command changing -time: all to -all. These are the results:
C:\Users\KINGSTON>"C:\Archivos PORTABLES\Exiftool\exiftool.exe" -time:all -a -s -ext AVI "C:\Archivos PORTABLES\Exiftool\Cinta143.20140913-09-24-10.00.avi"
FileModifyDate                  : 2014:09:14 12:23:16+02:00
FileAccessDate                  : 2019:09:13 16:52:38+02:00
FileCreateDate                  : 2019:09:13 16:52:37+02:00


C:\Users\KINGSTON>"C:\Archivos PORTABLES\Exiftool\exiftool.exe" -all -a -s -ext AVI "C:\Archivos PORTABLES\Exiftool\Cinta143.20140913-09-24-10.00.avi"
ExifToolVersion                 : 11.50
FileName                        : Cinta143.20140913-09-24-10.00.avi
Directory                       : C:/Archivos PORTABLES/Exiftool
FileSize                        : 27 MB
FileModifyDate                  : 2014:09:14 12:23:16+02:00
FileAccessDate                  : 2019:09:13 16:52:38+02:00
FileCreateDate                  : 2019:09:13 16:52:37+02:00
FilePermissions                 : rw-rw-rw-
FileType                        : AVI
FileTypeExtension               : avi
MIMEType                        : video/x-msvideo
FrameRate                       : 25
MaxDataRate                     : 3891 kB/s
FrameCount                      : 185
StreamCount                     : 2
ImageWidth                      : 720
ImageHeight                     : 576
StreamType                      : Video
VideoCodec                      : dvsd
VideoFrameRate                  : 25
VideoFrameCount                 : 185
Quality                         : 0
SampleSize                      : Variable
BMPVersion                      : Windows V3
ImageWidth                      : 720
ImageHeight                     : 576
Planes                          : 1
BitDepth                        : 24
Compression                     : dvsd
ImageLength                     : 144000
PixelsPerMeterX                 : 0
PixelsPerMeterY                 : 0
NumColors                       : Use BitDepth
NumImportantColors              : All
StreamType                      : Audio
AudioCodec                      :
AudioSampleRate                 : 32000
AudioSampleCount                : 236800
Quality                         : 0
SampleSize                      : 4 bytes
Encoding                        : Microsoft PCM
NumChannels                     : 2
SampleRate                      : 32000
AvgBytesPerSec                  : 128000
BitsPerSample                   : 16
TotalFrameCount                 : 185
Duration                        : 7.40 s
ImageSize                       : 720x576
Megapixels                      : 0.415


The datetime does have it somewhere because with the Mediainfo program it informs about this data, as you can see in the output I transcribe.
PROGRAM MEDIAINFO
General
Complete name                            : C:\Archivos PORTABLES\Exiftool\Cinta143.20140913-09-24-10.00.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
Commercial name                          : DVCAM
File size                                : 26.6 MiB
Duration                                 : 7 s 400 ms
Overall bit rate mode                    : Constant
Overall bit rate                         : 30.2 Mb/s
Recorded date                            : 2014-09-13 09:24:10.000

Video
ID                                       : 0
Format                                   : DV
Commercial name                          : DVCAM
Codec ID                                 : dvsd
Codec ID/Hint                            : Sony
Duration                                 : 7 s 400 ms
Bit rate mode                            : Constant
Bit rate                                 : 24.4 Mb/s
Width                                    : 720 pixels
Height                                   : 576 pixels
Display aspect ratio                     : 4:3
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Standard                                 : PAL
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Bottom Field First
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 2.357
Time code of first frame                 : 00:03:05:20
Time code source                         : Subcode time code
Stream size                              : 25.4 MiB (96%)
Encoding settings                        : wb mode= / white balance= / fcm=auto focus

How will mediainfo get the information?

Thanks in advance


StarGeek

I did a slight edit on your post so I could read the data easier.

Hmmm...  It looks like Mediainfo is finding something that exiftool is not.  The time is off from the FileModifyDate by a day and 3 hours, so it's not using that, which is common thing for a lot of programs to read.

Unfortunately, I can't offer any advice in this case.  And Phil is currently away on vacation until late September.  If you're able to make a small sample available, through Google drive or Dropbox for example, he might want to take a look at it and see what's up.

I'd suggest hitting the "Notify" button in the upper right corner of this thread if you would like to get an email when there's a response to this thread.

Edit: Oops, wrong link to top of this thread, fixed.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lamola

Thanks for everything, I will wait for Phil in case he has any solution to my problem.

greybeard


lamola

A sample.

LINK:  https://1drv.ms/f/s!Ak37_ejSsRf7pns939Hs0kwazLRt

StarGeek

This is definitely going to take some checking from Phil.  I did some poking around looking through the file and not sure where MediaInfo is pulling the data.  I found this list of supported tags on the MediaInfo website.  The "Recorded_Date" gives some details where it would take the data from, but there's nothing under RIFF, which would encompass AVI files.  Did some searching for the obvious plain text possibilities (2014 or DVCPRO) and nothing in the file in plain text.  FFProbe doesn't pull up any of the data the MediaInfo does.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Hayo Baan

Interesting! I analysed both files you uploaded and I really can't see where the dates as reported by Mediainfo are coming from. The date tags in the mov file for instance are actually all 0 and if there are date tags in the avi file, then exiftool is currently unable to find them. Still, for both files Mediainfo reports recording dates so they must be present somewhere in the files, but not at a "standard" location. Perhaps Phil is able to determine where they are coming from?
Hayo Baan – Photography
Web: www.hayobaan.nl

greybeard

For the avi file the recorded date is in the LIST_movi chunk that Exiftool doesn't appear to parse.

If you run exiftool with the -v2 switch you will seem the chunk listed but the date/time fields haven't been extracted.


StarGeek

Please be patient.  Phil is probably still on vacation.  He might be back tomorrow or the next day.  The last patch notes said his vacation is through the 24th. 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

greybeard

My guess is that this will be non-trivial (even for Phil)

Why not just use mediainfo?

Here is an example that generates a series of move commands for each of the AVI files. You would save the commands in a file and run as a batch.
It has the advantage that you can read the batch file and make sure it does it exactly what you want before you run it.
(the exact syntax will depend on your operating system and command shell):

a) Create directory structure:
mediainfo --Inform="General;mkdir %Recorded_Date%" *.avi | sed -e 's/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9].000//g'

b) Move files
mediainfo --Inform="General;mv %FileName%.avi %Recorded_Date%/%FileName%.avi" *.avi | sed -e 's/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9].000//g'

(The "sed" part of the command is being used to remove the time part of the Recorded date - if you don't have sed then something else would be needed)

lamola

Thank you for your attention but with what S.O. Are the commands written?
My S.O. it's windows 10.
lamola

greybeard

Those were Linux (or a Linux-like shell under Windows)

I just tested these under the Windows Powershell

mediainfo --Inform="General;mkdir %Recorded_Date%\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}
mediainfo --Inform="General;mv %FileName%.avi %Recorded_Date%/%FileName%.avi\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}

greybeard

Quote from: greybeard on September 24, 2019, 11:03:16 AM
Those were Linux (or a Linux-like shell under Windows)

I just tested these under the Windows Powershell

mediainfo --Inform="General;mkdir %Recorded_Date%\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}
mediainfo --Inform="General;mv %FileName%.avi %Recorded_Date%/%FileName%.avi\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}

A couple of corrections as I don't really understand much about Windows

When I first ran these commands in the Powershell they outputted a double-byte character set.

I ended up running the following before the commands:

$PSDefaultParameterValues = @{ '*:Encoding' = 'utf8' }

Also the Linux "mv" command above doesn't seem to work for Windows - it should be "move"

mediainfo --Inform="General;mkdir %Recorded_Date%\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}
mediainfo --Inform="General;move %FileName%.avi %Recorded_Date%/%FileName%.avi\r\n" *.avi  | %{$_ -replace " \d\d:\d\d:\d\d.000",""}

StarGeek

Quote from: greybeard on September 25, 2019, 07:05:20 AM
When I first ran these commands in the Powershell they outputted a double-byte character set.

If Powershell doesn't think that the output when piped/redirected is in unicode, it will assume it is ascii and "help" you by converting it to unicode.  This is a big problem when trying to extract embedded preview images.  See this post for details and links.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

greybeard

Quote from: StarGeek on September 25, 2019, 12:12:00 PM
Quote from: greybeard on September 25, 2019, 07:05:20 AM
When I first ran these commands in the Powershell they outputted a double-byte character set.

If Powershell doesn't think that the output when piped/redirected is in unicode, it will assume it is ascii and "help" you by converting it to unicode.  This is a big problem when trying to extract embedded preview images.  See this post for details and links.

Thanks - it caused me much confusion

lamola

THANKS greybeard and StarGeek but I find the command very confusing and dangerous.
I hope to see if Phil can help me in this, I have hundreds of files to order and I don't like the idea of ​​doing it one by one.
Thanks for everything
lamola

greybeard

Quote from: lamola on September 29, 2019, 03:35:28 AM
THANKS greybeard and StarGeek but I find the command very confusing and dangerous.
I hope to see if Phil can help me in this, I have hundreds of files to order and I don't like the idea of ​​doing it one by one.
Thanks for everything
lamola

I understand your caution.

Whatever solution you go with its recommended to back everything up before you start.

Phil Harvey

Quote from: lamola on September 29, 2019, 03:35:28 AM
I hope to see if Phil can help me in this,

I don't have time to read this whole thread.  Is the problem that PowerShell mangles the files?  If so, the solution is simple: Don't use PowerShell.  Use cmd.exe instead.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

greybeard

No the problem is that Exiftool doesn't currently parse out certain dates from some types of video file (and the OP would rather use Exiftool than Mediainfo)

StarGeek

You can find a sample file in this post. greybeard figured out that a time stamp that MediaInfo detects but exiftool does not is probably in a LIST chuck in the file.

The PowerShell posts are about figuring out an alternative way to do what the user wants since exiftool doesn't read the timestamp.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lamola

Hello everyone,
Programs like DVdate by Paul Gagla and Windv123 by Petr Mourek read and manage the date and time of the video.
Windv123 captures the video from the video camera and records it on the computer with the name of the file "year-month-day-hour-minutes-seconds-frames" of the first frame of the video.
DVdate overwrites the date and time of the capture in each frame. However, none of the programs can be used to move the videos to directories sorted by "year-month-day".
The videos are in .avi format and codec minidv of sony, canon and panasonic
Thanks.

Phil Harvey

Right, thanks.

The LIST_movi chunk that greybeard refers to in the AVI file is the audio/video data, which in general Exiftool doesn't parse.  ExifTool is a metadata utility, and unfortunately it seems as if there is no date/time metadata in either the AVI or MP4 video posted.

I have made some exceptions, such as AVCHD (M2TS) files, for which ExifTool does parse the video stream (because these files have no metadata), but I really don't want to get into this can of worms for other formats if I can avoid it.  (Read here for a bit of a rant about this.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

lamola

Thanks Phil, I understand that exiftool can't do anything because avi-minidv files don't contain capture date metadata. However, they do have this data at fixed points in the structure of each video frame.
On the other hand, in the capture I made of the video camera, the file name I gave to the capture was "Tapennn.aaaammdd-hh-mm-ss.xx.avi" where
yyyy year, mm month, dd day, etc "
How could I sort these files into directories according to year-month-day and checking that the date string is correct?
Thank you

Hayo Baan

Quote from: lamola on September 30, 2019, 03:22:55 AM
Thanks Phil, I understand that exiftool can't do anything because avi-minidv files don't contain capture date metadata. However, they do have this data at fixed points in the structure of each video frame.
On the other hand, in the capture I made of the video camera, the file name I gave to the capture was "Tapennn.aaaammdd-hh-mm-ss.xx.avi" where
yyyy year, mm month, dd day, etc "
How could I sort these files into directories according to year-month-day and checking that the date string is correct?
Thank you

I see no year in your filename, but assuming the aaaa is the year, you could do something like this

exiftool '-directory<${filename;s/Tape\d+\.(\d{4})(\d{2})(\d{2})/$1$2$3/} -if '$filename =~ /Tape\d+\.\d{8}\-\d{2}-\d{2}-\d{2}/' FILESorDIRS

This would put your files in a directory named yyyymmmdd. I split the year, month and day into separate parts to easily allow changing their order, adding delimiters, etc. (e.g. .../$1-$2-$3/... would add dashes between the year, month and day parts). If this isn't what you want, please provide an example that illustrates what you want to achieve.

Note: if you're on windows replace the single quotes with double quotes.
Hayo Baan – Photography
Web: www.hayobaan.nl

lamola

Sorry, the initial year was in Spanish (my source language) year in Spanish is año.
I will test your command.
Thanks