Thanks to Herbert Kleebauer's coding skills, this works great
to crop any MP4 video to any desired selection box area with ffmpeg.
@echo off
REM clipcrop.bat (framecrop.bat?)
REM
REM WIP Improvements?
REM Learn how save a video frame to the clipboard with Irfanview alone!
REM
REM Setup instructions:
REM If the video frame is already in the clipboard, then use...
REM start /w "" C:\path-to\Irfanview\i_view32.exe /clippaste
REM
REM If you ran "VLC:Video > Take snapshot" on the video, then use...
REM start /w "" C:\path-to\Irfanview\i_view32.exe C:\path-to\vlcsnap.png
REM
REM To manually load the video frame image into IrfanView, use...
REM start /w "" C:\path-to\Irfanview\i_view32.exe
REM
REM Operating instructions:
REM 1st Open a command window
REM 2nd execute this batch file (which pops up Irfanview)
REM 3rd (optionally load the vlcsnap framegrab if not already done)
REM 4th In Irfanview, leftmouse draw the desired selection box
REM 5th In Irfanview, press "Shift+c"
REM 6th Click the Irfanview [Save values and exit] button
REM 7th Kill Irfanview (this spits out the desired ffmpeg crop command)
start /w "" C:\path-to\Irfanview\i_view32.exe
for %%k in (CustSelX CustSelY CustSelW CustSelH) do (
for /f "delims=." %%i in ('find "%%k=" ^<C:\path-to\iview\i_view32.ini') do set %%i
)
echo ffmpeg -i in.mp4 -vf "crop=%CustSelX%:%CustSelY%:%CustSelW%:%CustSelH%" -c:a copy out.mp4
You are perfect in doing easy things in a complicated way.
I think I know why you said that I make things complicated, but what's
really happening is I'm testing it because I want it to work for me.
In my setup, I don't use Potplayer. I use Irfanview & VLC & MPC-BE.
So I want it to work with them (preferably with only Irfanview).
But after explaining that, I have to say that your method is great.
It works with Irfanview on a vlcsnap.png file, which works for me.
Therefore, I want to clearly thank you for your proposed method.
It works great!
The only thing I'm trying to do different is I don't use potplayer.
But I want to be clear I like your proposed method. It works wonderfully.
I love that it *creates* the ffmpeg command for you - that's fantastic!
Especially because both Irfanview & ffmpeg use confusing pixels.
The only problem is getting the frame into the Windows clipboard.
Which means I don't know Windows as well as I wish I knew Windows.
Because the only problem is getting a video frame into the clipboard.
After that, it works beautifully. Fantastically so. I love it.
So rest assured I'm faithfully trying to do it your way.
The only difference is I don't use PotPlayer.
https://apps.microsoft.com/detail/xp8bsbgqw2dks0?hl=en-US&gl=US
I'm trying to do your method but with one of these three tools:
1. Irfanview alone (that would be nice!)
2. MPC-BE + Irfanview (that's OK)
3. VLC + Irfanview (that's OK also)
To use those tools, which almost everyone has already installed,
is the way I'm trying to do your method - which works well.
The only complexity is getting the video frame into the clipboard.
It's really an Irfanview or Windows expert question, is it not?
Post by OliverIn MPC-BE (which most people use)
I never heard of MPC-BE. I use the portable version of PotPlayer
(formerly KMplayer) since many decades and most probably will
never use anything else (it is made to make complicated things
easy and not to make easy things complicated).
Oh. OK. I'll explain then, as I've used MPC for a billion years.
MPC-BE used to be called "media player classic" (that's the MPC part).
It has a long history where I don't remember what the BE stands for.
(I looked it up. It doesn't mean anything other than "Black Edition".
https://sourceforge.net/projects/mpcbe/
https://www.videohelp.com/software/MPC-BE
https://www.majorgeeks.com/files/details/media_player_classic_black_edition_(mpc_be)_64_bit.html
https://www.techspot.com/downloads/5076-media-player-classic-be.html
MPC-BE is also found as a Microsoft app (but I don't use the MS Store).
https://apps.microsoft.com/detail/9pd88qb3bgkn?hl=en-US&gl=US
It's very well maintained and most people on Windows use it
because it's a small lightweight powerhouse, like Irfanview is.
https://sourceforge.net/projects/mpcbe/files/MPC-BE/MPC-BE%20x64/
I also have a portable version of VLC, because this is the
only player I know, which can read the video from stdin.
This allows to store private videos encrypted on the disk
and play them without first generating a decrypted version
on the disk. https://onlib.de/pub/pfv/
That's interesting as I never thought about encrypted videos.
I don't even know what an encrypted video is, although I'm familiar with
pgp encryption and with truecrypt container encryptions, but I never
encrypted a video in and of itself. I download torrents all the time, but I
don't encrypt them. I use VLC to play cinema movies with subtitles.
Since I always figure if you posted a link, I should read it, I looked at
that link you provided & it's pretty neat stuff. Thank you for posting it.
https://onlib.de/pub/pfv/readme.txt
This utility can be use to display encrypted videos in
combination with the VLC media player:
usage: pfv.exe number : password1 : password2 : inputfile >outputfile
That's neat. I like it. I don't have a need to encrypt a video.
But I like that this capability exists. I'll save it for future use.
BTW, I can tell you probably wrote that script. Kudos to you for that.
It's *very* helpful when you write scripts as they are all first rate!
I like the video of the white & black cat on the tile roof as a test too.
You might want to remove the EXIF data though... like Video_DSCF0365.MOV
ffmpeg -i demo.mp4 -map 0 -map_metadata -1 -c copy demo_noexif.mp4
Post by Oliverthere doesn't seem to be a way to save
the frame to a file. A Windows print-screen would be all wrong.
If your screen is large enough to display the video in original
size and you don't care about a few pixels off, you can take
a screenshot with the snipping tool (<WIN>-<SHIFT>-S) to store
the picture in the clip board.
That's a good idea. There's actually *multiple* ways in Irfanview to save a
screenshot to the clipboard - but none of them seem to actually work. Sigh.
There is, of course, a way in VLC to save a frame to a file, which works.
VLC:Video > Take snapshot" which puts a single-frame grab into
C:\Users\you\Pictures\vlcsnap-2024-11-17-18h08m36s459.png
If only I could get the Irfanview save-to-clipboard commands to work.
a. Copy your video to be cropped to "in.mp4" to the current directory
b. Rightclick on in.mp4, which will bring up a Windows context menu
c. Select "Open with > Irfanview" (which will be 32-bit or 64-bit)
d. That should start playing the in.mp4 video inside of Irfanview
e. Freeze Irfanview at a desired frame by leftmouse clicking once
f. Rightclick in the frozen Irfanview window (which pops up a menu)
g. From the menu, select "Copy current frame to clipboard - Ctrl+C"
But for whatever reason, I can't get that to actually put anything
into the Windows clipboard. I don't understand why not. Do you?
I also tried this but it too won't put anything into the clipboard.
a. Open the VLC framegrab PNG in Irfanview
b. Irfanview:Options > Capture Screenshot
c. Select "Foreground Window" & "Copy captured image to clipboard"
Maybe I'll open a separate thread to see if anyone can get
Irfanview to put the image only (no borders!) into the clipboard.
Note that in Irfanview, the F12 key modifies the GUI to that of
a MS Paint dialog which has an option to measure distances between
two points on a drawn line.
Also note when you're done drawing a crop rectangle in Irfanview,
on top of Irfanview is displayed the coordinates of that crop.
XY:(953,1080) (850x1080 Pixels, 0.787)
Also note Irfanview by default doesn't display the cursor x:y
position but you can get that information by setting this option:
Irfanview:Options > Properties/Settings > Viewing
[x]Show mouse coordinates in the Statusbar
Post by OliverLuckily in VLC (which most people also use) there is an option
VLC:Video > Take snapshot" which puts a single-frame grab into
C:\Users\you\Pictures\vlcsnap-2024-11-17-18h08m36s459.png
I'm not sure how to get that video frame into the clipboard though.
No need to get the picture into the clipboard, just replace
start /w "" D:\Programme\IrfanView\i_view32.exe /clippaste
start /w "" D:\Programme\IrfanView\i_view32.exe d:/your-path/name.jpg
That's it! That will work. The good news is it works. I just tried it.
Great!
The bad news is it requires VLC to work - but most people have VLC already.
The other bad news is the vlcsnap file name constantly changes - but that
can be worked around by grabbing the latest vlcsnap framegrab & moving it
to a consistent name in the CWD such as "vlcsnap.png" (or vlcsnap.jpg).
I tested the vlcsnap PNG framegrab which worked perfectly the first time!
Thanks. I posted my batch in as an EDIT above as that's what matters.
Post by Oliver@echo off
start /w "" D:\Programme\IrfanView\i_view32.exe /clippaste
for %%k in (CustSelX CustSelY CustSelW CustSelH) do (
for /f "delims=." %%i in ('find "%%k=" ^<D:\Programme\IrfanView\i_view32.ini') do set %%i
)
echo ffmpeg -i in.mp4 -vf "crop=%CustSelX%:%CustSelY%:%CustSelW%:%CustSelH%" -c:a copy out.mp4
When I open the VLC frame grab in Irfanview, I can leftmouse crop the
area I want to crop the entire video to as you suggest I do.
When I'm done drawing the crop rectangle of the VLC frame grab in
Irfanview, on top of Irfanview is displayed the coordinates of that crop.
XY:(953,1080) (850x1080 Pixels, 0.787)
All I need now is the X:Y coordinate of the starting point of that line.
Unfortunately, Irfanview doesn't give me the starting X:Y coordinates.
Just above you wrote, IrfanView displays the starting coordinates
XY:(953,1080). But you don't need to transfer them manually to
the ffmpeg command, the batch extracts that in formation from
the ini file.
Yes. I *love* that the batch file transfers the necessary pixel coordinates!
That's the sheer *beauty* of your batch-file method. It's fantastic.
I love it.
Note that I googled like crazy to figure out how to get Irfanview
to put the framegrab into the clipboard when I found accidentally that
Irfanview *does* give us the constantly changing mouse coordinates.
So I was wrong about that (like so many other things I don't know).
I just didn't know it's not set by default to show pixel coordinates.
Irfanview:Options > Properties/Settings > Viewing
[x]Show mouse coordinates in the Statusbar
Now the dynamic cursor position is shown in the bottom status bar.
Post by OliverThis is clipcrop.bat as it had to be modified to fit my system setup.
for /f "delims=." %%i in ('find "%%k=" ^C:\app\editor\pic\iview\i_view64.ini') do set %%i
for /f "delims=." %%i in ('find "%%k=" ^<C:\app\editor\pic\iview\i_view64.ini') do set %%i
Aurgh. I didn't even notice that mistake. My bad. I apologize.
I had thought it was a typo from linewrapping nntp line lengths.
My mistake. I've fixed it. Thanks for catching my faux pas.
Post by OliverEnvironment variable ---------- C:\PATH\IVIEW\I_VIEW64 not defined
I'll write up a simpler description after I post this so that we don't lose
the issues that came up when running the process using VLC instead of
Potplayer as the main problem I had was getting the frame into the
clipboard. If there is an easier way to do that, I'm all ears.
Don't make easy things complicated.
I don't disagree that we want it to be simple for everyone to use daily.
I just wish I knew how to get a video frame from Irfanview into the Windows
clipboard instead of having to go to VLC to output a vlcsnap.png file.
1. Play the video and extract a single frame. In PotPlayer
just press <CTRL>-C to store it in the clipboard, in VLC save
it to a file. Then the player isn't needed any more.
2. Start the batch, but be sure you have the correct line
start /w "" C:\path\iview\i_view64.exe /clippaste
if the picture is in the clipboard
start /w "" C:\path\iview\i_view64.exe C:\path\name.jpg
if you saved the video frame to a picture file
start /w "" C:\path\iview\i_view64.exe
if you want to load the picture file manually in IrfanView
Those are GREAT instructions. I've added them to the comments.
You see them in the abstract at the top of this message body.
3. After IrfanView is started and the video frame is displayed,
use the left mouse button to select the the crop region.
Then press <SHIFT>-C and then "Save values and exit".
Then close IrfanView. The batch then extracts the data
from the ini file and executes the ffmpeg command.
Only these 3 steps are required, nothing more.
It's actually a half-dozen steps (or so) but still - it's easy now!
1st Open a command window
2nd execute this batch file (which pops up Irfanview)
3rd (load the vlcsnap framegrab if not already done)
4th In Irfanview, leftmouse draw the desired selection box
5th In Irfanview, press "Shift+c"
6th Click the Irfanview [Save values and exit] button
7th Kill Irfanview (this spits out the desired ffmpeg crop command)
It's beautiful. It works. It's efficient. Thank you.
Everyone will benefit who needs to crop a video using ffmpeg!
You're wonderful.