Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th February 2019, 17:45   #1  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Get width or height and add it to file's name with PowerShell ?

Hi,
for some videos, I'd like to add their width or height in their file's name but I can't figure out how to make it (if possible) with PowerShell.
I know that some metadatas are usable to be added in file's name ; this batch command line works to add the "last modification date" at the end of all file's name in a folder ;
Code:
get-childitem -Path "F:\vid\" | ForEach-Object {$_ | Rename-Item -NewName {$_.Basename + ' ' + ("{0:yyyy-MM-dd HH\hmm}" -f $_.LastWriteTime) + $_.Extension }}
And I was wondering if the same kind of process could work with other metadatas, as video resolution.
I tried this on an mp4 (Windows 7 can display its resolution in the bottom part of the explorer when I click on it, thus I guess there should be a way to recover this information) but it doesn't work ;
Code:
get-childitem -Path "F:\vid\" | ForEach-Object {$_ | Rename-Item -NewName {$_.Basename + ' ' + ("{0:0-9}" -f $_.FrameHeight) + $_.Extension }}
It's not refused but it only adds a space, no resolution. I guess the error is in the ("{0:0-9}" -f $_.FrameHeight) part.
I tried several variants (0:^[1-3000], 0:^0-9) but the result is always the same.

Does anybody know how to achieve this ?
Or maybe with ffprobe ?
Thanks.
Music Fan is offline   Reply With Quote
Old 25th February 2019, 18:08   #2  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Hello,

I do such stuff all the time with simple batch files and the CLI version of MediaInfo.

Please tell me your desired target file name format, and I will hack something together for you. I suppose you want the capability to do this for all video files in a folder. Do you want to delete the original files and just keep the renamed files, or do you want to keep the original files, too?


Cheers
manolito
manolito is offline   Reply With Quote
Old 25th February 2019, 18:14   #3  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Thanks, I'd like to keep the original files, thus export the new ones in another folder.
But you can give both scripts, it may be useful

For the target file name format : original name + space + resolution (width or height or both with a point between them).
For example ;
my video.mp4
becomes
my video 1280.720.mp4

Music Fan is offline   Reply With Quote
Old 25th February 2019, 18:38   #4  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Alright, I'll do it later tonite...

Fortunately I don't need to do this from scratch, I can reuse most of the code. But I just started to do my tax return for last year, I don't want to interrupt this right now.
manolito is offline   Reply With Quote
Old 25th February 2019, 19:19   #5  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
No problem, I'm not in a hurry.
Actually, I believe that i don't need to keep the original files ; that's only a name change after all, not a re-encoding.
Music Fan is offline   Reply With Quote
Old 25th February 2019, 23:41   #6  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Alright, here we go:
https://www.sendspace.com/file/5cytwp

Extract the 2 files into a folder of your choice, then drag & drop (or copy & paste) the source file(s) on the "Rename_Resolution.bat" file.

Some notes:
The "Rename_Resolution.bat" file works like a droplet. Highlight one or many source files from a folder and drag & drop them on the batch file. You can also create a link to the batch file on your desktop to make it easier.

By default the source files are renamed. You can edit the batch file to change the default behavior to copying the source files.

I used the older MediaInfo version 18.05. Zenitram changed the interface considerably after this version. I have no idea if newer versions will work, try it for yourself.

You can easily expand the renaming capabilities by adding additional MediaInfo properties (like frame rate or aspect ratio). The MediaInfo CLI download comes with comprehensive documentation about the supported file properties.


Cheers
manolito

Last edited by manolito; 26th February 2019 at 00:01.
manolito is offline   Reply With Quote
Old 26th February 2019, 17:04   #7  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Thanks, this works well !

This gives me an idea : is there a way to add an i (for interlaced) or a p (for progressive) after the resolution (without space) ?
1280.720p, 720.576i ...
It's not that important but that would be cool

Music Fan is offline   Reply With Quote
Old 26th February 2019, 18:10   #8  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Sure, no problem...

https://www.sendspace.com/file/n5rgn0
manolito is offline   Reply With Quote
Old 26th February 2019, 19:58   #9  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Great!



I noticed a strange thing with one avi file : the resolution has been added but the end of the name was erased
But I tested with your second version, no more problem

I still have a request : sometimes, there is no information about scan type and nothing is added after resolution.
As it probably means in (nearly) all cases that it's progressive, could you add a "p" at the end anyway ?
Music Fan is offline   Reply With Quote
Old 26th February 2019, 20:21   #10  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
This is hard to debug without a source file sample. In the latest version I changed the way how the MediaInfo output is exported into an environment variable. The old version used intermediate txt files, the new version does it directly with a FOR /F command. I had hoped that this would improve the speed, but it does not. If it fixes the output with one of your source files, all the better...

For files where MediaInfo does not report the ScanType value, this could have many reasons. New file formats might be MBAFF instead of Interlaced, but I think this is a special "Interlaced" format. It would be nice if you could upload such a file where my routine fails (I guess you know how to cut out a short sample...). Just blindly adding "p" seems a bit risky to me.


