Avidemux Forum

Avidemux => Windows => Topic started by: guju on January 12, 2019, 03:08:12 PM

Title: Display Aspect Ratio - If and how to set
Post by: guju on January 12, 2019, 03:08:12 PM
I made a copy of a typical movie DVD (PAL ,760 x 576) to my HD (orig streams in a MKV).
The display aspect ratio (in original and copy) was 4:3, and the copy showed fine.

Now I wanted to squeeze it a litte more (HEVC).
With "standard settings" the DAR 4:3 seems to get lost,
and the compressor's config don't seems to be the right place to set it.

My questions:
Is the only (right) place to set the DAR the output format of the muxer?
(But not all formats support DAR).
Or is it better to resize the movie to the destination format?
(Better quality, and done once & forever)
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 12, 2019, 10:44:52 PM
760x576 is not the PAL resolution, it is either 720x576 or 704x576 displayed at 4:3 or 16:9 DAR. I would not resize the movie but simply set the desired DAR in the container. It doesn't matter that not all muxers support it. The two that matter (mp4 and mkv) do.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 13, 2019, 12:04:48 AM
Yes, sorry, 760 was a typo.
And thankyou for confirming the newbie's guess about setting the DAR.  :)
(Still: Would it be an idea to let Avidemux set the DAR from source by default?)

And then my thinking was that it would be better to resize the movie
+ better quality (than "on the fly" when viewing)
+ saves ressources (done once and forever)
- slightly more space (due to enlarged resolution)
Why am I wrong?
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 13, 2019, 10:23:35 AM
Quote from: guju on January 13, 2019, 12:04:48 AM
Still: Would it be an idea to let Avidemux set the DAR from source by default?

AFAIR the existing video filter interface in Avidemux doesn't allow passing aspect ratio information. It was also a design choice (probably for performance reasons as the fallback video output, used by default on Windows, is not hw accelerated) to use square pixel throughout the application.

QuoteAnd then my thinking was that it would be better to resize the movie
+ better quality (than "on the fly" when viewing)
+ saves ressources (done once and forever)

Videos, especially standard definition videos, are seldomly watched without scaling, they get usually scaled on-the-fly by the graphics card or TV set hardware anyway with very high quality and minimal overhead. Basically, my feeling was that 720x576 is standard and the original resolution, so don't change what is not broken.

On the other hand, if the video is interlaced, you really should insert a good deinterlacer (in Avidemux: yadif) into the filter chain before feeding images to the encoder. This is very important.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 13, 2019, 01:06:17 PM
Quote from: eumagga0x2a on January 13, 2019, 10:23:35 AM
...

On the other hand, if the video is interlaced, you really should insert a good deinterlacer (in Avidemux: yadif) into the filter chain before feeding images to the encoder. This is very important.

Wait a minute ...
(I have to realize that deep hole that just opened in front of me ...  :o )

Actually until now I literally never cared about interlacing.

Does this mean that every time my source video is interlaced I have to deinterlace it before any filtering/ encoding?

In the example of this thread the standard DVD is interlaced.
I simply resized and hevc-encoded it into an MKV.
MediaInfo doesn't show "Scan Type" from that, but in the "encoding settings" it says "interlace = 0",
so I presume it's progressive.
However the quality is undistinguable from the source ... (?)
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 13, 2019, 01:25:42 PM
Interlacing is the greatest inconvenience and generally a PITA as all displays nowadays expect progressive video images.

QuoteDoes this mean that every time my source video is interlaced I have to deinterlace it before any filtering/ encoding?

Yes, you really should, especially when resizing. Always deinterlace first, resize second.

QuoteIn the example of this thread the standard DVD is interlaced.

Sometimes I experienced fake interlaced material, i.e. technically the video is interlaced, but both halfs belong to a single progressive frame. If you don't see jagged outlines with fast moving objects when stepping through the video in Avidemux, it is most likely the case. This would also explain why the visual quality remains good after re-encoding. You don't need a deinterlacer then.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 13, 2019, 01:38:44 PM
Well - all I can say again:  Thank you for your hint and your help!  :)

Maybe it would be an idea ... to prevent unexperienced like me to worsen movies,
to give a message in Avidemux, when "save" is clicked, and the source is interlaced and in the filter chain/ encoder
there is no deinterlacer?
(And even profs may forget it sometimes).

