Log in

View Full Version : How to add blackbars to mkv files on bottom and top?


varekai
28th October 2017, 10:31
Hello!

Don't know if this is the right place to post this request...?

I have some mkv files I would like to add blackbars on bottom and top.
The files are 1920x960 and I would like to make them 1920x1080.
That should be 60 extra on top and bottom.
Is there an fairly easy way to do this? Without losing any quality?
If the files get larger it's not a problem.
I don't mind if it's timeconsuming as I guess there have to be some kind of reencode of the mkv's.
A batch mode would be great then I can run the reencodes overnight.

I found a solution where converting the mkv's to other format is needed, then use Vegas Pro and in there add blackbars.
But that reqires two extra software and at least Vegas is not for free.
I'm thinking there have to be an easier way? With free software, maybe Avisynth?
If someone knows what settings/script Avisynth requires please let me know!

Thanks...

Yanak
28th October 2017, 10:51
Try with aviynth :
AddBorders(0, 60, 0, 60, color_black)
or
AddBorders(0, 60, 0, 60, $000000)

But you will have to reencode to get them on your video, i see not other solution, unless just playing the .avs script adding the black borders in a player like MPC-HC for example ( and this might not be very fluid, will depend of your PC performances i guess) , maybe others will have more ideas.

varekai
28th October 2017, 14:39
OK, thanks, will do some testing.
Have to find a good video file converter first.

StainlessS
28th October 2017, 16:33
A lot of people here use MeGUI, or for less experienced perhaps Handbrake, both in MPEG-4 Encoder GUI's forum.

EDIT: There are many additional alternatives in same forum.

