rename file with info from other file

Started by rodanny, August 10, 2023, 03:45:46 AM

Previous topic - Next topic

rodanny

Hello,
I have the following problem.
I have the following directory structure:

x:\work\originals\
       |
       \recode\

In folder originals have some file type mp4 .
In folder recode i have compress file type mp4 with same name from originals.

I want to copy the metadata of the files from the original directory to the recode directory, to rename the file from the recode directory according to the pattern: yyyymmdd_hhmmss_[camera name]_[original file name].mp4

I would also like to create a txt and json file with all the information about this file encoded but taken from the original file.

I managed to piece by piece, but I get stuck when renaming the new file and when generating txt and json files with the new name

Thank you very much
 

Phil Harvey

This is indeed a bit tricky.  What are you pulling the "camera name" from?  And are the original file names all the same length?  If the camera name or original file names are constant lengths, then it would be easy to determine the original file name from the renamed recoded file, and use this to generate the JSON/TXT output.  Otherwise, things get a bit more complicated.

Also, exactly what metadata do you want to copy to the recoded files?  And what do you want to write to the JSON/TXT files?

Assuming variable-length names and all metadata copied and written to JSON, and taking the camera model from a "Model" tag (unlikely to exist though), you could do this in 2 commands:

1. Copy metadata to recode files, adding OriginalFileName and renaming according to CreateDate and Model:

exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${createdate}_${model}_${filename}" "-originalfilename<filename" x:\work\originals\recode

2. Write JSON files from metadata in original file to output files of the recoded file names:

exiftool -ext mp4 -file1 "%d../$originalfilename" -file1:all -j -w %d%f.json x:\work\originals\recode

I haven't tested these, but if we are lucky they will do what you want.

- 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 ($).

rodanny

Hello @Phil Harvey, thanks.... so...

i need copy all meta info can be copied...., in JSON/TXT i want save all metainfo... -ee parameter, for keep all information can not be transferred from original file to recode file.
Name of new file need to be yyyymmdd_hhmmss_[cameraname]_[originalfilname].mp4

Need to make same same and for json/txt file.... for keeping in recode directory.

Best,
Danny

rodanny

#3
Quote from: Phil Harvey on August 10, 2023, 12:22:21 PMThis is indeed a bit tricky.  What are you pulling the "camera name" from?  And are the original file names all the same length?  If the camera name or original file names are constant lengths, then it would be easy to determine the original file name from the renamed recoded file, and use this to generate the JSON/TXT output.  Otherwise, things get a bit more complicated.

Also, exactly what metadata do you want to copy to the recoded files?  And what do you want to write to the JSON/TXT files?

Assuming variable-length names and all metadata copied and written to JSON, and taking the camera model from a "Model" tag (unlikely to exist though), you could do this in 2 commands:

1. Copy metadata to recode files, adding OriginalFileName and renaming according to CreateDate and Model:

exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${createdate}_${model}_${filename}" "-originalfilename<filename" x:\work\originals\recode

2. Write JSON files from metadata in original file to output files of the recoded file names:

exiftool -ext mp4 -file1 "%d../$originalfilename" -file1:all -j -w %d%f.json x:\work\originals\recode

I haven't tested these, but if we are lucky they will do what you want.

- Phil

i testing your command....

exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${createdate}_${model}_${filename}" "-originalfilename<filename" x:\work\originals\recode


but only transfer metadata, but not renamed..... why?
10x

rodanny

#4
Quote from: Phil Harvey on August 10, 2023, 12:22:21 PMThis is indeed a bit tricky.  What are you pulling the "camera name" from?  And are the original file names all the same length?  If the camera name or original file names are constant lengths, then it would be easy to determine the original file name from the renamed recoded file, and use this to generate the JSON/TXT output.  Otherwise, things get a bit more complicated.

Also, exactly what metadata do you want to copy to the recoded files?  And what do you want to write to the JSON/TXT files?

Assuming variable-length names and all metadata copied and written to JSON, and taking the camera model from a "Model" tag (unlikely to exist though), you could do this in 2 commands:

1. Copy metadata to recode files, adding OriginalFileName and renaming according to CreateDate and Model:

exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${createdate}_${model}_${filename}" "-originalfilename<filename" x:\work\originals\recode

2. Write JSON files from metadata in original file to output files of the recoded file names:

exiftool -ext mp4 -file1 "%d../$originalfilename" -file1:all -j -w %d%f.json x:\work\originals\recode

I haven't tested these, but if we are lucky they will do what you want.

- Phil


this is output when run your line command

f:\1\1\orig>exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${CreateDate}_${DeviceModelName}_${filename}" "-originalfilename<filename" f:/1/1/orig/recode/
Warning: [minor] The ExtractEmbedded option may find more tags in the media data - f:/1/1/orig/recode/../C0120.mp4
Error: Error creating file: f:/1/1/orig/recode/2023:04:17 13:23:56_DSC-RX100M7_C0120.mp4 - f:/1/1/orig/recode/C0120.mp4
    1 directories scanned
    0 image files updated
    1 files weren't updated due to errors


Can help me plese?

rodanny

#5
I managed to do the renaming correctly.
But I can't insert it into a .bat command file

This is command line and work individual.

exiftool -ext mp4 -tagsfromfile %d../%f.%e -all:all "-filename<${CreateDate} ${DeviceModelName}_${filename} " "-originalfilename<filename" f:/1/1/orig/recode/ -d "%Y%m%d %H%M%S"


When make a file test.bat with this comadn line.....doesn't work...
apear :

f:\1\1\orig>test.bat

f:\1\1\orig>exiftool -ext mp4 -tagsfromfile f.all "-filename<${CreateDate} ${DeviceModelName}_${filename} " "-originalfilename<filename" f:/1/1/orig/recode/ -d "mHS"
File 'f.all' does not exist for -tagsFromFile option

10x in advance

StarGeek

* 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).

rodanny

#7
add and a new question....
why
exiftool.exe -ext mp4 -ee -X -g4 c0003.mp4 > c0003.xml

work perfectly, but

exiftool.exe -ext mp4 -ee -X -g4 -file1 "%d../$originalfilename" -file1:all  -w %d%f.xml f:/1/1/orig
doesn't work?

sorry i'm newbie

rodanny

#8
Quote from: StarGeek on August 18, 2023, 11:28:51 AMSee FAQ #27
Thank you. Work Great...but...
i have other problem...

when run on command prompt:
exiftool -ext mp4 -file1 "%d../$originalfilename" -file1:all -j -w %d%f.json f:/1/1/orig/

i obtain file json with error:

[{
  "SourceFile": "f:/1/1/orig/C0003.mp4",
  "ExifToolVersion": 12.64,
  "FileName": "C0003.mp4",
  "Directory": "f:/1/1/orig/..",
  "Error": "Error opening file"
}]

Why?
I want save all data in json format laike option -ee

Phil Harvey

I'm not sure if Windows supports a syntax like "f:/1/1/orig/../C0003.mp4" to access "f:/1/1/C0003.mp4"

This works on Mac/Linux, but I can't test this in Windows right now.

- 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 ($).

StarGeek

Quote from: Phil Harvey on August 21, 2023, 08:55:02 AMI'm not sure if Windows supports a syntax like "f:/1/1/orig/../C0003.mp4" to access "f:/1/1/C0003.mp4"

It does.  One of my regular commands copies data from the parent directory with
-TagsFromFile %d../%f.jpg
* 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).

rodanny


Thank you. Work Great...but...
i have other problem...

when run on command prompt:
exiftool -ext mp4 -file1 "%d../$originalfilename" -file1:all -j -w %d%f.json f:/1/1/orig/

i obtain file json with error:

[{
  "SourceFile": "f:/1/1/orig/C0003.mp4",
  "ExifToolVersion": 12.64,
  "FileName": "C0003.mp4",
  "Directory": "f:/1/1/orig/..",
  "Error": "Error opening file"
}]

Why?
I want save all data in json format laike option -ee