To my experience it would generally (in our world) be a good idea to more give assistance/ hints,
to prevent quality loss/ miss-handling, instead of doing it ever more complicated ...

Greetings!
Title: Re: Display Aspect Ratio - If and how to set
Post by: fish on January 13, 2019, 01:57:59 PM
You don't state how the video will be viewed. I change the DAR of mp4's that display at the wrong ratio by using Yamb. It doesn't re-encode the video but I don't know whether it works  for anything other than playing in Windows Media Player Classic. One thing I don't understand is, if you are going to re-encode the video to HEVC, why you don't simply resize the video at that stage or if it is just display ratio change you need, set the player to display at the desired ratio.
If you want to try Yamb simply, double click on create an mp4, drag your video into Yamb, select just the video track in the window and on the right click the properties tag. At Pixels Aspect Ratio select custom. In your case i think you want to change the video from displaying at 16:9 to display at 4:3 or to make sums easier 16:9 to 12:9.
So to keep the height the same enter 100 (think of it a percent) in the right hand box.
12/16 = 0.75 so enter 75 in the left hand box. When you save the video (change the name slightly or save in a different location) it should play at 4:3 without changing settings in your player every time.
If you re-edit the video you will need to repeat the process as this doesn't change the video dimensions, simple how it is displayed.
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 13, 2019, 02:05:36 PM
I assume, MP4Box manipulates in this case just the container metadata. You achieve the same with the Mp4 muxer in Avidemux with or without re-encoding. Many (all good ;-)) players respect DAR specified at the container level. I advise against resizing during re-encoding if this is not absolutely necessary (in case the target equipment is known to be incapable of interpreting DAR container metadata).
Title: Re: Display Aspect Ratio - If and how to set
Post by: fish on January 13, 2019, 03:22:14 PM
Ah yes, I didn't know that feature was there in mp4 without re-encoding, I think I have noticed that in Mpeg TS or it may have been MKV. I think a custom option would be a handy addition for weird or non standard video sizes, that play at the wrong DAR. The original pixel aspect ratio could be 1:1, 4:3 PAL or NTSC, 16:9 PAL or NTSC or the video could be cropped to some non standard size which tends to lead to unreliable results when changing the DAR using standard 16:9 and 4:3 settings.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 13, 2019, 03:27:56 PM
This DAR thing seems to be another PITA ...  ;)

However I do agree now that one should only resize to the DAR if not resized when viewing in the actual device again.
Which very seldom will be the case.

BTW
As my movie seems to be "fake interlaced" - isn't there a simple technical way to determine that?
By looking at the motion vectors (but how?) for example?
Title: Re: Display Aspect Ratio - If and how to set
Post by: fish on January 13, 2019, 07:36:36 PM
You should be able to tell very easily by zooming in on a high motion area. In WMPC press 9 on your number key pad and alt 1-9 to pan around. It may also use MBAFF which is a mixture of interlaced and progressive, although I've never seen a movie encoded like that.  MBAFF is usually used for TV broadcasting but even movies broadcast on TV are in progressive. As far as I know only movies that have been telecined for American TV or DVD would be interlaced. In PAL land I think they just speed them up to 25 fps.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 13, 2019, 08:13:11 PM
Thanks for the information.
Still, MediaInfo says most of the standard movie DVDs to be interlaced. (???).

However after playing around I would like to report an effect about DAR setting:

The scenario as above quite simple:

First I copied the streams from a standard movie DVD to MKVs.

That MKVs consist of 720 x 576, PAL. DAR: 4:3.

When playing that with MPC-HC (View / Aspect Ratio set to "Default")
the video shows with 768 x 576 as expected (W * (4/5) * (4/3)).
A saved frame is 720 x 576.

OK so far.

Now I let Avidemux read the MKV and do a simple copy of audio and video
and "output format" forced DAR = 4:3 for the MKV output.
It plays alright.

If I don't set the DAR in the output format, MPC shows a 720 x 576 movie.
OK too.
BUT MediaInfo still says DAR 4:3, PAL.
(Actually MediaInfo shows identical info. Although "somewhere" there
MUST be the information of forced DAR as MPC plays it different)
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 13, 2019, 11:05:37 PM
I did a brief test encoding a short 720x576 16:9 mpeg2 clip with x264 to H.264 using MKV as container to determine video player behavior when info from the codec and from the container disagreed. I tested with mpv, vlc, totem and ffplay. I also checked with MediaInfo.

