VideoHelp Forum




+ Reply to Thread
Results 1 to 18 of 18
  1. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    My head hurts! Could you FFMPEG gurus help me out here; I've spent the afternoon on this but am stuck.

    On a set of DV files in a folder, I'm trying to crop off the top 2 pixels and the rightmost 4 pixels, then resize them to 1440x1080.

    Code:
    for %%A in (*.avi) do C:\ffmpeg\bin\ffmpeg.exe ^
    -i "%%A" ^
    -vf "bwdif=mode=0,hqdn3d=1.5:1.5:3:3" ^
    -vf "crop=716:574:0:2" ^
    -vf "scale=1440:1080" ^
    -c:v libx264 -crf 24 -preset medium ^
    -pix_fmt yuv420p ^
    -c:a aac ^
    -b:a 192k ^
    "%%~nA.mp4"
    The script runs fine without the Crop command as shown, resizing to 1440x1080, but cropping doesn't occur.

    Extra question: how can I comment out a line (similar to # in AVISynth)? I've tried REM and #, to no avail.

    I realise the colour format is wrong but will attend to that later.

    Why, you ask? Although Handbrake does this, the folder setups and the Dimensions are just weird and illogical and I can't cope! I simply drop this BAT into a folder, double-click it and it's done. Just have to sort out the cropping.

    I've attached a short DV file.

    I would really appreciate any help you can provide.
    Image Attached Files
    Last edited by Alwyn; 4th Nov 2026 at 18:41. Reason: Crop value amended.
    Quote Quote  
  2. Banned
    Join Date
    Nov 2026
    Location
    Brazil
    Search Comp PM
    Ah, that’s the classic multiple -vf gotcha: ffmpeg is only using the last one, so combine them into a single comma-separated filter chain like -vf bwdif=mode=0,hqdn3d=1.5:1.5:3:3,crop=716:574:0:2,s cale=1440:1080. Also double-check the crop width: 720 minus 4 is 716, so 718 would only trim 2 from the right.
    Quote Quote  
  3. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Boom! Thank you Sidonia, that works a treat. Well spotted on the pixel count, I'll change my calculator batteries.
    Quote Quote  
  4. Comma separators are missing. Try
    ffmpeg.exe -i "ffmpeg crop\20050813_180811 T11 snip.avi" ^
    -vf bwdif=mode=0,hqdn3d=1.5:1.5:3:3,crop=718:574:0:2,s cale=1440:1080 -c:v libx264 -crf 24 -preset medium -pix_fmt yuv420p -c:a aac -b:a 192k out.mp4

    For commenting use REM or ::
    Quote Quote  
  5. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Thanks Sharc, tried REM and double colon but no joy, the command window closes immediately.
    Quote Quote  
  6. Originally Posted by Alwyn View Post
    Thanks Sharc, tried REM and double colon but no joy, the command window closes immediately.
    Yes, looks like one cannot use it within a commandline to skip certain parts ....

    Btw., you can still break down your commandline into several lines, something like
    Code:
    ffmpeg.exe -i "ffmpeg crop\20050813_180811 T11 snip.avi" ^
    -vf bwdif=mode=0,^
    hqdn3d=1.5:1.5:3:3,^
    crop=718:274:0:2,^
    scale=1440:1080^
     -c:v libx264 -crf 24 -preset medium -pix_fmt yuv420p -c:a aac -b:a 192k^
     out.mp4
    
    pause
    I usually put pause at the end so the window stays open to read the log/error messages.
    Last edited by Sharc; 4th Nov 2026 at 08:14.
    Quote Quote  
  7. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Thanks Sharc, I'll try that. I saw some red errors go past but they disappeared.
    Quote Quote  
  8. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Thanks very much to all, this is what I've come up with that works:

    Code:
    for %%A in (*.avi) do C:\ffmpeg\bin\ffmpeg.exe ^
    -i "%%A" ^
    -vf "bwdif=1:1:0","hqdn3d=4:3:6:4.5","crop=716:572:0:2","scale=1440:1080" ^
    -c:v libx264 -crf 24 -preset medium ^
    -pix_fmt yuv420p ^
    -c:a aac ^
    -b:a 192k ^
    -ar 48000 ^
    "%%~nA.mp4"
    
    pause
    My next question... this script runs in a folder to convert all the DV files in that folder. But I have many folders of DV files and want to convert all the files in all the folders in one go. They are located in a parent folder called "DV".

    Is that possible and how would I go about it? I have looked at Google AI but it fails. This is the Powershell code it gave me:

    Code:
    Get-ChildItem -Recurse -Filter *.dv | ForEach-Object {
        $mp4Path = $_.FullName -replace '\.dv$', '.mp4'
        \ffmpeg\bin\ffmpeg.exe -i $_.FullName -c:v libx264 -preset medium -crf 20 -c:a aac -b:a 192k "$mp4Path"
    }
    If I can get this working, I'll modify the vf to match my original script.

    Thanks for any help!
    Last edited by Alwyn; 4th Nov 2026 at 21:36. Reason: Powershell ref added.
    Quote Quote  
  9. Originally Posted by Alwyn View Post
    Thanks very much to all, this is what I've come up with that works:

    Code:
    for %%A in (*.avi) do C:\ffmpeg\bin\ffmpeg.exe ^
    -i "%%A" ^
    -vf "bwdif=1:1:0","hqdn3d=4:3:6:4.5","crop=716:572:0:2","scale=1440:1080" ^
    -c:v libx264 -crf 24 -preset medium ^
    -pix_fmt yuv420p ^
    -c:a aac ^
    -b:a 192k ^
    -ar 48000 ^
    "%%~nA.mp4"
    
    pause
    Before targeting mass production you may want to take a look at the colorspace. For upscaling SD->HD I would apply bt601 -> bt709 conversion to prevent color distortions upon playback. Or keep the original resolution and leave the upscaling to the TV.
    For upscaling I suggest to modify the scale like
    Code:
    scale=1440:1080:in_color_matrix=bt601:in_range=limited:out_color_matrix=bt709:out_range=limited


    Can't help you much with the powershell issue. But try putting below in the parent (DV) folder. It should then start with the current (DV) folder and walk through the subfolders (I think this is what you want):

    Code:
    for /R %%A in (*.avi) do C:\ffmpeg\bin\ffmpeg.exe ^
    -n -i "%%A" ^
    -c:v libx264 -crf 24 -preset medium -pix_fmt yuv420p ^
    -c:a aac -b:a 192k -ar 48000 -movflags +faststart ^
    "%%~dpnA.mp4"
    
    pause
    The -n in the second line skips any existing .mp4 with the same name. Leave the -n away if you prefer to be prompted, or use -y to overwrite.
    Last edited by Sharc; 5th Nov 2026 at 03:39.
    Quote Quote  
  10. Alwyn,
    I'm hopeless with batch scripts, but if you happen to be interested in using a GUI you could try AnotherGUI. You can drag and drop the source files onto the GUI to queue the encoding jobs, and you can also configure "watch folders"' so it'll automatically encode files. I haven't used the "watched folders" option for quite a while, but from memory it's fairly versatile. For it to work, you have to download some SQLite files and copy them to the AnotherGUI folder. There's links here. https://www.stuudio.ee/AnotherGUI/
    I'm pretty sure you can drag and drop whole folders onto the GUI, although I'm not sure if sub-folders are automatically added too.

    An ffmpeg preset for x265/AAC encoding with AnotherGUI could look something like this. If you want to write the output files to the same folder as the source files and they have the same extension, this will append "_encoded" to each output file name. If you don't need it to do that, you can delete _encoded from the output name in the preset.

    Code:
    (Executable ffmpeg.exe)
    -i "<FullSourceFileName>" -vf bwdif=mode=0,hqdn3d=1.5:1.5:3:3,crop=716:574:0:2,scale=1440:1080 -c:v libx264 -crf 24 -preset medium -pix_fmt yuv420p -c:a aac -b:a 192k -movflags faststart "<OutputPath><OutputFileName>_encoded.mp4"
    Or you could use an Avisynth script for the filtering and x264/x265 for the encoding, although you'd have to create a script for each source file and handle the audio separately.
    Normally when upscaling SD to HD, I'd convert the video from rec.601 to rec.709 with an Avisynth plugin, then specify rec.709 as the VUI info for the encoder to write. I don't know how to convert the colors with ffmpeg off the top of my head, but a typical x264 preset for encoding Avisynth scripts looks like this for me:

    Code:
    (Executable x264.exe)
    --level 4.1 --preset slow --tune film --crf 20.0 --b-adapt 2 --me umh --subme 9 --partitions all --no-fast-pskip --stitchable --sar 1:1 --threads 12 --vbv-bufsize 50000 --vbv-maxrate 50000 --colorprim bt709 --transfer bt709 --colormatrix bt709 --output "<OutputPath><OutputFileName>.mkv" "<FullSourceFileName>"
    For encoding Avisynth scripts with x265.exe you have to pipe from ffmpeg. Once again, this is just an encoder preset of mine I copied and pasted as an example.

    Code:
    (Executable cmd.exe)
     /d /c "C:\Encoders\ffmpeg\ffmpeg.exe" -i "<FullSourceFileName>" -strict -1 -f yuv4mpegpipe - | "C:\Encoders\x265\x265.exe" --crf 20.0 --profile main10 --preset slow --deblock=-1:-1 --no-open-gop --ctu 32 --rc-lookahead 80 --lookahead-slices 0 --rd 4 --psy-rd 2.0 --rdoq-level 2 --psy-rdoq 1.5 --aq-strength 1.3 --no-strong-intra-smoothing --no-sao --sar 1:1 --colorprim bt709 --transfer bt709 --colormatrix bt709 --output "<OutputPath><OutputFileName>.hevc" --y4m --input -
    In preferences, it'd be a good idea to set the number of processes to 1, as it defaults to the number of cores your CPU has, which means for a 6 core CPU with hyperthreading it'd try to run 12 encodes simultaneously.
    Last edited by hello_hello; 5th Nov 2026 at 06:21.
    Quote Quote  
  11. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Originally Posted by Sharc
    But try putting below in the parent (DV) folder. It should then start with the current (DV) folder and walk through the subfolders (I think this is what you want):
    Your blood's worth bottling Sharc, thanks very much, that's working superbly.

    Thanks Hello, I'll study your reply. I had a play with the 709 commands (similar to yours in your script) but they all failed, my syntax was wrong apparently. I think I'll just go with Sharc's suggestion of SD.
    Quote Quote  
  12. FWIW attached a demo what usually happens to the colors when one forgets the 601->709 conversion for SD->HD upscaling.
    Image Attached Files
    Quote Quote  
  13. Originally Posted by Alwyn View Post
    Your blood's worth bottling Sharc, ...
    Something new, every day
    Quote Quote  
  14. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    This stuff is frustrating... an example:

    This runs OK:
    -vf "bwdif=1:1:0","hqdn3d=4:3:6:4.5","crop=716:572:0:2 ","scale=768:576" ^

    This doesn't:
    -vf -bwdif=1:1:0 -hqdn3d=4:3:6:4.5 -crop=716:572:0:2 -scale=768:576 ^

    With this message:
    "Unrecognized option 'hqdn3d=4:3:6:4.5'.
    Error splitting the argument list: Option not found"

    It obviously does know what hqdn3d is, but won't accept it when using -.
    Quote Quote  
  15. Originally Posted by Alwyn View Post
    This doesn't:
    -vf -bwdif=1:1:0 -hqdn3d=4:3:6:4.5 -crop=716:572:0:2 -scale=768:576 ^
    Illegal syntax, use:
    -vf bwdif=1:1:0,hqdn3d=4:3:6:4.5,crop=716:572:0:2,scal e=768:576 ^

    The different video filters (-vf) need to be comma-separated, not by -
    The quotation marks just serve to ignore blanks and special characters.
    Last edited by Sharc; 5th Nov 2026 at 08:53.
    Quote Quote  
  16. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Originally Posted by Sharc
    FWIW attached a demo what usually happens to the colors when one forgets the 601->709 conversion for SD->HD upscaling.
    I'm onto it!

    The different video filters (-vf) need to be comma-separated,
    Got it, thanks. I was misled by the other lines and their -.
    Quote Quote  
  17. Member
    Join Date
    May 2005
    Location
    PAL User
    Search Comp PM
    Success (I think) with color 601 to 709. I used:

    colorspace=all=bt709:iall=bt601-6-625:fast=1
    Last edited by Alwyn; 5th Nov 2026 at 09:48.
    Quote Quote  
  18. Probably faster with hardly noticeable difference:
    Code:
    -vf scale=1440:1080:in_color_matrix=bt601:in_range=limited:out_color_matrix=bt709:out_range=limited ^
    -c:v libx264 -crf 24 -preset medium -pix_fmt yuv420p ^
    -colorspace bt709 -color_primaries bt709 -color_trc bt709 -color_range tv ^
    last line added to set the metadata (maybe double-stitching....)
    Last edited by Sharc; 5th Nov 2026 at 10:24.
    Quote Quote  



Similar Threads

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