Add frame width & height to filename

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Add frame width & height to filename

Post by Papoulka »

OK, I have searched on all keywords but I haven't even attempted this myself because (a) I don't know if it's possible in XY and (b) even if it can be done I have no idea where to start.

I have many miscellaneous video files (AVI etc) of sundry resolutions. I want to rename each with its frame width and height at the end. Thus:

football_july.avi

would become

football_july 512x272.avi

I'm open to any advice including "forget it" from those who know these things.

Thanks

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

Code: Select all

renameitem("* " . property("#299") . "x" . property("#301"));
#299 and #301 can be different. Depends on the used OS.

And if the video format delivers these values at all...

If not, you have to use a script that makes use of MediaInfo (CLI version)...
One of my scripts helped you out? Please donate via Paypal

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Add frame width & height to filename

Post by Papoulka »

Thank you, Highend. I see now how it would be done.

As it happens, under Win 7, the Properties are hard to extract although they appear OK in XY Columns. I tried having XY find them using the info in the Help:

text property("*width");

but it returned nothing.

The Help also suggested this for Win 7:

msg property("#299", "%winsysdir%\msvbvm60.dll");

but that did not give me Frame Width or Height.

I'm not yet at the point of using MediaInfo but I appreciate the tip towards that.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Add frame width & height to filename

Post by bdeshi »

PropFrames.png
You should open up the shown config panel and find the correct index of those properties for your system.

Since I see Frame height and Frame width are indexed as 283 and 285 and named so, I would use either of these to get them for current item.

Code: Select all

text property("#283"); text property("#285");

Code: Select all

text property("*frame_height"); text property("*frame_width");
substitute spaces in property names with _


btw, text property("*width"); will return width for images, not video files.
Papoulka wrote:msg property("#299", "%winsysdir%\msvbvm60.dll");
where?
To see the attached files, you need to log into the forum.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

Code: Select all

    $mediaInfo  = "D:\Users\Highend\Downloads\MediaInfo_CLI_0.7.72_Windows_i386\MediaInfo.exe";
    $resolution = replace(runret("$mediaInfo --Output=Video;%Width%x%Height% ""<curitem>"""), "<crlf>");
    if ($resolution) { renameitem("* $resolution"); }
    else             { status "No resolution found, aborted!", "FF0000", "stop"; }
Ofc you need to get the CLI version of MediaInfo (http://mediaarea.net/en/MediaInfo/Download/Windows) and change the path to it in the script
One of my scripts helped you out? Please donate via Paypal

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Add frame width & height to filename

Post by Papoulka »

.
Thank you Sammay and Highend! This solves my problem of adding frame width and height to the end of a video's filename.

For the use of others -

The following code (updated per post below by TheQwerty) is sufficient for .AVI, .MP4 and probably many other "simple" encodings:

Code: Select all

renameitem("* " . property("System.Video.FrameWidth") . "x" . property("System.Video.FrameHeight"));
But to cover more formats including MKV, make a command-line call to the MediaInfo util available via Highend's link:

Code: Select all

 $mediaInfo = "C:\XYplorer_p\Data\MediaInfo\MediaInfo.exe";
    $resolution = replace(runret("$mediaInfo --Output=Video;%Width%x%Height% ""<curitem>"""), "<crlf>");
    if ($resolution) { renameitem("* $resolution",,1,"-01"); }
    else             { status "No resolution found, aborted!", "FF0000", "stop"; }
I added flags to keep the existing extension and to handle name collisions. Also, I'm running Windows 7 but that shouldn't matter with the above techniques.
Last edited by Papoulka on 20 Jan 2015 20:16, edited 1 time in total.

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

Code: Select all

renameitem("* " . property("*frame_width") . "x" . property("*frame_height"));
Can't recommend this. These property names are language dependent. E.g. in Germany you would use *Bildhöhe and *Bildbreite. *frame_width | *frame_height don't exist.
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Add frame width & height to filename

Post by bdeshi »

For that matter, neither do I recommend property("#283") etc, for non-personal use.
These are OS-dependent.

The same property can have different indices in different OSes (heck, even different updates/software configuration of the same OS)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

These are OS-dependent.
Yes, they are. But it's way easier to support approx. 5 different prop values instead of hundreds (of different languages) :)
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Add frame width & height to filename

Post by TheQwerty »


yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Add frame width & height to filename

Post by yusef88 »

hi

Code: Select all

 $mediaInfo = "C:\XYplorer_p\Data\MediaInfo\MediaInfo.exe";
    $resolution = replace(runret("$mediaInfo --Output=Video;%Width%x%Height% ""<curitem>"""), "<crlf>");
    if ($resolution) { renameitem("* $resolution",,1,"-01"); }
    else             { status "No resolution found, aborted!", "FF0000", "stop"; }
didn't work for me i used following script but why this sign appears?

Code: Select all

 $mediaInfo = "%programfiles%\DAUM\PotPlayer\Module\MediaInfo.exe";
 $length = regexreplace(runret("$mediaInfo --Inform=Video;%Width%x%Height% ""<cc_item>"""), "\.\d*\r?\n");
 return $length;
To see the attached files, you need to log into the forum.

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

Because of your regex?

"\r?\n" is enough.
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: Add frame width & height to filename

Post by yusef88 »

thanks :beer:

Dustydog
Posts: 321
Joined: 13 Jun 2016 04:19

Re: Add frame width & height to filename

Post by Dustydog »

SammaySarkar wrote:For that matter, neither do I recommend property("#283") etc, for non-personal use.
These are OS-dependent.

The same property can have different indices in different OSes (heck, even different updates/software configuration of the same OS)
So, the most stable is to reach out to another program. If staying purely within XY, we're stuck with either using a number, which might change depending on patch or machine in use, but is far more useful to share to other language XY users, or a word that is unlikely to change, but is language dependent.

Wouldn't a word with a note to translate at the bottom of a script, if one wants to stay as simple as possible, be perhaps the most simple and stable? Such as (adds space frame height into brackets with a p on the end " [720p]":

Code: Select all

 rename b, "* [<prop *frame_height>p]";
Then just:
//Note: Localize frame_height to your language.

or

/*
English script, must localize (search/replace) these properties to your language:

frame_height
frame_width
*/

?

Realize it's...more selfish...but I'm looking for simple right now - my most useful scripts are perhaps 4-8 lines long each in multi-scripts at the moment. Reaching out to another program is still a bit of a stretch for me. So: Stable across my machines, fast and easy to write is the current priority, though I wouldn't mind adding some commenting if something might ever start to look generally useful.

And yes, of course the comment is in English - but it's pretty obvious, and there's always Google translate.

You're, of course, on a whole different level - and I appreciate your making the effort to be language neutral.
Last edited by Dustydog on 23 Feb 2017 00:58, edited 1 time in total.

highend
Posts: 14983
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Add frame width & height to filename

Post by highend »

These are language neutral:

Code: Select all

property("System.Video.FrameWidth")
property("System.Video.FrameHeight")
The problem is just: Not all file types are supported. So if support for a specific
codec requires e.g. the k-lite codec pack and somebody doesn't want to
install it, he needs mediainfo.exe anyway.

And regarding "translation by the user": That requires the user that he knows how
this property would be named in his language ;)
One of my scripts helped you out? Please donate via Paypal

Post Reply