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. |
|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 | Link |
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
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 }} 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 }} 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. |
![]() |
![]() |
![]() |
#2 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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 |
![]() |
![]() |
![]() |
#3 | Link |
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
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 ![]() |
![]() |
![]() |
![]() |
#4 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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. |
![]() |
![]() |
![]() |
#6 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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. |
![]() |
![]() |
![]() |
#7 | Link |
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
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 ![]() ![]() |
![]() |
![]() |
![]() |
#9 | Link |
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
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 ![]() As it probably means in (nearly) all cases that it's progressive, could you add a "p" at the end anyway ? ![]() |
![]() |
![]() |
![]() |
#10 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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 |
![]() |
![]() |
![]() |
#12 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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". |
![]() |
![]() |
![]() |
#13 | Link |
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
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 |
![]() |
![]() |
![]() |
#14 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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 |
![]() |
![]() |
![]() |
#15 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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 |
![]() |
![]() |
![]() |
#16 | Link | ||
Registered User
Join Date: May 2009
Location: Belgium
Posts: 1,741
|
Quote:
![]() Quote:
Anyway, I use very rarely VFR encodings. |
||
![]() |
![]() |
![]() |
#17 | Link | |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
Quote:
![]() 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. |
|
![]() |
![]() |
![]() |
#19 | Link |
Registered User
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,062
|
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 |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|