Discussion:
How do you display relative cursor X:Y coordinates in an MP4 video on Windows?
Add Reply
Oliver
2024-11-16 17:22:57 UTC
Reply
Permalink
How do you find the dimensions to crop a phone MP4 to a box within the
original frame?

That is, how can I play an MP4 & get the cursor coordinates of two points?

I'm successfully uploading phone MP4 videos to Amazon reviews but this
latest 1,920px width by 1,080px height video needs to have a portion
cropped out because a reflection of the video taker shows in the video.

Amazon rejected the video for privacy reasons but I can't re-take that
video so what I need to do is crop out the person at the left of the frame.

Googling I found out how to do that, which is pretty simple with ffmpeg:
https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg

That page explains to crop to a 80by60 section, starting from position
200,100 where all you do is run these commands to view & effect the edit.

ffplay -i in.mp4 -vf "crop=80:60:200:100"
ffmpeg -i in.mp4 -vf "crop=80:60:200:100" -c:a copy out.mp4

OK. That works great. But I don't want those coordinates, but some other
set of coordinates which is the reason I'm asking this question.

How do I get those coordinates?

What method do you use to find the coordinates to crop to only a section of
your video frames?

Googling for the answer to that question of finding the pixels is a lot
harder because most of the answers are how to rescale the entire frame.

I need to determine the coordinates to crop to a portion of that frame.

This thread seems to ask it, but mostly for images, not videos.
https://forum.videohelp.com/threads/394631-how-to-know-the-position-of-pixels-in-a-picture

They seem to recommend vdub2 or avspmod for avisynth for video to get the
dimensions to subsequently feed into the ffplay/ffmpeg command.

But I'd like to first ask how you get the cursor position when you're
viewing an MP4 on Windows (so that I can put them into the ffmpeg command)?
Oliver
2024-11-17 01:48:45 UTC
Reply
Permalink
Post by Oliver
But I'd like to first ask how you get the cursor position when you're
viewing an MP4 on Windows (so that I can put them into the ffmpeg command)?
I don't know which video player you use. I use Potplayer and there you
just press <CTRL>-C to copy the current frame into the clip board
(in VLC player you can use the pull down menu to save the picture).
Then in IrfanView do a <CTRL>-V and select the region you want, the
coordinates are displayed in the title bar.
Thanks for trying to help because what I want to do is both simple &
complicated at the same time. It's something almost nobody does and
something everyone who uploads videos has to do at the same time.

These videos are for Amazon reviews where Amazon gives me free stuff to
review but I have to do the reviews and I'm trying to do a good job.

So I generally upload one video with every review (you can't upload more
than one video although you can upload plenty of photos in each review).

To answer your kind questions...
My image viewer is the same one almost everyone uses, which is Irfanview.
My media player is the same one almost everyone uses, which is MPC-BE.
Although I sometimes use VLC when I watch movies (usually with subtitles).
Just like everyone else does - so I'm not unusual in any way shape or form.

I solved the problem that I had asked in this thread before I saw your
helpful answer to copy a frame and then grab the coordinates in Irfanview &
then use ffmpeg to crop to those coordinates. That should work I'm sure.

In reality I was hoping for a purely graphical "draw a box" solution.
But I found a solution which is kind of sort of but not exactly that.

As stated in the opening post, this is how to crop in ffmpeg but you need
to already know what the draw-the-box pixels are going to be ahead of time.
https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg
ffplay -i in.mp4 -vf "crop=80:60:200:100"
ffmpeg -i in.mp4 -vf "crop=80:60:200:100" -c:a copy out.mp4

In googling for a graphical way to "draw the box", I found this site.
https://superuser.com/questions/510985/how-can-i-crop-a-video-to-a-part-of-the-view
We can use Handbrake to draw the box kind of sort of but not exactly.

I had to install Handbrake 1.8.2 which also required Net 8.0 on Windows.
https://handbrake.fr/docs/en/latest/get-handbrake/download-and-install.html
https://handbrake.fr/rotation.php?file=HandBrake-1.8.2-x86_64-Win_GUI.exe

Handbrake 1.8.2 required Windows dotNet 8.0 but it got it for me.
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-8.0.11-windows-x64-installer?cid=getdotnetcore

Then I followed the instructions for drawing the crop box from here.
https://www.tweaking4all.com/video/handbrake-trim-crop-rotate-video/

