Page 1 of 2

Add frame width & height to filename

Posted: 19 Jan 2015 22:45
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

Re: Add frame width & height to filename

Posted: 19 Jan 2015 22:57
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)...

Re: Add frame width & height to filename

Posted: 20 Jan 2015 03:12
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.

Re: Add frame width & height to filename

Posted: 20 Jan 2015 05:02
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?

Re: Add frame width & height to filename

Posted: 20 Jan 2015 08:01
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

Re: Add frame width & height to filename

Posted: 20 Jan 2015 17:20
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.

Re: Add frame width & height to filename

Posted: 20 Jan 2015 17:31
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.

Re: Add frame width & height to filename

Posted: 20 Jan 2015 17:52
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)

Re: Add frame width & height to filename

Posted: 20 Jan 2015 18:23
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) :)

Re: Add frame width & height to filename

Posted: 20 Jan 2015 18:34
by TheQwerty

Re: Add frame width & height to filename

Posted: 04 Nov 2015 04:35
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;

Re: Add frame width & height to filename

Posted: 04 Nov 2015 07:49
by highend
Because of your regex?

"\r?\n" is enough.

Re: Add frame width & height to filename

Posted: 04 Nov 2015 08:03
by yusef88
thanks :beer:

Re: Add frame width & height to filename

Posted: 23 Feb 2017 00:25
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.

Re: Add frame width & height to filename

Posted: 23 Feb 2017 00:52
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 ;)