Avidemux Forum

Avidemux => Stable branch (2.5) discussion => Topic started by: estragon1 on August 26, 2012, 02:27:10 PM

Title: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 02:27:10 PM
Newbie here, again (http://www.avidemux.org/smf/index.php?topic=10835.0). As I said in my previous message, I use avidemux (the x64 2.6 betas now, on Win7), in order to edit quickly my TV recordings from a Dreambox 7020.

Recordings are reported in Avidemux by File, Information as:
image size 544x576, aspect ratio unknown (24:17) or
image size 704x576, aspect ratio unknown (16:11)

Both look quite strange, almost square the first, on Avidemux, while they look fine (4:3, 16:9) on VLC.

If I use Video Output: Copy, Audio Output: Copy, Output Format: AVI Muxer, I get the clip I want, having edited out commercials, etc. Such a video plays in nice proportions (4:3, or 16:9) with VLC, and if I upload it on Youtube, it shows up fine.

But if I want to reencode my clips, to make them smaller in filesize, in x264/mp4, the output clip I get always looks ugly (exactly as the original inside Avidemux) in VLC, not in 4:3 or 16:9 as expected (and the same happens if I upload such a clip in Youtube). Now, if I go to VLC and change under Video, the Aspect Ratio, from Default to 4:3 or 16:9, the one I know that is right, the video will play fine.

It seems like reencoding doesn't "save" that Aspect Ratio information somewhere --or that I don't know how to force it to do so. I don't want to change the actual size of the video.

What am I missing there? I've read about SAR and PAR and DAR but it has not really helped. I would like to save my compressed AVI or MP4 files, and be sure that they will play in their expected sizes, no matter if it is on a software or hardware media player, or if I upload them on Youtube.

Excuse me if this topic has been covered here comprehensively before, yet I haven't found it.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 26, 2012, 02:44:48 PM
If this about SD TV in 16:9 showing up as 4:3 try resize to 1024 x 576. Avidemux works with 1:1 pixels.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 26, 2012, 02:55:38 PM
You can also play with Force display width (http://www.avidemux.org/smf/index.php?topic=10232.msg55041#msg55041).
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 03:12:13 PM
If this about SD TV in 16:9 showing up as 4:3 try resize to 1024 x 576. Avidemux works with 1:1 pixels.

Thank you but I don't understand your suggestion. I tried to describe the problem as clearly as possible, I'll rephrase it shortly below:

A. Source File information from Avidemux: image size 544x576, aspect ratio unknown (24:17)
1. Original ts file shows up like a square in avidemux (file info says 544x576). But it shows fine (4:3) in VLC, or Youtube
2. If I edit without reencoding (copy audio /copy video /avi muxer), avi fle still square in avidemux, but still fine (4:3) in VLC, or Youtube
2a. If I edit with reencoding (for example, mpeg4 AVC video, AAC audio /MP4 muxer), mp4 fle is "square" everwhere. I can correct the aspect ratio and set it manually to 4:3 in VLC to watch it properly, but on Youtube it stays "square".

Same for:
B. Source File information from Avidemux: image size 704x576, aspect ratio unknown (16:11)
1. Original ts file shows up inm odd proportions in avidemux (file info says 704x576). But it shows fine (16:9) in VLC, or Youtube
2. If I edit without reencoding (copy audio /copy video /avi muxer), avi fle still square in avidemux, but still fine (16:9) in VLC, or Youtube
2a. If I edit with reencoding (for example, mpeg4 AVC video, AAC audio /MP4 muxer), mp4 fle is "odd" everwhere. I can correct the aspect ratio and set it manually to 16:9 in VLC to watch it properly, but on Youtube it stays "odd".
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 03:31:00 PM
You can also play with Force display width (http://www.avidemux.org/smf/index.php?topic=10232.msg55041#msg55041).

Where is this? Only options for Configure, under MP4 Muxer Output Format is a Muxing Format (MP4/PSP options) dropbox and a Use Alternate MP3 Tags check box.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 26, 2012, 04:27:02 PM
You can also play with Force display width (http://www.avidemux.org/smf/index.php?topic=10232.msg55041#msg55041).

Where is this? Only options for Configure, under MP4 Muxer Output Format is a Muxing Format (MP4/PSP options) dropbox and a Use Alternate MP3 Tags check box.
you can find this in 2.6 is better suited to handle mpeg-ts
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 26, 2012, 04:39:49 PM
TV program 576i is either [ ] 4:3 or [   ] 16:9 (wide screen). If you re-encode 576i 16:9 and you resize in Video filter with these settings  1024 x 576 The video now will show 16:9 on vlc or or on flatscreen tv's. Can't explain it other way.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: zakk on August 26, 2012, 04:46:09 PM
Did you try to change the "Pixel Aspect Ratio" when encoding ? (see video options)
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 07:21:27 PM
What I only found is under Video | Filters | Transform | swsResize.

There I suppose I have to unlock the Aspect Ratio and Resize dimensions from 704x576 to 1024x576, or from 544x576 to 768x576. This gives the 16:9 / 4:3 expected result. Which of the Resize Methods should I prefer?

Is this what I should do?


Title: Re: Set Aspect Ratio info inside the encoded video
Post by: zakk on August 26, 2012, 07:44:45 PM
it's not in the filters but in AVC configuration
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 07:53:12 PM
it's not in the filters but in AVC configuration

I have Avidemux 2.6.0 (r8142) Windows 7 x64 installed. Could you tell me where I can find the "AVC configuration"?

Oh, you mean the "Configure" button under Video Output Mpeg4 AVC (x264). But I can't find "Pixel Aspect Ratio" in any of the tabs there…  :(
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: zakk on August 26, 2012, 08:33:51 PM
"Output 1" tab. Try "as input".
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 26, 2012, 10:33:14 PM
Right, I had never gone past Advanced tabs, which were already far right!

I tried As Input to no avail. Then I tried Custom 16:9, 4:3, again no success, I tried the predefined ones PAL 4:3, NTSC 16:9, the same unsuccessful result. By that I mean that with default video aspect in VLC I see the 1:1 copy of the original. If I manually go to VLC, I can "correct" it to 4:3, 16:9 accordingly, but this information seems like it;s not store in the file. So if I upload it to youtube, it still comes out as a "1:1 copy" of the original, without the proper aspect ratio information. :(
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: zakk on August 26, 2012, 11:10:49 PM
I know it works with Avidemux 2.5, because I used it a lot.
Keep 2.6 for h.264 source only.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 28, 2012, 01:08:07 PM
Unfortunately, I have other reasons that I am using 2.6; they are discussed in the link of my initial post in this thread.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 28, 2012, 02:51:25 PM
I know it works with Avidemux 2.5, because I used it a lot.
I tried the latest 2.5.6. It didn't work with it either  :(
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 28, 2012, 03:00:55 PM
Sorry for the late reply.
in attachments 3 Tinypy Project resizes 576i StandardDefinition TV, so 16:9 is shown as 16:9 on flatscreens and so on.
- sofware only
- hardware opengl and vdpau (nvidia card)
load video and from Main menu -> File -> Tinypy Project - Run  Project
If your videocard supports
nvidia vdpau point to this one: SDto16x9VDPAU.py
opengl point to this one: SDto16x9openglResize.py
videocard support none of the above point to this one: SDto16x9VDPAU.py

original recording mpeg-ts 576i 16:9 found here orignal16by9.ts (7 MB)
saved to mkv without resizing: orignal16by9noresize.mkv (5 MB)
resized saved to mkv: orignal16by9resized.mkv (5 MB)

Should work with other encoders to. you only need to apply the video resize filter.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 28, 2012, 03:07:30 PM
If you use this filter on a regular basis you could do the same thing as done here: Custom Menu and Saved projects (http://www.avidemux.org/smf/index.php?topic=10948.0)
dump the project in folder Screen.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 29, 2012, 11:12:51 AM
Thank you, Jan (thank you, zakk, again, too).

It looks like most of the broadcasts I record from my Dreambox channels are in 24:17 or 16:11. So will these scripts work, or could you modify them? (as I said I'm forced to use the 2.6 nightlies).

Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 29, 2012, 01:09:35 PM
Projects are from 2.6. Download the original recording mpeg-ts 576i 16:9 sample and have look at it and see if it is similar.
These give me  big headache:
Pixel aspect ratio (http://en.wikipedia.org/wiki/Pixel_aspect_ratio)
Advanced Aspect Ratios - PAR, DAR and SAR (http://www.animemusicvideos.org/guides/avtech3/theory-videoaspectratios.html)
By any chance would these be freesat TV channels?
Or you could post a sample recording:how to Cut TS sample (http://www.avidemux.org/admWiki/doku.php?id=tutorial:cut_ts_sample)
and upload this to rapidshare (non pro should be free to use) or similar service and provide a link to it.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 29, 2012, 03:23:06 PM
Thank you for your consideration. I've been through a lot of channels on the bucket bouquet I pay for, and watch or sometimes record, and so far I've got the following aspect ratio collection: 12:11, 16:11, 16:15, 24:17, 64:45.

Here you are your samples (deleted link). Tell me when you've got them, so I remove them.
 
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 29, 2012, 04:57:49 PM
Thanks for the 19 samples (250 MB), will have a look at these and let you know.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 29, 2012, 05:10:17 PM
The clips you did upload are all 4:3 or 16:9.
Best you use a tool that gives you the correct information like MediaInfo  (http://mediainfo.sourceforge.net/en)
Il check the project later.
12:11 = 704*576 (4:3)
16:11 = 704*576 (16:9)
16:15 = 720*576 (4:3)
24:17 = 544*576 (4:3)
64:45 = 720*576 (16:9)






Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 29, 2012, 06:29:05 PM
for each kind I did a test run, check if output is OK. Hard to judge, have no reference to what it should be? 68 MB download is now removed.
Output is targeted to PAL:
 PAL  4:3 768x576 and 16:9 1024x576
if NTSC would be required, change values in filter accordingly:
NTSC 4:3 640x480 and 16:9  854x480

not for HD TV! only SD TV 4x3 filter for 4:3 channels, 16x9 for 16:9 channels
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 29, 2012, 11:47:24 PM
Thank you, I'll check tomorrow. I've downloaded the rapidshare 65 MB file.

I had the original .ts files loaded in Avidemux 2.5.6, went to Pixel Aspect Ratio, under Output 1, MPEG-4 AVC Configuration, and set it "As Input"; it gave me the values I reported in parentheses, so the tool I used was Avidemux itself…
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 30, 2012, 05:51:14 AM
Just have tested those on Samsung UE40B8000, it seems these play fine. Could need some more tweaking on the video section like an increase on the 2PASSBITRATE=2850 in x264?
Avidemux shows the PAR 1:1 if I'm not mistaken. It is all very confusing. Avidemux is not a player, is an editor. Some players don't use the internal file aspect ratios (flatscreen TV's when playing from USB sticks, networks, ....
When using the project files you can use preview, and these should show what you get while playing.
On the toolbar: (https://avidemux.org/smif/proxy.php?request=http%3A%2F%2Fwww.avidemux.org%2FadmWiki%2Flib%2Fexe%2Ffetch.php%3Fmedia%3Dusing%3Atoolbar-qt.png&hash=f26460ab1d69093890ea9b8aa4b24c08)
switch from Input View (https://avidemux.org/smif/proxy.php?request=http%3A%2F%2Fwww.avidemux.org%2FadmWiki%2Flib%2Fexe%2Ffetch.php%3Fmedia%3Dusing%3Ainput-qt.png&hash=24dc73f878f2f19101d190f654584c70) to Output view (https://avidemux.org/smif/proxy.php?request=http%3A%2F%2Fwww.avidemux.org%2FadmWiki%2Flib%2Fexe%2Ffetch.php%3Fmedia%3Dusing%3Aoutput-qt.png&hash=b2f5c358b1b98c2c52b09e59825ffebc)
Keep the project files as sample, you can adjust these when loaded and save as another Tinypy Project.
The header looks something like this:
Quote
#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("/home/jan/Videos/test.mkv")
adm.clearSegments()
adm.addSegment(0, 0, 12441000)
adm.markerA = 0
adm.markerB = 12441000
The bolded part should be left out: references to one video, and you don't want these in general purpose project.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 30, 2012, 08:42:30 PM
But why do you use the MKV container, when it is suggested to use the MP4 container with AVC? Or, is it just the AVI container which should be avoided?
 
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 31, 2012, 05:27:01 AM
But why do you use the MKV container, when it is suggested to use the MP4 container with AVC? Or, is it just the AVI container which should be avoided?
Just have tested those on Samsung UE40B8000, it seems these play fine. Could need some more tweaking on the video section like an increase on the 2PASSBITRATE=2850 in x264?
...
Keep the project files as sample, you can adjust these when loaded and save as another Tinypy Project.
I needed to test on non computer player. You could use any container video codec / audio codec. As long as these work for your players. Avi can give problems with size/and audio tracks, ...
Use what works best for you, test with small sample file and keep tabs of your changes made in filter.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 31, 2012, 10:39:32 AM
Well, my basic need is a personal offline archive, and sharing online at Youtube. So, it's the problem of uploading to Youtube and getting a 1:1 or other odd ratios there, that bugs me most. And I do need compression, thus reencoding, together with best possible quality, when filesizes are big. A lot of time, it suffices to leave it as mpeg.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 31, 2012, 11:00:29 AM
Load video, load provided filter
Change  in Video output to the codec you want, make the changes you want in configure.
Change in Audio Output to the codec you want, make the changes you want in configure.
Select in Output Format the container you want.

Save Project from Main Menu -> Tinypy project -> Save As Project -> Give it a name that makes sense for you.
Edit that file with name that makes sense.py and omit from that file the section referring to loaded file and markers:
Delete this block:
Quote
adm.loadVideo("/home/jan/Videos/test.mkv")
adm.clearSegments()
adm.addSegment(0, 0, 12441000)
adm.markerA = 0
adm.markerB = 12441000

you should now have a workable project for that aspect ratio and wanted container
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 31, 2012, 01:30:58 PM
I was supposed to test and use the py files you kindly prepared for me, with only needing to switch MKV to MP4, wasn't I?

Or should I just do what you said in your previous message and add/edit the lines below, with appropriate changes (to what)?

Code: [Select]
adm.addVideoFilter("glResize", "width=768", "height=576")
adm.setContainer("MP4", "forceDisplayWidth=False", "displayWidth=1024")
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 31, 2012, 01:44:52 PM
Yes:
adm.addVideoFilter("glResize", "width=768", "height=576") would fix [ ] 4:3 tv recordings
adm.addVideoFilter("glResize", "width=1024", "height=576") would fix [   ] 16:9 tv recordings
the fix is intended for players not taking in account the info provided inside the video clip
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on August 31, 2012, 02:55:51 PM
And what about this:
Code: [Select]
adm.setContainer("MP4", "forceDisplayWidth=False", "displayWidth=1024")
as compared to the default:
Code: [Select]
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")
Should I always set displayWidth to 1024?
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on August 31, 2012, 03:28:51 PM
Sorry don't have a clue about those:  test it out with a small sample. I don't use mp4 or mp4v2 and would not know what the effect is for those.
If "forceDisplayWidth=False" then my guess would be it does not matter, only when "forceDisplayWidth=True" it would matter?
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on September 01, 2012, 10:46:02 AM
Unless the .py file has a adm.loadVideo() line, it always crashes (in 2.6.0r8164) :(
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on September 01, 2012, 12:03:41 PM
You need to place these as described here: Custom Menu and Saved projects  (http://www.avidemux.org/smf/index.php?topic=10948.0) then these work without the adm.loadVideo() line.
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: estragon1 on September 01, 2012, 01:21:06 PM
You need to place these as described here: Custom Menu and Saved projects  (http://www.avidemux.org/smf/index.php?topic=10948.0) then these work without the adm.loadVideo() line.
Right! Thank you.

And how do I find out which of swResize, opengl, VDPAUresize I should use? Do I try them all and decide, or does my graphics card support one or the other?

OK, it looks like opengl, VDPAUresize crash Avidemux, while swResize doesn't. So is only the latter compatible with my system, or is there something wrong?

I also remember trying the swResize Filter (http://www.avidemux.org/smf/index.php?topic=10970.msg58752#msg58752), when following zakk's suggestions. Well I tried again and saved the settings as a project to see the differences.

With swResize Filter the differences with your swResize filter are (in bold):

Code: [Select]
adm.addVideoFilter("swscale", "width=768", "height=576", "algo=2", "sourceAR=[b]2[/b]", "targetAR=[b]2[/b]")(yours hane the value of 1)

Your MKV container setting also asks for
Code: [Select]
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1024")as opposed to the MP4 defaults of
Code: [Select]
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")
So, what could the sourceAR, targetAR (Aspect Ratios?) values of 1 or 2 mean?
Title: Re: Set Aspect Ratio info inside the encoded video
Post by: Jan Gruuthuse on September 01, 2012, 03:12:36 PM
In linux you can test their presence by passing one of these command in terminal:
VDPAU (http://en.wikipedia.org/wiki/VDPAU) (only on some nvidia cards supported)
Code: [Select]
vdpauinfo
Quote
display: :0   screen: 0
API version: 1
Information string: NVIDIA VDPAU Driver Shared Library  304.43  Sun Aug 19 20:36:15 PDT 2012
...
OpenGL supported on several kinds of videocards (Intel, AMD, nvidia, ...)
Code: [Select]
glxinfo
Quote
name of display: :0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:
...
With opengl could be display is not functioning correctly, if that is the case change settings in:
Edit -> Preferences -> [Video] -> Video Display: X11, Xvideo or VDPAU and don't use OpenGl for display.
If no VDPAU or OpenGL is present use the swResize.

Need to check for your videocard:
If supported by current OS and if you installed necessary packages/drivers
When resize filter is loaded open it in video filter and in configure, it will show the settings and what these do.
Don't think it is good to mix both methods, if you do, you need to test.