That is, with Handbrake 1.8.2 on Windows 10, I did the following.
a. I opened the 1920x1080 in.mp4 phone video with Handbrake 1.8.2
b. I clicked the Handbrake 1.8.2 "Dimensions" tab
c. I changed the Dimensions tab "Cropping" from "Automatic" to "Custom"
d. I pressed the Handbrake "Preview" button on the top bar
e. It failed with a popup asking me to check "Use External Player App"
f. I checked "Use External Player App" & pressed the popup "Close" button
g. For my video, I set the four crop dimensions manually to:
Top = 0
Bottom = 350
Left = 600
Right = 500
This part was sort of graphical but really more like trial & error.
h. Once I had the dimensions set, I checked it out with the preview slider
i. Then I got ready to save by clicking the "Summary" tab
Set Format = MP4
[x]Web Optimized
[x]Align A/V Start
i. I changed the "Save As" line to the desired path & name (out.mp4)
j. Finally I hit the "File > Start Encode" menu item & waited for results
k. When I watched the results I was happy with them.
l. But I needed to concatenate a second video which needed to be cropped.
m. Without closing Handbrake 1.8.2 I opened that second (shorter) video
n. Darn. The Dimensions reverted to the default so I changed them back.
o. I followed the saving procedure to save the second cropped mp4 file
p. Then I merged the two files. It wasn't seamless. But it was close.
echo file out.mp4 > mylist.txt
echo file out2.mp4 >> mylist.txt
ffmpeg -f concat -i mylist.txt -c copy output.mp4
q. Now I have to remove the metadata (if any)
ffmpeg -i output.mp4 -map 0 -map_metadata -1 -c copy output1.mp4
r. I deshaked the video (deshook?) although it wasn't too shaky
ffmpeg -i output1.mp4 -vf deshake output2.mp4
s. While that was running I manually created dummy captions
gVim output2.srt
1
00:00:10,000 --> 00:00:15,000
This is the first caption

2
00:00:25,000 --> 00:00:50,000
This is the second caption

3
00:01:00,000 --> 00:01:15,000
This is the third caption

4
00:01:20,000 --> 00:01:30,000
This is the fourth caption

t. I tested the dummy captions by playing output2.mp4 in MPC-BE
and then I adjusted the captions to the actual desired captions.

u. I then burned those captions into the video for a single upload.
ffmpeg -i output2.mp4 -vf subtitles=output2.srt output3.mp4

The result is a single video that has the offending person cropped out!

Thanks for your kind help which I very much appreciate since these kinds of
video edits are both common and unusual at the same time.

Basically, anyone uploading videos to the Amazon reviews who still wants to
maintain a bit of privacy (so there is no voice in the video) needs this.

The good news is I hope someone finds a much better way to crop the video
because what I wanted was just to draw a box and then say "crop to it!".
Zaidy036
2024-11-17 21:17:42 UTC
Reply
Permalink
Post by Oliver
Post by Oliver
But I'd like to first ask how you get the cursor position when you're
viewing an MP4 on Windows (so that I can put them into the ffmpeg command)?
I don't know which video player you use. I use Potplayer and there you
just press <CTRL>-C to copy the current frame into the clip board
(in VLC player you can use the pull down menu to save the picture).
Then in IrfanView do a <CTRL>-V and select the region you want, the
coordinates are displayed in the title bar.
Thanks for trying to help because what I want to do is both simple &
complicated at the same time. It's something almost nobody does and
something everyone who uploads videos has to do at the same time.
These videos are for Amazon reviews where Amazon gives me free stuff to
review but I have to do the reviews and I'm trying to do a good job.
So I generally upload one video with every review (you can't upload more
than one video although you can upload plenty of photos in each review).
To answer your kind questions... My image viewer is the same one almost
everyone uses, which is Irfanview.
My media player is the same one almost everyone uses, which is MPC-BE.
Although I sometimes use VLC when I watch movies (usually with subtitles).
Just like everyone else does - so I'm not unusual in any way shape or form.
I solved the problem that I had asked in this thread before I saw your
helpful answer to copy a frame and then grab the coordinates in Irfanview &
then use ffmpeg to crop to those coordinates. That should work I'm sure.
In reality I was hoping for a purely graphical "draw a box" solution.
But I found a solution which is kind of sort of but not exactly that.
As stated in the opening post, this is how to crop in ffmpeg but you need
to already know what the draw-the-box pixels are going to be ahead of time.
https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-
with-ffmpeg
ffplay -i in.mp4 -vf "crop=80:60:200:100"
ffmpeg -i in.mp4 -vf "crop=80:60:200:100" -c:a copy out.mp4
In googling for a graphical way to "draw the box", I found this site.
https://superuser.com/questions/510985/how-can-i-crop-a-video-to-a-part-
of-the-view
We can use Handbrake to draw the box kind of sort of but not exactly.
I had to install Handbrake 1.8.2 which also required Net 8.0 on Windows.
https://handbrake.fr/docs/en/latest/get-handbrake/download-and-install.html
https://handbrake.fr/rotation.php?file=HandBrake-1.8.2-x86_64-Win_GUI.exe
Handbrake 1.8.2 required Windows dotNet 8.0 but it got it for me.
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-
desktop-8.0.11-windows-x64-installer?cid=getdotnetcore
Then I followed the instructions for drawing the crop box from here.
https://www.tweaking4all.com/video/handbrake-trim-crop-rotate-video/
That is, with Handbrake 1.8.2 on Windows 10, I did the following.
a. I opened the 1920x1080 in.mp4 phone video with Handbrake 1.8.2
b. I clicked the Handbrake 1.8.2 "Dimensions" tab
c. I changed the Dimensions tab "Cropping" from "Automatic" to "Custom"
d. I pressed the Handbrake "Preview" button on the top bar e. It failed
with a popup asking me to check "Use External Player App"
f. I checked "Use External Player App" & pressed the popup "Close" button
  Top = 0
  Bottom = 350
  Left = 600
  Right = 500
  This part was sort of graphical but really more like trial & error.