Yanak
28th October 2017, 20:16
For the encoder GUI maybe Staxrip (http://forum.doom9.org/showthread.php?t=172068) is a good option as it can do batch encodings.
http://staxrip.readthedocs.io/intro.html#download

You will just need to edit the filter list and add the "AddBorders(0, 60, 0, 60, color_black)"

Maybe using a x264 profile with a very low CRF will do the trick for the no loss of quality needed, not sure what will be the exact parameters for getting something very close to lossless tho.

Audio can be set to be just remuxed into the output container, not touched or re-encoded in Staxrip too, audio is extracted from the source and copied into the output container.

Or something like ProRes codec for output maybe since size is not a problem ? ( also possible in Staxrip, via FFMPEG if i make no errors ) ?

This will need others users with more knowledge to bring more infos to know the best output to choose to get something lossless or close to it for the video re-encoded.

varekai
28th October 2017, 20:24
Using MeGUI adding the script throws an error:
https://s1.postimg.org/3fsk2ick7z/error.png
What am I doing wrong?

I'll try StaxRip!

Thanks for your help Yanak and StainlessS, appreciate it!

Best regards

Yanak
28th October 2017, 20:53
Long time i have not used MEGUI but if i recall correctly :

- Go to tools > Avs Script Creator
- Next to Avisynth profile click the "config" button and add this at the end and validate:
AddBorders(0, 60, 0, 60, color_black)
- Still on this popup window select the video input ( browse it ) , it will open preview.
- close preview and on the main window click on " reopen video preview" to see if the black borders have been added.

As for the output codec and parameters needed ... same as before hard to say what will be close to lossless...
Hard to say more on the error seeing the screenshot tho.


In Staxrip once you just started it create the filter for the borders :
- Right click on the "AVS filters list" then on the contextual menu select " Profiles"
- At the very top of the new popup copy and paste this, then save :
[My Filters]
Add Blackbars = AddBorders(0, 60, 0, 60, color_black)
https://s14.postimg.org/5cpfl1av5/80777020171028214410.png

- Then right click again on the filters list , on the contextual menu " +Add > My Filers > Add BlackBorders"
https://s14.postimg.org/klfcytc9d/58485320171028214642cr.jpg
-You can then save this as template going to "Project > Save as Template " ( and set staxrip to start like this with this filter set already too )

Then click on "source" or at the bottom to select your source using "Single File" , (select "File Batch" and put a few of your videos once you will have all ready and set to your needs )

- Press F5 or click preview to see if all went well with the balckbars added.
- for the audio select copy/mux ( click on the default "opus 250 kpbs" to change it)

Then next step is finding a nice preset and setting for a lossless as possible output ( clicking on x264 on the UI ), a low crf of 16-18 instead of 20 like it have by default should bring good results i think.

Again this will need someone else help for the best encoding codec and settings, the rest i could provide help again if needed to set this once parameters are known, here or on the Staxrip thread ^^ ( same about MEGUI, best will probably to ask help on the dedicated threads or dedicated forum section for the most lossless possible settings you need for the encodings )

Good Luck.

Edit : maybe RipBot (http://forum.doom9.org/showthread.php?t=127611) could be a solution too, have not used it since years and can't even remember how to add a simple avisynth filter on it or if it is even possible :p
but it's maybe a solution for batch encoding, you will need to ask on the dedicated thread ^^

manono
29th October 2017, 00:37
UncropMKV (https://www.videohelp.com/software/uncropMKV) was designed for what you want. Since it uses AviSynth, it'll reencode.

varekai
29th October 2017, 10:13
UncropMKV (https://www.videohelp.com/software/uncropMKV) was designed for what you want. Since it uses AviSynth, it'll reencode.
ESET Internet Security Scan Log
Version of detection engine: 16321 (20171029)
Date: 2017-10-29 Time: 09:58:18
Scanned disks, folders and files: *:\***\uncropMKV 1.55\uncropMKV_1.55.exe
*:\***\uncropMKV 1.55\uncropMKV_1.55.exe » NSIS » AcPro.exe » INNO » {app}\AutocompletePro.dll - a variant of Win32/Complitly.
A potentially unwanted application - action selection postponed until scan completion.
Number of scanned objects: 43
Number of threats found: 1
Number of cleaned objects: 1
Time of completion: 09:59:05 Total scanning time: 47 sec (00:00:47)

Cut from videohelp:
WARNING
uncropMKV 1.55 installed AutoCompletePro without asking.
To remove this malware see https://malwaretips.com/blogs/remove-autocomplete-pro/

Not cool at all!!

----------------------------------------------

Edit:
Well it seems Mr. Dean have a clean version on his site, no adware warning from ESET!
multiavchd.deanbg.com/uncropMKV/
Mr. Dean is a very clever man, I wish he would continue working on his smart tools, I use quite a few of them.

varekai
29th October 2017, 10:21
@Yanak
Got StaxRip to do what I wanted, good thing is it works directly on mkv so no need for converting.
Bad thing is it takes forever... so now it's time to confer with two of my best colleagues, trial & error...

Groucho2004
29th October 2017, 11:05
Funny that everyone suggest some "GUI". ffmpeg can do this easily using the "pad" option with a simple command line.
For example:
ffmpeg -i "input.mkv" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "output.mkv"

Also in batch mode:
if not exist output md output
for %%i in (*.mkv) do (
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "output\%%~ni.mkv"
echo.
)

StainlessS
29th October 2017, 11:28
Funny that everyone suggest some "GUI"

I guess that we were all waitin' for the wisdom of G2K4, thanx ol' wise one for those 'simple command line's :)

varekai
29th October 2017, 11:30
Funny that everyone suggest some "GUI". ffmpeg can do this easily using the "pad" option with a simple command line.
Probably because it's a steep learning curve for users who are unfamiliar with this type of interface.
I will look into this:
https://www.ffmpeg.org/ffmpeg.html
Maybe I could learn how to use it.

Yanak
29th October 2017, 11:38
Yup i'm too used to gui tools, only using cmd line and things like ffmpeg for very specific needs, not having the reflex to look into this first, forgot it had the possibility to add the bars too, at the same time this tool have so many options...

For the -crf 21 isn't this value a bit too high for the re-compression since he wanted to not loose any quality at all ? Maybe 16-18 will be better for this purpose and a small loss of quality, maybe combined with -ssim parameter too? maybe, i'm not sure.

I noted this command for a possible use of it one of those days too , thanks ;)

Groucho2004
29th October 2017, 11:41
For the -crf 21 isn't this value a bit too high for the re-compression since he wanted to not loose any quality at all ? Maybe 16-18 will be better for this purpose and a small loss of qualityYes, encoding parameters as needed. It was just an example to demonstrate the use of "pad".

Yanak
29th October 2017, 11:46
Got it, for this part he will need external help, i know only one real way to do lossless it's with x265 --lossless but the output file sizes are so big that it becomes crazy unless you do this on very short videos for very specific needs.

Now needs to find out what re encoding parameters will bring the minimal loss possible ^^

Thank you.

Sharc
29th October 2017, 12:31
Probably because it's a steep learning curve for users who are unfamiliar with this type of interface.
I will look into this:
https://www.ffmpeg.org/ffmpeg.html
Maybe I could learn how to use it.
Or import your file with BD-Rebuilder and select a BD (or AVCHD) compliant output. It will add the borders automatically for you.

varekai
29th October 2017, 13:57
Funny that everyone suggest some "GUI". ffmpeg can do this easily using the "pad" option with a simple command line.

I learnt how to set up ffmpeg and it's working.
Is the correct way to add -crf 0 for keeping files "untuched"?
The results I get is very close to original size, sligthly larger but that would be expected.
Thanks for your help, learned a lot, lots of fun! :D

Edit:
How would the batch script look when having these mkv files in lets say drive X:
But I want to have another output drive like Y:


if not exist output md output
for %%i in (*.mkv) do (
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "output\%%~ni.mkv"
echo.
)


Regards

varekai
29th October 2017, 13:58
Or import your file with BD-Rebuilder and select a BD (or AVCHD) compliant output. It will add the borders automatically for you.
I will try this as I used BD-RB before.
Thanks.

Groucho2004
29th October 2017, 14:17
Is the correct way to add -crf 0 for keeping files "untuched"?
The results I get is very close to original size, sligthly larger but that would be expected.CRF 0 is lossless but the resulting file size would be very large compared to the source. So, I'm quite puzzled that you get a size close to the source.

Groucho2004
29th October 2017, 14:33
Edit:
How would the batch script look when having these mkv files in lets say drive :X
But I want to have another output drive like :Y

Something like this:
@echo off
set SOURCEPATH=X:\Source Files
set TARGETPATH=Y:\Target Files

if not exist "%SOURCEPATH%" goto ErrorSource
if not exist "%TARGETPATH%" goto ErrorTarget

for %%i in ("%SOURCEPATH%\*.mkv") do (
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "%TARGETPATH%\%%~ni.mkv"
echo.
)
goto Exit

:ErrorSource
echo Source path "%SOURCEPATH%" does not exist.
goto :eof

:ErrorTarget
echo Target path "%TARGETPATH%" does not exist.
goto :eof

:Exit
echo Done.
echo.

varekai
29th October 2017, 15:50
CRF 0 is lossless but the resulting file size would be very large compared to the source. So, I'm quite puzzled that you get a size close to the source.
I used a small file, 1,75 MB for testing purposes, it came out to 1,91 MB.
So with a larger input file the output will be significantly larger.
Have to test that, maybe change the CRF upwards a lot.

varekai
29th October 2017, 15:54
Something like this:

Thank you so much for your help.
Will set things up and run overnight, hopefully I'll get good results.
I'll let you know tomorrow.

Regards

varekai
30th October 2017, 12:46
@Groucho2004

Hello!

I have probably not got paths correctly for batch script because I can't get it to work?
Single file script works perfectly!
Using Shift+Ctrl--> rightclick on empty space--> Open command window here.
T:\>ffmpeg -i *(copy/paste script)* then run single file script you provided and all is good.
I ran it with -crf 16 but file was undersized so I will test with with lowering -crf until I get closer to original file.

But I can't figure out how to batch add several mkv's like
01.mkv
02.mkv
03.mkv and so on.
I place source mkv's in root of T: and output target to mkv's in root of R:
But when running script I get errors.

This is how I do it and the errors I get.
I've changed drives to source path T: and target path R: where I have more space.
T:\>ffmpeg -i *(add batch script copy/paste)*

@echo: No such file or directory
Unexpected %%i. *(<-- my translation from swedish to english)*
%%i: No such file or directory
T:\>:ErrorSource
T:\>echo Source path "%SOURCEPATH%" does not exist.
Source path "T:\Source Files" does not exist.
T:\>:ErrorTarget
T:\>echo Target path "%TARGETPATH%" does not exist.
Target path "R:\Target Files" does not exist.
I don't wan't to occupy this avisynth thread so I'm OK with doing my project files one by one.
If I can get batch mode working it's a big bonus!

Thanks and best regards,
varekai

Groucho2004
30th October 2017, 17:29
But I can't figure out how to batch add several mkv's like
01.mkv
02.mkv
03.mkv and so on.

Create a batch file with the commands I posted in #22
Create the directories according to the "SOURCEPATH" and "TARGETPATH" variables
Put the source MKVs in the source directory
Run the batch file

varekai
30th October 2017, 18:43
Create a batch file with the commands I posted in #22
Create the directories according to the "SOURCEPATH" and "TARGETPATH" variables
Put the source MKVs in the source directory
Run the batch file

If I'm being a PITA we can just drop this and I'll try to figure this one out or just don the projekt one by one...
Best regards,
varekai

The batchfile:
ffmpeg -i @echo off
set SOURCEPATH=T:\
set TARGETPATH=R:\

if not exist "%T:\%" goto ErrorSource
if not exist "%R:\%" goto ErrorTarget

for %%i in ("%T:\%\*.mkv") do (
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "%R:\%\%%~ni.mkv"
echo.
)
goto Exit

:ErrorSource
echo Source path "%T:\%" does not exist.
goto :eof

:ErrorTarget
echo Target path "%R:\%" does not exist.
goto :eof

:Exit
echo Done.
echo.
The error
T:\>ffmpeg -i @echo off
(removed stuff for viewing purposes)

@echo: No such file or directory

T:\>set SOURCEPATH=T:\

T:\>set TARGETPATH=R:\

T:\>
T:\>if not exist "%T:\%" goto ErrorSource

T:\>if not exist "%R:\%" goto ErrorTarget

T:\>
T:\>for %%i in ("%T:\%\*.mkv") do (
Oväntat %%i.
T:\> start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "%R:\%\%%~ni.mkv"
(removed verision and other ffmeg stuff for viewing purposes)
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
%%i: No such file or directory

T:\> echo.


T:\>)
T:\>goto Exit

T:\>
T:\>:ErrorSource
T:\>echo Source path "%T:\%" does not exist.
Source path "%T:\%" does not exist.

T:\>goto :eof

T:\>
T:\>:ErrorTarget
T:\>echo Target path "%R:\%" does not exist.
Target path "%R:\%" does not exist.

T:\>goto :eof

T:\>
T:\>:Exit
T:\>echo Done.
Done.

T:\>echo.

Groucho2004
30th October 2017, 18:46
If you remove the "ffmpeg -i" from the beginning of the batch file it will work. Also, don't use the root directories of your drives, it's bad practice.

Edit: OK, I just noticed that the batch file is really screwed up. The only thing you should have changed are the "SOURCEPATH" and "TARGETPATH" variables at the beginning.

If you decide to continue you should read up on batch files.

varekai
30th October 2017, 19:18
If you remove the "ffmpeg -i" from the beginning of the batch file it will work. Also, don't use the root directories of your drives, it's bad practice.

Edit: OK, I just noticed that the batch file is really screwed up. The only thing you should have changed are the "SOURCEPATH" and "TARGETPATH" variables at the beginning.

If you decide to continue you should read up on batch files.
Like this?
@echo off
set SOURCEPATH=T:\Source Files (*mkv.01 mkv.02 etc. in here)*
set TARGETPATH=R:\Target Files

if not exist "%SOURCEPATH%" goto ErrorSource
if not exist "%TARGETPATH%" goto ErrorTarget

for %%i in ("%SOURCEPATH%\*.mkv") do (
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "%TARGETPATH%\%%~ni.mkv"
echo.
)
goto Exit

:ErrorSource
echo Source path "%SOURCEPATH%" does not exist.
goto :eof

:ErrorTarget
echo Target path "%TARGETPATH%" does not exist.
goto :eof

:Exit
echo Done.
echo.
Still get error:

T:\>@echo off
set SOURCEPATH=T:\Source Files
set TARGETPATH=R:\Target Files

if not exist "%SOURCEPATH%" goto ErrorSource
if not exist "%TARGETPATH%" goto ErrorTarget

for %%i in ("%SOURCEPATH%\*.mkv") do (
Oväntat %%i. *(Unexpected)*
start/b/wait/low ffmpeg -i "%%i" -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -preset slow -crf 21 -c:a copy "%TARGETPATH%\%%~ni.mkv"

*(removed stuff)*

%%i: No such file or directory
echo.

)
goto Exit

:ErrorSource
echo Source path "%SOURCEPATH%" does not exist.
Source path "T:\Source Files" does not exist.
goto :eof

:ErrorTarget
echo Target path "%TARGETPATH%" does not exist.
Target path "R:\Target Files" does not exist.
goto :eof

:Exit
echo Done.
Done.
echo.
I will study more on batch files.
Thanks for your help, appreciate it!
Best regards,
varekai

Groucho2004
30th October 2017, 19:26
Are you pasting the content of the batch file into your command line?

varekai
30th October 2017, 19:29
Are you pasting the content of the batch file into your command line?
Yes, copy and paste.

Groucho2004
30th October 2017, 19:34
So, you didn't read my instructions. :D

You're supposed to create a batch file. Name it as you wish, for example "mkvpad.bat". Run the batch file just as you would run an executable file.

varekai
30th October 2017, 19:49
Hahaha... are you kidding me!!? F*** this is so cool, it's works like a charm! :D
Blame it on the language barrier... or more like me being stupid!
Your my hero Groucho!
https://s1.postimg.org/3gf6kovey7/a-child-of-five.jpg

SeeMoreDigital
30th October 2017, 22:32
I have some mkv files I would like to add blackbars on bottom and top.
The files are 1920x960 and I would like to make them 1920x1080.
That should be 60 extra on top and bottom.
Is there any particular reason why you want to do this?

varekai
30th October 2017, 23:53
Is there any particular reason why you want to do this?
My aim is to be able to keep my own created sup subtitles at the bottom of the video.
I'll load the sup subtitles into PotPlayer at V:Position (%) 100
Add padding to 1080 makes it possible to have subtitles at the bottom.
Was thinking about add padding 120 at bottom only but that would probably look strange?
Hmm... maybe not, think I'll try that, if I can figure out how to that is...

Regards

Edit:
PotPlayer cannot use V:Position (%) on any sup suptitles, their bottom margin is fixed for PotPlayer.
So first I use EasySup by mr. deank and in there I set the margin (0) of sup.
Sorry for the confusion, was rather tired last night...

I tested to add 120 at bottom but only managed to get 120 at the top?
Any ideas? I'll keep testing.
Edit: I figured it out, looks great with 120 black bar at bottom!
Kudos Groucho! Case closed! :D