For the first round, I enabled the 64:45 pixel aspect ratio in the codec settings. No display width or DAR forced at the container level. From the video players above only totem displayed the video at 16:9 DAR, mediainfo also showed 16:9 as DAR.

For the second round, I forced display width / DAR at the container level. Pixel aspect ratio in codec settings was set to 1:1. All players played the sample at 16:9 DAR. MediaInfo showed 16:9 as "Display aspect ratio" and additionally 5:4 as "Original display aspect ratio".

The lesson is clear: the chances to get the desired result are much higher when setting DAR at the container level. Setting both in codec and in the container doesn't harm, but few players honor the former.

Technically MKV doesn't store a rational for DAR but simply stores the display width. The DAR menu in the Avidemux' MKV muxer facilitates the procedure for users.

MediaInfo is not a tool to explore MKV structures, use MKVToolNix or an equivalent for that.

Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 14, 2019, 12:02:36 AM
Thankyou for the test!
This DAR thing seems to be a little ... "delicate".

Meanwhile I did tests for myself, and got strangest effects
if using (crop) filter in the procedure:
The shown videos have never the size I expected.
Either I misunderstand all that, or within the filterchain
there are unexpected DAR values used (from the codec?).

Concrete Example:
Croping my orig video from above to 698x448.
MKV output DAR 4:3.
=> Too small in width.
Title: Re: Display Aspect Ratio - If and how to set
Post by: fish on January 14, 2019, 01:15:19 AM
Your cropped example demonstrates why a custom setting is needed when the video is not a standard size. If the video is encoded as PAL or NTSC the pixels are non square, unlike HD video which uses square pixels. So if you crop PAL or NTSC encoded video, so that the frame height to width ratio is changed, then the standard multiples such as in Avidemux no longer give the expected results. If I remember NTSC encoded pixels are taller than they are wide, PAL wider than they are tall, HD video uses square pixels as do computer monitors. So it is not that "This DAR thing seems to be a little ... "delicate".", it is just that there are complications due to older legacy formats used in DVD's and PAL/NTSC television formats. Sorry it is not all simple, I notice even the television professionals occasionally get it wrong when mixing old footage with new.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 14, 2019, 09:34:05 AM
Thank you.
Being a simple user I still hadn't the right notion of DAR.
There seem to be a lot of pitfalls one is not aware of
- even if being fallen in.
Of course Avidemux can't be blamed for that. It gives you
full freedom (= responsibility).
Still - as said - this situation will lead to worsening quality
(by the simple user, and occational even by profs).

I well understand that the devs of Avidemux have enough other
things to do, still I think a way would be to have something
like a "check option", that tests "unusual" settings.
(DAR, interlace, ...). Just an idea.
But maybe this is like asking for a navigation assistant ...
in a racing car?

... in case of cropping with DAR - a "preserve AR" option
in the filter GUI would be helpful.