h. Once I had the dimensions set, I checked it out with the preview slider
i. Then I got ready to save by clicking the "Summary" tab
  Set Format = MP4
  [x]Web Optimized
  [x]Align A/V Start
i. I changed the "Save As" line to the desired path & name (out.mp4)
j. Finally I hit the "File > Start Encode" menu item & waited for results
k. When I watched the results I was happy with them.
l. But I needed to concatenate a second video which needed to be cropped.
m. Without closing Handbrake 1.8.2 I opened that second (shorter) video
n. Darn. The Dimensions reverted to the default so I changed them back.
o. I followed the saving procedure to save the second cropped mp4 file
p. Then I merged the two files. It wasn't seamless. But it was close.
  echo file out.mp4 >  mylist.txt   echo file out2.mp4 >> mylist.txt
  ffmpeg -f concat -i mylist.txt -c copy output.mp4
q. Now I have to remove the metadata (if any)
  ffmpeg -i output.mp4 -map 0 -map_metadata -1 -c copy output1.mp4
r. I deshaked the video (deshook?) although it wasn't too shaky
  ffmpeg -i output1.mp4 -vf deshake output2.mp4
s. While that was running I manually created dummy captions
  gVim output2.srt
  1
  00:00:10,000 --> 00:00:15,000
  This is the first caption
  2
  00:00:25,000 --> 00:00:50,000
  This is the second caption
  3
  00:01:00,000 --> 00:01:15,000
  This is the third caption
  4
  00:01:20,000 --> 00:01:30,000
  This is the fourth caption
t. I tested the dummy captions by playing output2.mp4 in MPC-BE
  and then I adjusted the captions to the actual desired captions.
u. I then burned those captions into the video for a single upload.
  ffmpeg -i output2.mp4 -vf subtitles=output2.srt output3.mp4
The result is a single video that has the offending person cropped out!
Thanks for your kind help which I very much appreciate since these kinds of
video edits are both common and unusual at the same time.
Basically, anyone uploading videos to the Amazon reviews who still wants to
maintain a bit of privacy (so there is no voice in the video) needs this.
The good news is I hope someone finds a much better way to crop the video
because what I wanted was just to draw a box and then say "crop to it!".
If it is a standard button to press look at free AutoIt
https://www.autoitscript.com/site/autoit/

Another, not free, program is easier to program PTFBpro
https://www.ptfbpro.com/download.shtml
Oliver
2024-11-18 02:44:25 UTC
Reply
Permalink
Post by Oliver
I had to install Handbrake 1.8.2 which also required Net 8.0 on Windows.
I don't understand why it is easier to install new software instead
of using the already installed IrfanView.
DO NOT CLOSELY READ THIS POST - IT IS FOR REFERENCE - I WILL REWRITE IT!
(JUST NOTE THAT GETTING THE FRAME GRAB IN THE CLIPBOARD IS AN ISSUE.)
ONCE THE FRAMEGRAB IS IN THE CLIPBOARD, THEN YOUR BATCH FILE WORKS GREAT!

Thanks for bringing that up as the goal of every Usenet thread is also to
learn for the thousands of people who read this thread both now & forever.

Just to be super clear, I never said either way was easier, and in fact I
said I wanted a purely graphical "draw-the-box" solution, and as yet, we
haven't found that area-draw method (but it probably exists... somewhere as
it's a common need to want to draw an area box and then to want to crop the
entire video to that drawn area box.