Cheers
manolito
manolito is offline   Reply With Quote
Old 27th February 2019, 08:43   #11  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Ok, but if it's MBAFF, we could maybe add in the script ;
IF !%type%==!MBAFF SET type=i
and "if no scan type, set p" (but I don't know how to make it).
Music Fan is offline   Reply With Quote
Old 27th February 2019, 18:14   #12  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
OK, check out this one:
https://www.sendspace.com/file/24j1w6

For MBAFF and PAFF it will report "i", if there is no ScanType it will report "p".
manolito is offline   Reply With Quote
Old 28th February 2019, 09:16   #13  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Thanks !
In some cases, I may need also the framerate, thus I could edit the file to create a second bat : can you give just the line to be added in the script ? No need to post another bat.

Suggestion : if there is nothing after the point, write only what is before, thus for 30.000 FPS, write only 30, but if i's 29.970, write 29.97.
In other words, remove everything atfer the last digit which is not a 0, but only after the point of course (if possible), not to have 3 instead of 30.
Sorry to be boring

Last edited by Music Fan; 28th February 2019 at 15:31. Reason: form
Music Fan is offline   Reply With Quote
Old 28th February 2019, 18:25   #14  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Do you need the frame rate combined with the frame size and scan type in one file name, or do you want a second batch file which only adds the frame rate to the file name?

Luckily MediaInfo can report the raw frame rate exactly in the format you want, so this should not be a problem (string formatting is not a strong point of the batch language - it could be done, though).

One problem might be if you feed a file with variable frame rate to the batch file. For such VFR files MediaInfo does not report a frame rate at all, it just reports "VFR". There are 2 possible workarounds:

1. Older MediaInfo versions behaved differently, they did report a frame rate for VFR files. Not sure if I can find such an older version, and an older version might have problems with newer formats.

2. AVSMeter also reports frame rates for VFR files. But here I would have to apply some nasty string formatting tricks...


Cheers
manolito
manolito is offline   Reply With Quote
Old 28th February 2019, 22:22   #15  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
I went ahead and made 2 batch files for adding the frame rate to the file name. For now I assumed that you want a separate batch file for the frame rate thing, but of course this can be changed.
Download link:
https://www.sendspace.com/file/0wvdnh

First of all my assumption that MediaInfo can already manage the string format to your needs was wrong. The documentation is incorrect. So I had to apply my nasty batch file tricks, wasn't so hard after all.

The first method is to use the older MediaInfo version 0.7.58 which still reports fps values for VFR sources. It is from 2012, so I am not sure how modern formats like HEVC are handled. Of course you can also try this batch file with a current MediaInfo version, but then you will not get any fps value for VFR sources.

The other method uses AVSMeter to determine the frame rate. Of course this requires that you have AviSynth installed on your computer. The DSS2 source filter must also be installed in the "AviSynth\Plugins" folder.


Cheers
manolito
manolito is offline   Reply With Quote
Old 1st March 2019, 09:18   #16  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Quote:
Originally Posted by manolito View Post
Do you need the frame rate combined with the frame size and scan type in one file name
Yes

Quote:
Originally Posted by manolito View Post
One problem might be if you feed a file with variable frame rate to the batch file. For such VFR files MediaInfo does not report a frame rate at all, it just reports "VFR".
That's ok, VFR is enough. If I wanna know more about the file, I will open it in Mediainfo.
Anyway, I use very rarely VFR encodings.
Music Fan is offline   Reply With Quote
Old 1st March 2019, 18:34   #17  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Quote:
Originally Posted by Music Fan View Post
That's ok, VFR is enough. If I wanna know more about the file, I will open it in Mediainfo.
This won't help you, the MediaInfo GUI also does not report any frame rate for VFR files...

OK, I will add the frame rate routine to the original batch file. I will add the older MediaInfo version 0.7.58 in a separate subfolder so you can switch between the versions. Will upload in a few hours.
manolito is offline   Reply With Quote
Old 1st March 2019, 18:43   #18  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Thanks.

Quote:
Originally Posted by manolito View Post
This won't help you, the MediaInfo GUI also does not report any frame rate for VFR files...
It shows an average frame rate (maybe not always).
Music Fan is offline   Reply With Quote
Old 1st March 2019, 20:47   #19  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Only if the container is not MKV. Have a look at this little dispute I had with Zenitram a while ago:
https://forum.doom9.org/showthread.p...34#post1739434

Anyways, the new version is ready for download:
https://www.sendspace.com/file/fkqmav


Have fun
manolito
manolito is offline   Reply With Quote
Old 2nd March 2019, 09:37   #20  |  Link
Music Fan
Registered User
 
Join Date: May 2009
Location: Belgium
Posts: 1,744
Great, thanks !
I see that you didn't put this line ;
Code:
IF NOT DEFINED height GOTO next_file
It's done for width and type but not height, I added it.
Music Fan is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:22.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.