Still there remains the question about interlacing (Your Post #11).
Are standard DVDs progressive although declared as interlaced?
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 14, 2019, 04:27:15 PM
Short addendum:

If I deinterlace the movie (before AR-cropping and compressing)
the result is worse than without deinterlacing.
Although der source stream (orig from DVD) is marked as interlaced.
("What's your name?" "It is Strange" " ..."  :P)
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 14, 2019, 05:21:44 PM
Quote from: gujuCroping my orig video from above to 698x448.

Don't do that. At least don't use values which are not a multiple of 16 (at worst: 8 ).

Quote from: gujuMKV output DAR 4:3.
=> Too small in width.

The logic in the MKV muxer takes the height of the picture and calculates width for the specified DAR. To keep desired pixel aspect ratio instead, you have to multiply your cropped width (698) with 16/15 with makes approx. 745 which you should enter into the field "Force display width".

Quote from: fishYour cropped example demonstrates why a custom setting is needed when the video is not a standard size.

This custom setting for the MKV muxer is present and precedes the DAR selector by years. It is absent in the MP4 muxer.

Quote from: gujuIf I deinterlace the movie (before AR-cropping and compressing) the result is worse than without deinterlacing.

Sure, but if you have already visually confirmed that video is not interlaced, what is the point to try it nevertheless?

Quote from: gujuBut maybe this is like asking for a navigation assistant ...
in a racing car?

Rather electric windows in a bicycle. Look, Avidemux is what you make out of it. The source code is open, quality contributions are welcome. Make your hands dirty, reshape things.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 14, 2019, 06:43:05 PM
Quote from: eumagga0x2a on January 14, 2019, 05:21:44 PM

Quote from: gujuIf I deinterlace the movie (before AR-cropping and compressing) the result is worse than without deinterlacing.

Sure, but if you have already visually confirmed that video is not interlaced, what is the point to try it nevertheless?

The point is ...
as I stated before in this thread, that the movie is marked as interlaced.
And so "someone" will pay attention to that (Player, decoder, ...)
and deinterlace it (Actually it looks like MPC-HC produces a worse image
playing the original (!) stream than the non-deinterlaced movie produced by Avidemux).
And we're talking about a standard commercial DVD (???).

"It looks like" - I'm not sure.
And I find it quite time observing to manually find out for every movie
one handles if interlace is set correctly.
That's the reason why I asked about motion vectors etc.

Quote from: eumagga0x2a on January 14, 2019, 05:21:44 PM

Quote from: gujuBut maybe this is like asking for a navigation assistant ...
in a racing car?

Rather electric windows in a bicycle. Look, Avidemux is what you make out of it. The source code is open, quality contributions are welcome. Make your hands dirty, reshape things.

... Thankyou for your invitation.  ;)
I hope you don't take it as a pretext, if I tell you,
that I take Avidemux as a tool to "make my hands dirty" on my things.
It's not my thing to work on the tool itself.
My contribution is to give a feedback/ hopefully unobtrusive hints
of a newbie.

So I disagree with your metaphor.
A bicycle without electric windows does no harm.
In contrast to a racing car without knowing how to deal with it.
It might well be possible that the majority of the Avidemux
produces films are bad in quality because most of the users
don't know about the pitfalls, two of them we are discussing
(DAR, interlacing).
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on January 15, 2019, 12:26:58 AM
Don't rely on interlace flag or absence thereof. Trust your eyes. It takes a few seconds with Avidemux to tell whether a video is interlaced or not, not more.

Quote from: gujuI hope you don't take it as a pretext, if I tell you,
that I take Avidemux as a tool to "make my hands dirty" on my things.
It's not my thing to work on the tool itself.
My contribution is to give a feedback/ hopefully unobtrusive hints
of a newbie.

This was exactly my attitude back then, two and a half years ago.

QuoteIt might well be possible that the majority of the Avidemux
produces films are bad in quality because most of the users
don't know about the pitfalls, two of them we are discussing
(DAR, interlacing).

But now you are able to handle the tool better, aren't you? If you have a vision of helping others to get the best out of Avidemux, make it happen.
Title: Re: Display Aspect Ratio - If and how to set
Post by: guju on January 15, 2019, 10:36:45 AM
Again: Thank you  :)

Well, knowbody knows what will be in the future  ;)
If I ever would contribute in Avidemux dev, I would pave it with checks/ warnings/ hints
(in the "standard user mode") if there are some suspicious settings,
or something could be made better etc.

You are right, I (!) can handle the tool better now/ know something more
(thanks to the contributers of this thread).
But this is only "by chance".
I assume that there is so much more I still do bad, because I don't know about*.
And I think most of the Avidemux' users don't take as much time as I do,
because they just want to have results, quickly.