In fact I had done the Handbrake method before I saw your Irfanview method.
The Handbrake method was "said" to be purely graphical - but it's not.
It's partly graphical. Much like the Irfanview method is (only different).

What is really needed is a video player that shows the cursor X:Y position.
I have to believe that already exists on Windows 10.

Just because the cursor position is so obvious a need. It must exist.
But where?

I think you're probably correct that this mystery program could be
Irfanview since I tried your method and I like the way you think.
1. Open the video in your player and copy one video frame
to the clipboard (for the Potplayer this is just a <CTRL>-C).
You can close the player then. You can also start the player
in the batch if you want.
Saving a video frame is easy so that's not going to be a problem.

The player most people use on Windows (AFAIK) is either MPC-BE or VLC.
When I open output.mp5 in MPC the "MPC: File > Properties" tells me:
Width: 1,920 pixels
Height: 1,080 pixels
But unfortunately I see no option to display the cursor X:Y location.
Likewise with the venerable VLC (as far as I can tell anyway).

In MPC-BE (which most people use) there doesn't seem to be a way to save
the frame to a file. A Windows print-screen would be all wrong.

Luckily 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.
(I use the ini file in IrfanView, if you use the registry you have
to modify the batch. You also have to use the correct path to Irfanview).
I also use the ini file in Irfanview because I install into a custom
location and putting stuff in the registry is just asking for trouble.

I like the way you think.
@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
I like the way you think so I copied that and changed the path to Irfanview
64 ini file (there was no 32-bit ini file in the Irfanview directory).

Unfortunately a right-click-copy on that VLC frame grab didn't put it into
the clipboard (C:\Users\you\Pictures\vlcsnap-2024-11-17-18h08m36s459.png).

Neither did opening that PNG file in Irfanview already.
How can I get the single-frame PNG from VLC into the Windows clipboard?

Anyway, I can just open the VLC frame grab in Irfanview, can't I?
After IrfanView is started and the video frame is displayed,
use the left mouse button to select the the crop region. You can
change the size with the left mouse button or move the region with
the right mouse button. Then press <SHIFT>-C and then "Save values and exit".
Then close IrfanView. The batch then executes the ffmpeg command.
I think we're getting close even though I can't get the VLC framegrab into
the clipboard no matter how hard I tried to do it with all sorts of ways.

But I already have the VLC frame grab PNG in Irfanview so I'll start there.

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)

I also accidentally noticed if I hit the F12 keyboard key while displaying
a VLC frame grab in Irfanview, the "Paint Dialog" that pops up has an icon
for "Measure Distance & Angles" which gives me the number of pixels any
line that I draw with my leftmouse on the image is.

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.

But there is a sneaky way to get them.
a. Open the VLC framegrab PNG in Irfanview
b. Press F12 to bring up the "Paint Dialog" menu
c. Click the "Rectangle" icon which will draw a rectangle
d. Draw the rectangle of the desired crop area on the image
e. Click on the "Measure Tool" icon which will measure line lengths
f. Measure from the left border to the top-left corner of the drawn box
g. Measure the bottom border to the bottom-right corner of the drawn box
h. Now you have the necessary X:Y locations in pixels from the borders

I just realized Irfanview can do a selection box which displays coordinates
where you can just draw a selection box inside of Irfanview to get the
coordinates displayed on the top of the Irfanview window as something like
(Zoom: 1796x1010) (Selection: 137,9;868x1002;0.866)

While I was documenting those steps for everyone to try out for themselves,
I realized Irfanview does have a save-to-clipboard command I can use!

a. Open the VLC framegrab PNG in Irfanview
b. Irfanview:Options > Capture Screenshot
c. Select "Foreground Window" & "Copy captured image to clipboard"

Unfortunately that doesn't directly put the image (without the borders)
into the clipboard as you have to initiate that step manually somehow.

Bummer. That command is too tricky to use as it doesn't directly save the
image to the clipboard without also saving the boarder areas we don't want.

