Hi guys, hopefully, this is the right forum for this question!
I use the program PS3 Media Server to stream my mkvs across to my TV. In said program, there's a few transcoding enguines you can use: MEncoder and AVISynth/MEncoder. I normally choose AVISynth/MEncoder over MEncoder due to my having had a few issues with the MEncoder engine. Most of my mkvs play without a hitch, however, the occasional one will have black bars to the sides. The problem is, these videos are 16:9 ratio, they're not suppose to have black bars! This results in the video looking all squashed and ugly. The interesting thing is, when I play these videos using MEncoder as the engine, the aspect is correct. This makes me think AVISynth is the culprit here.
When I load up these troublemaker mkvs in MediaInfo, I notice something odd: these videos have extra aspect ratio information! An example would be:
Width : 704 pixels
Height : 480 pixels
Display aspect ratio : 16:9
Original display aspect ratio : 1.467
The 16:9 mkvs that play properly when using AVISynth/MEncoder only make mention of one aspect ratio. This makes me think AVISynth is looking at "Original display aspect ratio" to get it's aspect ratio, while MEncoder is looking at "Display aspect ratio". This would explain why MEncoder gets it right, while AVISynth/MEncoder gets it wrong. Interestingly enough, the same mkvs that AVISynth has issues with, also show up as 4:3 thumbnails in Windows, instead of 16:9 like the non-troublesome ones. Obviously, Windows is being tripped-up in the same way AVISynth is.
Ideally, I would like the change the way AVISynth gets it's aspect ratio. In the troublesome mkvs, the "Display aspect ratio" field is normally correct, so if AVISynth would use this information instead, the problem would be solved. But failing that, how would I remove the extra, incorrect aspect ratio? I've tried using MKVtoolnix, both the "aspect ratio" option, as well as entering in the correct display width/height (which should be 704x480, but came up as 853x480 when I loaded up the video in MKVToolnix), both these options don't solve the problem.
+ Reply to Thread
Results 1 to 27 of 27
I do? What would be causing my aspect ratio issue then? And what would you suggest to solve it?
Your video is 704x480, or a ratio of about 1.47:1. That's what AviSynth 'sees' and that's what it encodes. If you want it to be resized by the player you have to set a DAR/PAR for the container or the video. Either that or have AviSynth resize it to some 1.78:1 ratio as Baldrick suggested earlier. I don't make MKVs so someone else can tell you how to set a DAR/PAR.
Ah ha! The video size would be the problem! 704x480 isn't wide enough! That's probably what's messing AVISynth up! How would I know what the correct size would be? I check an online database, and 704x480 is the known resolution for this video, but it's clearly not correct. When I load the video up in MKVToolnix, it defaults to 853x480, which looks to be the correct aspect ratio. That would mean it was correct to begin with! Yet both Windows and AVISynth are reading the resolution as 704x480! I tried remuxing it anyway, but Windows still thinks the new video is 704x480.
Last edited by billyboy12; 3rd May 2011 at 07:23.
The video is 704x480. You even showed us the MediaInfo information to confirm that. It'll always be that resolution unless you change the resolution when reencoding. It's a flag you set that can tell a player to resize it to 854x480 or whatever. Again, it's nothing to do with AviSynth.
If you want a 1.78:1 ratio video, resize it to 624x352 or 704x396 (Baldrick's suggestion) or even 854x480.
Your MKVs have been encoded anamorphically.
Can you see the Avisynth scripts created for these files?
I suspect the black bars aren't in the AVS file. If not, your TV may have a control to override the aspect ratio so it displays this correctly.
Otherwise, in Avisynth, resize it to the correct ratio.
mkvmerge, but nothing happens! The new video still has the same size as before! What am I doing wrong?
MEncoder is doing, but Windows and AviSynth are not doing. Unless PS3 Media Server creates scripts, not I can't see any AviSynth scripts.
Ah, I get it, the video itself is 704x480, which would normally be 4:3, but is normally stretched out to 16:9 to make the correct image. Windows and AviSynth are both telling it like it is, while MEncoder is applying the correct aspect ratio. Is there a way to solve this issue without re-encoding the video? I still think it's rather interesting that all the videos that give me trouble have two aspect ratios contained within them, while the ones that work, only have one. Is it possible to remove this extra aspect ratio or something?
To "remove" that you'd have to reencode to the widescreen ratio.
But also, usually you can set the aspect ratio on the TV or media player, overriding the default, without reencoding.
Yeah, I can remove the black bars and stretch the video out to the correct aspect by changing the PS3's screen settings, but it would be nice if there were a neater solution than this.
Well, I know that PS3 Media Server had the ability to insert AVISynth code, would there be any that someone could suggest that might solve this issue? Like, it resizes the video to the correct aspect? Obviously, the tricky part would be in getting it to leave videos that are suppose to be 4:3 alone!
1) demux (with mkvdemuxgui)
2) mux to mp4 and set SAR (and DAR if necessary) (mp4box).
3) optionally remux the mp4 to mkv (MKVmergegui).
Display Aspect Ratio = Storage Aspect Ratio × Pixel Aspect Ratio
DAR = SAR × PAR
You can't change the PAR without reencoding, but you can change the others by remuxing
You can change the DAR with MKVmergegui, but some players pick up the "original aspect ratio" and use that.
mp4box lets you change the SAR as well.
Last edited by AlanHK; 31st Oct 2014 at 11:13.
@AlanHK, you have that wrong: you can't change the SAR without re-encoding. mp4box let's you adjust PAR to arrive at a revise/corrected DAR. see http://tools.rodrigopolo.com/mp4box_aspect_fix/, and notice the "PAR" in the code.
This is another misconception that really screws many people up: People like to use the SAR shorthand in AR calculation, without realizing that "there is no such thing as a stored aspect ratio". In no codec, nor container, is there a field known as SAR. Why? Because the apps & devices deal with the actual resolutions themselves directly, never relying on "SAR" for anything. The only place where SAR reliance seems to have traction is in peoples' minds.
I think it would make discussions much clearer around here if people stopped using that stupid formula "DAR = SAR * PAR". I've been guilty of using it in a pinch also, but it's lazy! The real formula ought to be "DAR = (horizontal rez / vertical rez) * PAR" or simply "DAR = Hrez/Vrez*PAR". Basically the same thing, but it gets the point across that there is never a field called SAR that can be adjusted in any app or format. Keeps one from lazy thinking. And lazy thinking leads to faulty thinking.
And it's always been clear that one cannot resize without re-encoding (barring a few "runtime cropping method" exceptions).
What I think the OP had problem with was the lack of understanding that AVISynth has no notion of AR. It just deals with pixels & their sizes & placements. Whatever it's frameserving to is the app that needs to understand this and account for it as necessary, usually by expecting AVISynth to be serving 1:1 PAR material and adjusting for encoding or display needs.
Just to confuse everyone more There are dozens of different acronyms for the same thing
SAR is officially the Sample Aspect Ratio in MPEG4-AVC / h.264 terminology according to the specs, not the Storage Aspect Ratio. It used to be known as the "PAR" in MPEG2 days. "PAR" actually doesn't exist in AVC specs, only SAR.
And it is an AVC VUI parameter bitstream flag as sar_width, sar_height, which you can change without re-encoding using various tools. e.g. this ffmpeg patched build, but there are others
Storage Aspect Ratio in the old terminology can be though as the w:h of the frame dimensions; it's also sometimes called the Frame Aspect Ratio or FAR. This is the one you cannot change - the "physically" encoded frame dimensions without re-encoding
So if you are using MPEG4-AVC terminology, mp4box mislabells it the "PAR", but it's actually the "SAR", Sample Aspect Ratio that is being altered.
And this is a gravedig. Even though it's Halloween, Alan knows better than to bump old threads Maybe the all the protesting in HK is getting to him
Happy Halloween, from my avatar & me!
They seem designed to obfuscate the whole issue.
My specific problem, and what prompted this "grave digging":
(I don't consider this a violation of etiquette since the original question wasn't solved satisfactorily, and I wanted to correct a statement I had made myself, no matter how long ago -- and appears I'm not done self-correcting.)
I had an MKV 640x480 pixels
It should have had the same DAR (640:480= 4:3) but when encoded had been set 16:9.
I thought I'd fixed it by remuxing with MKVmerge and setting a new DAR, and it did play correctly on my old TV and in VLC.
But on my new media player it was playing at 16:9.
Media info showed :
Display aspect ratio : 4:3
Original display aspect ratio : 16:9
And my stupid player apparently was using the "original" ratio.
Similar files encoded correctly from the start had no "Original display aspect ratio" setting at all.
So, the command line I used was
mp4box -add 102.h264#video:par=1:1 -add 102.aac#audio 102.mp4
Muxed that in turn to MKV and that gave me a file that played with the correct 4:3 DAR and no "Original display aspect ratio" shown.
So yeah, I did change the PAR.
I was thinking that the PAR was the actual encoded pixels, since that's what it sounded like, but evidently that's the SAR.
Wrong explanation, right solution.
Last edited by AlanHK; 31st Oct 2014 at 20:23.
I would have been better to open a new thread on the discussion referencing or quoting the original post to keep it cleaner.I think,therefore i am a hamster.
I was expanding on my own earlier response.
This thread came up when I was Googling for a solution, so likely anyone else having the same problem will get here too. Putting the answer in a different thread doesn't help them find it.
But if it bothers you, go ahead and split it,
I guess there's differing opinions regarding posting in old threads, but in my opinion full credit should go to AlanHK for returning after all this time to admit "maybe I wasn't 100% correct". Not too many posters will even admit the slightest possibility they were wrong yesterday.
I don't see how starting a new thread would be "cleaner". To my way of thinking it'd be the opposite to a certain extent, if Google leads people to an old thread containing incorrect information. Anyway.....
Any aspect ratio is usually written to the video stream and at the container level, hence MediaInfo sometimes displaying "original aspect ratio" (video stream) and "display aspect ratio" (container). Mostly they're the same so MediaInfo will only show a "display aspect ratio". At least that's how I think it works.
In my experience most players follow the container aspect ratio first and the stream aspect ratio second. If memory serves me correctly one of the Bluray players here only obeys the container aspect ratio and ignores the stream aspect ratio completely (MKVs) even when there is no container aspect ratio as such. Some players might do things differently, or even use different rules for different containers (which maybe AlanHK has experienced) but if I'm changing the display aspect ratio, I generally change both so there's no issues. Of course if the "original aspect ratio" is correct and the container aspect ratio is wrong, simply remuxing while setting the correct container aspect ratio should fix the problem.
I'm not sure if there's another way to do it, but this version of ffmpeg will change the h264 stream aspect ratio amongst other things (it's command line).
If memory serves me correctly it doesn't set a container aspect ratio when muxing, so it's output needs to be remuxed in order to set one, but the end result should be matching container and video stream aspect ratios.
There's also the MPEG4 Modifier for ASP video (xvid, divx etc).
I can weigh in somewhat here. I was told before that aspect ratio information can be held not only in the container, but in the video stream inside the container as well. I tested this myself once by remuxing a video with a 4:3 ratio and telling mkvtoolnixgui to change it to 16:9. MPC-HC played it with the new aspect ratio, but my PS3 did not. In order to be sure your video plays correctly on all devices, the aspect ratio information should be set not only in the container but also in the video stream, which will require re-encoding.
AviSynth will lose the aspect ratio information. If you rip an NTSC DVD and process it with AviSynth, it'll come out 720x480. There are no DVDs that actually display 720x480 however, it's either 4:3 (480*4/3=640, so 640x480) or 16:9 (480*16/9=~854, so 854x480). Unless something else is there to change it... MeGUI will let you set the aspect ratio to whatever you want, even when using AviSynth.
You can change the aspect ratio of an existing h264 video stream without re-encoding. The version of ffmpeg I linked to in my previous post (a while ago now) will do it, although it's a command line tool. http://forum.doom9.org/showthread.php?t=152419
After using it to set a new video stream aspect ratio, you might have to remux with a tool such as MKVToolNixGUI to set the container aspect ratio correctly too.
I "think" Mpeg4 Modifier changes the video stream aspect ratio for mpeg4 (ASP) video in AVIs, given AVI doesn't officially support anamorphic video.