* Small example I just stumbled about (by chance!).
It makes a great difference in quality which kind of renderer one chooses in MPC-HC.
And depending on that choice, the renderer uses Intel's graphic driver's settings or not
(which - BY DEFAULT - do smoothing, blocking, color changing. They call it "enhancement").
I just discovered that by chance, with the thorough inspection concerning this thread.
I changed the HW about a year ago, not consciously noticing since then.
This-is-mad.
Title: Re: Display Aspect Ratio - If and how to set
Post by: fish on January 15, 2019, 03:04:10 PM
If you tell us what you hope to achieve it might be easier to trying to help. One thing you should give up on is trying to make the quality of the video 'better' than the original. You can alter the look to suit different playback methods but the original will always be the best quality.
What age is the DVD? Do you have a specific reason for cropping the video from the standard height/width ratio? 
Title: Re: Display Aspect Ratio - If and how to set
Post by: franz.b on April 23, 2020, 08:45:08 PM
Hi everybody,
I found and read this very interesting discussion, I'm also fighting with the correct proportions of the video files.
My procedure is as follows: I start from a movie (typically from DVDs, but not only) with the black bands above and below and I delete them with a crop (to save some space occupied in storing the file, to respond to the previous question to another user), recode without resizing and apply the correct DAR in the mp4 container.
The problem is that the available DARs are not enough (the black bands have the most varied thicknesses ...) and there is no possibility to insert an arbitrary one neither with the mp4 container nor with mkv.
I partially remedied with Yamb but it sets the PAR and to use it I must also install all GPAC because otherwise the mp4box alone does not see many audio streams ... so I would prefer to find another small and simple tool to change the DAR ...
Do you have any advice for me?
Thank you
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on April 23, 2020, 10:39:58 PM
Quote from: franz.b on April 23, 2020, 08:45:08 PM
there is no possibility to insert an arbitrary one neither with the mp4 container nor with mkv.

You can use an arbitrary DAR with MKV if you do a bit of maths to calculate the required display width from height of the video in pixels for the desired aspect ratio.

If you insist on cutting away the black bars, I would deinterlace first, outputting frame for field (frame rate doubling) if the content is interlaced, then scale to get square pixels and only then crop the black bars while keeping width and height a multiple of 16 (this is very important for compressibility).
Title: Re: Display Aspect Ratio - If and how to set
Post by: franz.b on April 25, 2020, 10:23:21 PM
I thank you for the answer!
But I don't understand a passage, or how to resize to get square pixels.
For example, a movie typically has a resolution of 720x576 with a 16: 9 DAR and the black bands are 32 pixels thick.
I proceed as follows: after the crop a 720x512 remains without applying any AR Avidemux gives me back a movie with this resolution and square pixels and with a ratio 720/512 = 1.4 that has deformed images. By applying an appropriate DAR I get the correct image.
Otherwise I do a resize to 720x464 and I get square pixels and an undeformed image (if not minimally to have divisibility by 16). But in this case I no longer need to apply a DAR ...

The Avidemux interface shows me the images without applying DAR or PAR, I crop it on square pixels. Where am I wrong in my reasoning?
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on April 26, 2020, 12:02:53 AM
In your example the original movie has a 2:1 aspect ratio padded with black bars to fill the standard 16:9 widescreen picture. In this case you should be able to do without scaling, i.e. crop the black bars to get 720x512 and save the re-encoded video using the MP4 muxer with forced display aspect ratio of 18:9 (don't forget about putting the deinterlacer first in case the source is interlaced!).

Else you can scale the source to 1024x576 to get square pixels, then crop the black bars and save without forcing aspect ratio.
Title: Re: Display Aspect Ratio - If and how to set
Post by: franz.b on April 26, 2020, 10:24:47 AM
Thank you very much!
this example was deliberately simple, but if the final DAR was not exactly 2 or default values then can I just use the mkv muxer? or the resize.
for resize which method gives the best quality? enlarge the horizontal side or reduce the vertical one?
Thanks in advance
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on April 26, 2020, 11:05:06 AM
Quote from: franz.b on April 26, 2020, 10:24:47 AM
this example was deliberately simple, but if the final DAR was not exactly 2 or default values then can I just use the mkv muxer?

Yes, you can.

Quoteor the resize.

This would be failsafe and avoid all compatibility issues from poor Matroska support in standalone devices.

Quotefor resize which method gives the best quality? enlarge the horizontal side or reduce the vertical one?

Always stretch, never compress.
Title: Re: Display Aspect Ratio - If and how to set
Post by: franz.b on April 27, 2020, 12:20:25 PM
Quote from: eumagga0x2a on April 26, 2020, 11:05:06 AM
Quote from: franz.b on April 26, 2020, 10:24:47 AM

or the resize.

This would be failsafe and avoid all compatibility issues from poor Matroska support in standalone devices.
Thanks!
Is there a significant difference in the final quality?
Title: Re: Display Aspect Ratio - If and how to set
Post by: eumagga0x2a on April 27, 2020, 07:15:31 PM
It will cost some quality, of course. Please try it at a short excerpt from the original video to find out how much.