I think this might work but I have to test it further to be sure.
a. Start Irfanview all by itself with no image
b. Irfanview:Options > Capture/Screenshot
c. In the "Capture Setup", Select "Custom rectangle/region capture"
d. Also select "After the capture" "Copy captured image to clipboard"
e. Set the "Capture method:" "Hot key:" to "Ctrl + Left" (or whatever)
f. Also select "Also show image in main window" (but that's optional)
g. Then press the "Capture Setup" "Start" button
h. It's a pain in the butt but that "Start" button iconifies Irfanview
i. So click the Irfanview icon in the taskbar to bring Irfanview back
j. Unfortunately Irfanview will be all black as it has nothing to show
k. So open the VLC framegrab file with "Irfanview:File > Open"
l. With the cursor in Irfanview, press that "Hot key" combination
m. This will bring up crosshairs over the pixel position!

But maybe there's an easier way as that menu is atrociously confusing.
All I'm trying to do is get the VLC screengrab into the clipboard
so that I can then run your clipcrop.bat batch script below.

Aha! I found it!

This is clipcrop.bat as it had to be modified to fit my system setup.

@echo off
REM clipcrop.bat
start /w "" C:\path\iview\i_view64.exe /clippaste

for %%k in (CustSelX CustSelY CustSelW CustSelH) do (
for /f "delims=." %%i in ('find "%%k=" ^C:\app\editor\pic\iview\i_view64.ini') do set %%i
)

echo ffmpeg -i in.mp4 -vf "crop=%CustSelX%:%CustSelY%:%CustSelW%:%CustSelH%" -c:a copy out.mp4

a. Make sure no instance of Irfanview is already running
b. Start Irfanview all by itself with no image
c. Irfanview:Options > Properties/Settings > Start/Exit Options
d. Make sure "Only 1 instance of Irfanview is active" is NOT checked!
e. Irfanview:Options > Capture/Screenshot
f. In the "Capture Setup", Select "Foreground window - Client area"
g. Also select "After the capture" "Copy captured image to clipboard"
h. Set the "Capture method:" "Hot key:" to "Ctrl + Left" (or whatever)
i. Also select "Also show image in main window" (but that's optional)
j. Then press the "Capture Setup" "Start" button
k. That will iconify the Irfanview window to the clipboard
l. Open the VLC framegrab PNG in another instance of Irfanview
m. Make sure the focus of the mouse is on that instance of Irfanview
n. Press the "Hot key" combination to save it to the Windows clipboard
o. In a command window, make sure ffmpeg is in your path
p. Make sure the path to Irfanview is correct in clipcrop.bat file
q. Then in that command window, run that clipcrop.bat file listed above
r. That will start a third instance of Irfanview
s. That third Irfanview instance will display only the VLC framegrab image
t. Use the left mouse button to select the desired crop region
(You can change the size with the left mouse button)
(After drawing you can Cmove the region with the right mouse button)
u. Then press <SHIFT>-C which brings up "Create custom selection"
(note that this shows your X:Y locations of your crop box for you)
v. In "Selection size/position", press the "Save values and exit" button
w. Then close IrfanView as the batch then executes the ffmpeg command
x. You should see output similar to the one I pasted below from mine
Environment variable ---------- C:\PATH\IVIEW\I_VIEW64 not defined
Environment variable ---------- C:\PATH\IVIEW\I_VIEW64 not defined
Environment variable ---------- C:\PATH\IVIEW\I_VIEW64 not defined
Environment variable ---------- C:\PATH\IVIEW\I_VIEW64 not defined
ffmpeg -i in.mp4 -vf "crop=47:183:272:325" -c:a copy out.mp4

I like it!

It needs to be streamlined a bit perhaps, but it works beautifully!
Thanks for solving the problem.

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.
Oliver
2024-11-18 04:04:35 UTC
Reply
Permalink
Apparently Irfanview can copy a video frame directly to the clipboard.
https://irfanview-forum.de/forum/program/support/92896-help-with-capturing-a-single-video-frame-using-irfanview

Here is a writeup for review by Herbert to ask if this is the simplest way
to accomplish the task of graphically choosing the crop area for ffmpeg.

This is clipcrop.bat as it had to be (minor) modified to fit my system.

@echo off
REM clipcrop.bat
start /w "" C:\path\iview\i_view64.exe /clippaste

for %%k in (CustSelX CustSelY CustSelW CustSelH) do (
for /f "delims=." %%i in ('find "%%k=" ^C:\path\iview\i_view64.ini') do set %%i
)

echo ffmpeg -i in.mp4 -vf "crop=%CustSelX%:%CustSelY%:%CustSelW%:%CustSelH%" -c:a copy out.mp4

Get a video frame into the Windows clipboard any way you can.
For example
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"

Now that the current video frame is copied by Irfanview to the
clipboard, you can run clipcrop.bat that Herbert kindly prior posted.
Oliver
2024-11-18 20:48:35 UTC
Reply
Permalink
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 Oliver
In 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 Oliver
there 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 Oliver
Luckily 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 Oliver
This 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 Oliver
Environment 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.

Loading...