VideoHelp Forum
+ Reply to Thread
Results 1 to 14 of 14
Thread
  1. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    I want to crop video file with FFMPEG. There option to preview video with crop-future results using FFPLAY. It works great and I can see what my crop values will give me as output. I want to set the new scale (display aspect ratio) too but can’t find the way to see that in preview. Tried everything, even couldn’t find in FFPLAY documentation a word about scaling (SAR, DAR) preview. Seems that it is hidden in some filtering options but… I am really stacked. Or it is impossible?
    Next code used (windows 10, BAT (CMD)):
    Code:
    Set cropHeight=64
    ffplay -i "filename.ext" -vf "crop=in_w:in_h-%cropHeight%"
    Thanks in advance.
    Quote Quote  
  2. try this:

    Code:
    set "h=1920"
    set "w=1080"
    set "cropHeight=64"
    
    ffplay -i "filename.ext" -x %w% -y %h% -vf "crop=in_w:in_h-%cropHeight%"
    Quote Quote  
  3. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Originally Posted by _Al_ View Post
    try this:

    Code:
    set "h=1920"
    set "w=1080"
    set "cropHeight=64"
    
    ffplay -i "filename.ext" -x %w% -y %h% -vf "crop=in_w:in_h-%cropHeight%"
    Thanks _Al_ but it's not that I meant. That's also crop. If I enter
    Code:
    set "h=900"
    set "w=1060"
    set "cropHeight=64"
    I will have huge black surcfeces on the bottom and the top even I cropped them from the original... I need SCALE or RESIZE but not CROP for scaling. My video should display my cropped results but in the scale of 16:9, 5:4, 3:2... on my choice...scaling and cropping are different issues... my video must be elastic, flexible, sensitive on scaling values...
    Quote Quote  
  4. you can use scale, i just test it:
    set "h=1920"
    set "w=1080"
    set "cropHeight=64"
    Code:
    ffplay -i "filename.ext"  -vf "crop=in_w:in_h-%cropHeight%,scale=%h%:%w%"
    that h x w , that is setting DAR basically
    Quote Quote  
  5. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Originally Posted by _Al_ View Post
    you can use scale, i just test it:
    set "h=1920"
    set "w=1080"
    set "cropHeight=64"
    Code:
    ffplay -i "filename.ext"  -vf "crop=in_w:in_h-%cropHeight%,scale=%h%:%w%"
    that h x w , that is setting DAR basically
    Thanks _Al_
    Not ok again... tomorrow I'll post video file somewhere and try to solve crop (again!) first.
    I didn;t read this page carefully:
    https://www.bogotobogo.com/FFMpeg/ffmpeg_cropping_video_image.php
    Quote Quote  
  6. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    If you are just looking for a general representation of how it looks you can do all in one shot with pipe ffmpeg to ffplay.

    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\CGOP.mp4" -t 52.753227 -vf crop=440:230:40:40 -f flv - |  ffplay - -vf scale=640:-2
    FLV not quite as good an output as your final ffmpeg but then neither is ffplay. -F FLV will pass the pipe where others such as MP4 will not.
    Quote Quote  
  7. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Bud, my code is more complex… sure that I am cropping video later but preview is the first step. If preview OK then Do Crop. Else: go back on entering crop values.

    This will not work on our way (_Al_, me etc...). Only one dimension of scaling is processed (larger one seems to me) and the second is automatically set to keep source video scaling (source DAR). Maybe that is exactly they wanted to achieve...

    I would like to set my own scaling (resizing!) for preview to get something as on the attached image “Sam Distortion.png”

    Whatever you enter as scaling width or scaling height, DAR 16:9 will be displayed in FFPLAY. Crop is another story: crop simple working perfect (there are lot of play with negative values, distance from the left or the bottom… etc.)!!!

    Video file is here (800 x 654 - if youtube did resize it...)
    https://www.youtube.com/watch?v=mNTWkStnsGA

    Batch code (just edit my paths):
    Code:
    @echo off
    echo !
    
    set dl=C:\Users\DL
    set ffmp=%dl%\pgs
    set wpath=%dl%\files
    set result=%dl%\result
    
    REM Bud sample
    REM %ffmp%\ffmpeg -i "C:\Users\DL\files\input.mp4" -t 52.753227 -vf crop=440:230:40:40 -f flv - | %ffmp%\ffplay - -vf scale=640:-
    REM pause
    REM exit
    
    :procStart
    FOR %%g IN (%wpath%\*) DO (
        for /F "delims=" %%e in ('%ffmp%\ffprobe -v error -select_streams v:0 -show_entries stream^="width,height" -of csv^=s^=x:p^=0 "%%g" 2^>^&1') do set "inputWH=%%e"
        )
    
    echo Input file scale (v-dimension, v-resolution, DAR?..) is %inputWH%
    
    set cw=800
    set ch=450
    set cx=0
    set cy=102
    set sw=480
    set sh=270
    
    set /p cw=Enter crop width value (default: %cw%): 
    set /p cw=Enter crop height value (default: %ch%): 
    set /p cw=Enter left shift value (default: %cx%): 
    set /p cw=Enter bottom shift value (default: %cy%): 
    set /p cw=Enter scale width value (default: %sw%): 
    set /p cw=Enter scale height value (default: %sh%): 
    
    echo cw is %cw%
    echo ch is %ch%
    echo cx is %cx%
    echo cy is %cy%
    echo sw is %sw%
    echo sh is %sh%
    
    pause
    
    FOR %%g IN (%wpath%\*) DO (
        %ffmp%\ffplay -i "%%g" -vf "crop=%cw%:%ch%:%cx%:%cy%,scale=%sw%:%sh%" -loop 4 -window_title "%%~nxg | CW %cw% CH %ch% CX %cx% CY %cy%" -autoexit
        )
    
    echo(
    echo If you are satisfied, choose OK. Chose Repeat to enter the new crop value. Or Exit to do nothing.
    
    CHOICE /C "123" /M "Choose your acction [(1)OK, (2)Repeat, (3)Exit]"
    echo(
    
    IF ErrorLevel 3 GoTo :Stop
    IF ErrorLevel 2 GoTo :procStart
    IF ErrorLevel 1 GoTo :doCrop
    echo(
    
    :Stop
    exit
    
    :doCrop
    echo Now crop and save your output file... but this is another story... exit
    timeout /t 32
    exit
    Thanks _Al_. We never give up!

    Huh... how to show attachments as link???

    Bud, your code doesn’t work for me… dunno why… I don’t understand why you need FLV and –t? Screenshot attached.
    Image Attached Files
    Last edited by Drag; 7th Oct 2018 at 12:43. Reason: Small tipo 2
    Quote Quote  
  8. You can affect ffplay preview by using -vf setsar or setdar

    https://ffmpeg.org/ffmpeg-filters.html#setdar_002c-setsar
    Quote Quote  
  9. I did not tried all of it, just core of the script for playback and it crops, no black bars
    Code:
    @echo off
    :procStart
    
    set cw=800
    set ch=450
    set cx=0
    set cy=102
    set sw=480
    set sh=270
    
    set /p cw=Enter crop width value (default: %cw%): 
    set /p cw=Enter crop height value (default: %ch%): 
    set /p cw=Enter left shift value (default: %cx%): 
    set /p cw=Enter bottom shift value (default: %cy%): 
    set /p cw=Enter scale width value (default: %sw%): 
    set /p cw=Enter scale height value (default: %sh%): 
    
    echo cw is %cw%
    echo ch is %ch%
    echo cx is %cx%
    echo cy is %cy%
    echo sw is %sw%
    echo sh is %sh%
    
    pause
    
    ffplay.exe -i "test file.mp4" -vf "crop=%cw%:%ch%:%cx%:%cy%,scale=%sw%:%sh%"  -window_title "test" -autoexit
       
    exit
    Image Attached Thumbnails Click image for larger version

Name:	Capture.JPG
Views:	300
Size:	224.0 KB
ID:	46841  

    Last edited by _Al_; 7th Oct 2018 at 11:32.
    Quote Quote  
  10. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Originally Posted by poisondeathray View Post
    You can affect ffplay preview by using -vf setsar or setdar
    When I am resizing, using that all the time. I've tried it here too but didn't work.

    Now... it works. But results, in combination with filter scale, are unpredictable... need to play for a while...

    Thanks poisondeathray.
    Quote Quote  
  11. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Well… that DAR & SAR are very complicated… the same problem guy had (exactly!) 5 years ago! Darn month October https://lists.ffmpeg.org/pipermail/ffmpeg-user/2013-October/018327.html

    Today, we did better than they in 2013.

    So, in this case, all of above working on the next way.:
    video is 800 x 654 with top black bar of 102 and bottom black bar of 102. I want to cut it on 800 x 450 (654 – 2 x 102). So cropWidth=800, cropHeight=450, cropX=0, cropY (shift from the bottom side)=102. Preview I want to see scaled (in dimensions), let’s say 560x315 (16:9 ratio). All my values are well calculated so I want to set SAR on 1:1. DAR should not be used together with SAR (probably ever(?!)) because, in this case, 560x315 has roll of DAR. Preview is perfect. And preview window will "listen" my commands, especially scale! It will not be in aspect (as before) but elastic as I order. Result is perfect (attached screenshot [File 800x654.png])

    Further, I resized video on 800 x 560 and new value for one side black bar is 86. So, I am cropping it cropping: 800 x 388 (560 – 2 x 86) and all values are:
    Code:
    cropWidth=800
    cropHeight=388
    cropX=0
    cropY (shift from the bottom side)=86
    Scale w x h = 560x315
    SAR (obligatory) 1:1
    (attached screenshot [File 800x560.png])
    I just wanted to push ffplay to show preview screen with my values without any automation. Achieved. 2 more screenshots attached: [Scale 560x650.png], [Scale 560x120.png])

    Final ffplay line is
    Code:
    FOR %%g IN (%wpath%\*) DO (
    	%ffmp%\ffplay -i "%%g" -vf "crop=%cw%:%ch%:%cx%:%cy%,scale=%sw%:%sh%,setsar=1:1" -loop 4 -window_title "%%~nxg | CW %cw% CH %ch% CX %cx% CY %cy%" -autoexit
    	)
    Done.

    Thanks _Al_, thanks Bud, thanks all. Still here for further (if any).
    Image Attached Files
    Last edited by Drag; 7th Oct 2018 at 14:00. Reason: Small tipo
    Quote Quote  
  12. personally I use mpv player for all the magic for a while, abandoning ffplay a while ago, for example, its array of options and options might have the same pattern, like ffmpeg
    Code:
    vf=crop=w:h:x:y
    , where you can have even autocrop functions that figure out those values (lua scripts, loading is easy like: --script=/path/to/script.lua)
    Or you might use this setup for cropping visually
    Last edited by _Al_; 7th Oct 2018 at 14:39.
    Quote Quote  
  13. Member
    Join Date
    Oct 2018
    Location
    Serbia
    Search Comp PM
    Originally Posted by _Al_ View Post
    personally I use mpv player for all the magic for a while, abandoning ffplay a while ago, for example, its array of options and options might have the same pattern, like ffmpeg
    Code:
    vf=crop=w:h:x:y
    , where you can have even autocrop functions that figure out those values (lua scripts, loading is easy like: --script=/path/to/script.lua)
    Or you might use this setup for cropping visually
    I know... many good programs today... that MPV is really something very nice... and Wondershare, Premiere... but I created scripts for all life cases. Now I can put 100 files in my DIR and each one will be processed, user will be asked to enter values, will have preview and choisee crop, back, skip or exit ... etc ... and everything must be simple... I am not doing this for myself...
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!