I have an AVI file ripped from a miniDV tape (PAL).
The aspect ratio of the file changes from 4:3 to 16:9 every now and then.
MPC-HC plays such a file correctly, but AviSynth assigns DAR from the first shot to the entire file.
Can Avisynth even read such files correctly and "transfer" such a frame flag to ffmpeg (with -avisynth_flags all)?
I use ffms2 to open the file (if that matters).
+ Reply to Thread
Results 1 to 13 of 13
-
Last edited by rgr; 18th Dec 2024 at 12:24.
-
Avisynth should be able to parse that information with frame properties if you use a source filter that reads it (e.g. ffms2, as you are using) - you can check with propshow() and _SARDen, _SARNum are read. Check to see if it switches on your video
But ffmpeg avs demuxer does not pass that information. Currently it passes
Code:_FieldBased _ChromaLocation _Primaries _Transfer _Matrix _ColorRange
-
ffms2 doesn't show correct _SarNum/Den (probably older version, but new ones have problems with file names). LWLibavVideoSource does.
But ffmpeg with "-avisynth_flags all" can read DAR/PAR of avs file?
Edit: I also did a test without AviSynth -- ffmpeg also couldn't handle the variable PAR with an avi file as a source. -
Yes, tehre were a few versions of ffms2 that had unicode support broken , not sure what the current status is
But ffmpeg with "-avisynth_flags all" can read DAR/PAR of avs file?
default
Code:Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(bottom first), 720x576, 25 fps, 25 tbr, 25 tbn
Code:Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(bottom first), 720x576, SAR 16:15 DAR 4:3, 25 fps, 25 tbr, 25 tbn
Can you verify if the switching AR is registered with lsmash , as least with the propshow()? -
On every AVI file.
LWLibav works.Last edited by rgr; 18th Dec 2024 at 12:19.
-
Any ideas on how to properly convert such a file, preferably automatically?
I'm thinking about using CropResize -- I need to check if it can scale using frame PAR.
Or changing the resolution of the DAR 16:9 fragments to 960x576 and adding black bars to the DAR 4:3 fragments. And saving with PAR 16:15.
I'll have to think about it. -
The best way is to separate the scenes, then add black pillars to all 4:3 scenes before they can be added back to their locations and joined with the rest of 16:9 scenes and processed into one single file.
At least that's what I would do if I have such tape. Use vdub to strip DV out, add black borders using the add border feature to the 4:3 frame one scene at a time and output into lossless AVI for each 4:3 segment, Then do the same thing for all 16:9 scenes, and rename all the output segments in a numerical order of their placement in the original footage, Use append feature in vdub to add all segments to the timeline and output as a single file and output in the same lossless AVI format, the entire process should be lossless.
From this large file you can de-interlace, resize to 1920x1080 and encode to your desired format. -
I wonder if something like this has a chance of working. I did something like that, but it was changing one command depending on the height. From the Avisynth syntax I see that the chances are slim.
_prop("_SARNum") == 64 ? Eval("resize(960,576)" ? Eval("addBorders(left=120,right=120,color=0)")
Invented syntax -- that's how I imagine it. -
Here is a rough example using PropGetInt to parse the _SARNum, and it returns one version (b1) if SarNum is 64, otherwise (a1) . There is no error catching logic , and it's really rough
In this example, the "c" test clip is dark grey 4:3 + light grey 16:9 + dark grey 4:3 all at 720x576
Based on their SarNum value, those sections are replaced with a square pixel equivalent. Change the values as you see fit
Code:blankclip(width=720,height=576,length=10,pixel_type="YV12",colors=[64,128,128]).killaudio() propSet("_SARNum",16) propSet("_SARDen",15) #4:3 a=last blankclip(width=720,height=576,length=10,pixel_type="YV12", colors=[192,128,128]).killaudio() propSet("_SARNum",64) propSet("_SARDen",45) #16:9 b=last a1=a.crop(8,0,-8,0).spline36resize(768,576).addborders(128,0,128,0).propSet("_SARNum",1).propSet("_SARDen",1) b1=b.crop(8,0,-8,0).spline36resize(1024,576).propSet("_SARNum",1).propSet("_SARDen",1) #testclip c=a+b+a scriptclip(c.spline36resize(1024,576), """propGetInt(c,"_SARNum") == 64? b1 : a1""")
-
did not know that dv avi can have alternating aspect ratio, would be interesting if ffms2 or BestSource read those, in vapoursynth perhaps more likely (BestSource likely?):
Code:from vapoursynth import core from functools import partial import havsfunc #clip = core.ffms2.Source(r"E:\PAL_DV.avi") clip = core.bs.VideoSource(r"E:\PAL_DV.avi") clip = clip.std.SetFrameProps(_Matrix=5, _Primaries=5, _Transfer=5) clip = clip.std.CropAbs(width=704, height=576, top=0, left=8) # deinterlace or filters here clip = havsfunc.QTGMC(clip, Preset='slow', TFF=False) clip = clip.std.RemoveFrameProps(['_DurationNum', '_DurationDen']) def compare_ar(n, f, clip): if int(f.props['_SARNum']) == 64: clip = clip.resize.Spline36(width=1024, height=576) else: clip = clip.resize.Spline36(width=768, height=576) clip = clip.std.AddBorders(left=128, right=128, color=(16,128,128)) return clip placeholder = clip.std.BlankClip(width=1024, height=576) clip = core.std.FrameEval(placeholder, partial(compare_ar, clip=clip), prop_src=clip) clip = clip.std.SetFrameProps(_SARDen=1, _SARNum=1) clip.set_output()
Last edited by _Al_; 18th Dec 2024 at 20:59.
-
Thanks for the idea, I modified it a bit to suit my needs. I also replaced the filter with ConditionalFilter (according to the description it is more stable with multiple threads).
Code:name="Tape 1 (01.09.2007 11.52).avi" #4:3 a=LWlibavvideosource(name).QTGMC(preset="slow",TR2=3)#.propshow a=AudioDub(a,LWlibavaudiosource(name)) #16:9 b=LWlibavvideosource(name).QTGMC(preset="slow",TR2=3)#.propshow a1=a.addborders(120,0,120,0) b1=b.spline36resize(960,576).propSet("_SARNum",16).propSet("_SARDen",15) #scriptclip(b.spline36resize(960,576), """propGetInt(a,"_SARNum") == 16 ? a1 : b1""") ConditionalFilter(a, a1, b1, """propGetInt(a,"_SARNum")""", "==", "16")
Edit:
This is a problem with LWLibavAudioSource with uncompressed audio, I just remembered.
You need to use:
Code:a=AudioDub(a,ffms2(name, atrack=-1))
Last edited by rgr; 19th Dec 2024 at 07:16.
-
Similar Threads
-
Ffmpeg piped as source to avisynth
By Budman1 in forum Video ConversionReplies: 14Last Post: 22nd Jul 2024, 11:55 -
Changing PAR (pixel aspect ratio) in mov file
By rgr in forum Video ConversionReplies: 6Last Post: 21st Apr 2024, 02:40 -
Deinterlacing Source in Avisynth
By bit.whisperer in forum Video ConversionReplies: 16Last Post: 25th Jan 2024, 19:34 -
how to join the video from multiple source with avisynth?
By adi111 in forum EditingReplies: 3Last Post: 30th Dec 2022, 09:28 -
avisynth: how to trim alwais the last 3 seconds of the source?
By marcorocchini in forum Newbie / General discussionsReplies: 4Last Post: 16th Jun 2020, 17:44