Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
8th September 2017, 04:14 | #1 | Link |
Registered User
Join Date: Aug 2015
Posts: 17
|
TFM IVTC not working on .MPG
Here's my script. The .mpg was copied from a DVD.
video = FFmpegSource2("F:\mymovie.mpg") TFM(video, order = 1) TDecimate(video) video = BicubicResize(video, 640, 480) return video This outputs the video, but it is still telecined and it is still 30i. Why won't it work to detelecine? Thanks. |
8th September 2017, 05:53 | #2 | Link |
Moderator
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
|
Why not write your scripts like normal people?
FFmpegSource2("F:\mymovie.mpg") TFM(order = 1) TDecimate() BicubicResize(640, 480) You should also create a D2V project file using DGIndex and then use MPEG2Source on it, together with the DGDecode.dll. It'll save you creating that MPG before working on your video. |
8th September 2017, 16:42 | #3 | Link | |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 3,156
|
Quote:
Anyway, I would use something like this to IVTC and Resize: Code:
#Index #(I noticed you are using FFMpegSource2 and not FFVideoSource, so I assume you wanna index the audio track as well. To do so, add atrack=-1) FFmpegSource2("F:\mymovie.mpg", atrack=-1) #inverse telecine to 23.976 tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) tdecimate() #Resize Spline64Resize(640, 480) |
|
8th September 2017, 18:14 | #5 | Link | |
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
This would work: video = FFmpegSource2("F:\mymovie.mpg") video = TFM(video, order = 1) video = TDecimate(video) video = BicubicResize(video, 640, 480) return video But when a filter expects a clip as the first argument it's automatically taken from the "last" variable. "Video=" also becomes obsolete and the way manono suggested to do it is all that's required. FFmpegSource2("F:\mymovie.mpg") TFM(order = 1) TDecimate() BicubicResize(640, 480) The special variable "last" passes the output of one filter to the input of the next and while you could add return last to the end of a script it's not necessary as it's automatically assumed. http://avisynth.nl/index.php/Runtime..._and_functions If you must use FFmpegSource2 it's generally a good idea for DVD sources to include rffmode=1 like so: FFmpegSource2("F:\mymovie.mpg", rffmode=1) So ffms2 will obey any repeat field flags. Without it, it ignores them and the output can be unexpected. As manono said though, for mpeg/DVD sources, DGIndex/MPEG2Source is a better option. PS If the source is a 4:3 DVD and you're not cropping, resizing to 656x480 would usually be a better choice. For 4:3 DVDs, only 704 of the width contributes to an exact 4:3 resolution. If you want exactly 4:3, you probably should do this: Crop(8, 0, -8, 0) BicubicResize(640, 480) Last edited by hello_hello; 9th September 2017 at 02:23. |
|
8th September 2017, 19:31 | #6 | Link |
Registered User
Join Date: Aug 2015
Posts: 17
|
Manono - Thanks, that worked. I'm somewhat new to Avisynth.
FranceBB, poisondeathray - My rule of thumb in ffmpeg has been to use bicubic when scaling down and lanczos when scaling up. I'll have to see what scaling options are available in Avisynth. I will look at the multi-threaded scaling as well. hello_hello - Ah, thanks for clarifying how my script wasn't working. So why is DGIndex/MPEG2Source a better option? Also, these are from DVDs recorded from TV, in case that makes a difference. For instance, I see less than 16 pixels of the width of this particular MPEG can be cropped, but that may be because I'm cropping after scaling. What I'm doing is converting to square pixels then cropping like so: Crop(6, 4, 628, 474, align=False). I was wondering though, given that the original width is 720, is it the best strategy to scale to 640? What if instead I scaled the height to 540? My current script: FFmpegSource2("F:\Movie files\Movies\Bundle Of Joy (1956).mpg", atrack=-1, rffmode=1) TFM(order = 1, mode = 5, PP = 7, slow = 2, micmatching = 2) TDecimate() BicubicResizeMT(640, 480) Crop(6, 4, 628, 474, align=False) |
9th September 2017, 02:09 | #7 | Link | ||
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
Quote:
In theory at least, the best quality method is to crop and not resize at all, but set the correct pixel aspect ratio when encoding and let the player resize it on playback as it would for the original mpeg2/DVD video. Next best would be to crop and only resize the width for the correct aspect ratio, while third best is resizing the height and/or width. NTSC 4:3 DVDs are the only type of DVD that require reducing the width when resizing to square pixel dimensions, so that could be an argument for increasing the height instead, but I doubt it'd make a difference to picture detail. I usually go with 624x468 for 4:3 NTSC as it's exactly 4:3 and if you're also cropping a few pixels top and bottom, which I invariably do, after cropping you're not reducing the height by much. It's personal preference though.... I use the third best method nearly all the time because IMHO the the quality difference is largely theoretical, because I like to resize a bunch of related videos to the same resolution after cropping, because I'm OCD about cropping to exactly 4:3 or 16:9 if the source is close to those aspect ratios, and because the media player in my TV doesn't support anamorphic MKVs/MP4s (video with non-square pixels) and displays them incorrectly, so I always resize to square pixel dimension when encoding. If you're just cropping the black and don't care about the final aspect ratio it doesn't matter which order you do it in, but if you want to control the output dimensions it's easier to do it the other way around because you can crop to a specific aspect ratio such as 4:3, and then resize to whatever 4:3 dimensions you prefer. The resize filters also crop as the Crop() filter does, although for cropping the black it's probably better to use the cropping filter before resizing (see the info just above "Examples" here) however the resize filters aren't restricted to mod 2 cropping. As an example, this would crop 10 pixels from the left, 9 from the right, and 2 from the bottom, and for a 4:3 NTSC DVD that'd give you an aspect ratio of 1.3332 so you could resize to any 4:3 dimensions with virtually zero aspect error. Crop(10, 0, -8, -2) # or Crop(10, 0, 702, 478) BicubicResizeMT(640, 480, 0, 0, -1, 0) How you do it is personal preference of course, but if you want to try that method have a play with this calculator: YodaResizeCalculator 0.4.0.1 As a rule of thumb, select "mpeg4" as the PAR Spec for 4:3 DVDs and "Generic" for 16:9 DVDs. Last edited by hello_hello; 9th September 2017 at 02:25. |
||
9th September 2017, 02:29 | #8 | Link |
Registered User
Join Date: Aug 2015
Posts: 17
|
This spurs a few questions:
I should have mentioned that I want to avoid non-square pixels for simplicity, so I have to resize at least one of the dimensions. How is it better to resize the width only rather than keep the width and resize the height? How important is it to have standard resolutions like 640x480? For example, my current script outputs 628x474, which is not quite 4:3. I want maximum compatibility with various media players and servers. This is a very large movie library. (BTW, I also like the idea of keeping it simple and resizing everything to the nearest standard ratio; I just want to make sure it's worth doing.) That's nice that you can crop down to the pixel. Is there a Avisynth filter that auto-crops? These movies often have a video (30i) introduction. It's usually pretty simple: maybe the first two minutes are video, and the rest is the movie. Now, my current script seems to do a pretty good job of IVTC with TFM, but I still see combing in the video introduction. So how do I properly deinterlace this section, and can I convert this section to 24p like the movie without it looking choppy? |
9th September 2017, 03:53 | #9 | Link | ||||
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
Mind you it's often possible to resize down a bit without any visible loss of detail, especially for interlaced sources (if you de-interlace them). I'm in PAL-land so resizing the "width only" would give you something like 1024x576 for 16:9 and 786x576 for 4:3, but I often use 960x540 and 640x480. In fact.... if you use a sharp(ish) resizer to resize to square pixels, even if you resize down a little, when the encoded version is upscaled on playback for a 1080p display, it can still end up looking sharper than the original video. Mostly that's a good thing, in my opinion, but it's all personal preference. Here's some screenshots of anamorphic encoding verses resizing to 1024x576 for encoding, upscaled to 1080p. https://forum.videohelp.com/threads/...ty#post2444902 https://forum.videohelp.com/threads/...ty#post2445018 Quote:
Back in the mpeg2 and Xvid (mpeg4) days, mod16 dimensions were often required (width and height evenly divisible by 16), but they could be any mod16 dimensions. That's why AVI resolutions such as 656x272 or 640x256 etc were once quite common. These days even that's not an issue, at least for h264, but if you want to be 100% safe, you could stick to mod4 dimensions. It's not something to stress about though. I've not met a h264 hardware player that cares. Quote:
CropResizeBorder Or Google "AutoCrop.dll Avisynth". That script was created to automatically do the type of cropping and resizing I referred to. You only need to specify the desired output resolution and it'll do the rest. It uses AutoCrop.dll to do all the cropping, which means it's limited to mod2 cropping, although that's enough for pretty accurate resizing. I did start working on a new version that only uses AutoCrop.dll to crop the black and any additional cropping would be done by the resize filter, giving it sub-pixel resizing accuracy, but I got distracted and never went back to it. I will at some stage. Quote:
hybrid=1 outputs 23.976fps. Any 29.970fps sections in the source are converted to 23.976fps by removing/blending frames. Hybrid=3 outputs 29.970fps. Any "film" sections are converted to 29.970fps using frame blending. The default is hybrid=0 which just assumes everything is "film" but what should happen is TFM would de-interlace the 30i sections and TDecimate will drop frames for 23.976fps, so while that might effect how smooth motion looks it shouldn't leave combing. Try TFM(cthresh=-1) to tell TFM everything is combed. If that fixes the problem try increasing it till it doesn't (the default cthresh is 9), otherwise I'd suggest you upload a small sample for someone to look at. Last edited by hello_hello; 9th September 2017 at 03:57. |
||||
12th September 2017, 19:49 | #10 | Link |
Registered User
Join Date: Aug 2015
Posts: 17
|
That's a lot of info. Thanks.
Here's some five-minute video clips that represent most of my movie collection. If you want, feel free to play with Avisynth/FFmpeg settings, including IVTC, scaling, and sharpening. Fullscreen 256kbps NTSC MPEG Fullscreen 256kbps NTSC MPEG (poorer film quality) Widescreen 256kbps NTSC MPEG Fullscreen black and white 256kbps NTSC MPEG Widescreen black and white 256kbps NTSC MPEG Last edited by ogrgkyle; 12th September 2017 at 20:38. Reason: Specifying the clips are NTSC. |
12th September 2017, 22:43 | #13 | Link | |
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
I don't use ffmpeg much, but it appears to assume 8:9 for an NTSC 4:3 DVD. Input #0, mpeg, from 'E:\test\VTS_01_1.VOB': Duration: 00:00:10.88, start: 0.280633, bitrate: 6168 kb/s Stream #0:0[0x1bf], 11, 1/90000: Data: dvd_nav_packet Stream #0:1[0x1e0], 152, 1/90000: Video: mpeg2video (Main), yuv420p(tv, top first), 720x480 [SAR 8:9 DAR 4:3], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc Stream #0:2[0x80], 157, 1/90000: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s Stream #0:3[0x20], 2, 1/90000: Subtitle: dvd_subtitle Successfully opened the file. List Of PARs (SARs) If you stick to the mpeg4 or ITU specs, 704x480 = 4:3 so you'd crop 8 pixels from each side and use SAR 10/11 for exactly 4:3. It surprises me ffmpeg uses the generic SARs. Mind you, all software players do (as far as I know), as do players/TVs when connected via HDMI. For 4:3 DVDs though, in my experience mpeg4 SARs are almost always correct. 16:9 DVDs are different. They tend to use generic SARs although there's no rule either way. Last edited by hello_hello; 12th September 2017 at 22:45. |
|
13th September 2017, 01:12 | #14 | Link | |
Registered User
Join Date: Aug 2015
Posts: 17
|
I will take a look at those SARs. I did not know 640x480 wasn't necessarily the correct scaling! I've always assumed that.
Are you saying using anamorphic pixels is closer to the MP4 container spec? Does this make any practical difference? Quote:
By the way, my "widescreen" DVD/MPEG recordings are not actually technically widescreen ratio, but letterboxed, so these unfortunately have even fewer useful pixels than the "fullscreen" recordings. Here is my current Avisynth script: Code:
FFmpegSource2("movie.mpg", atrack=-1, rffmode=1) TFM(order = 1, mode = 5, PP = 7, slow = 2, cthresh = 0, micmatching = 2) TDecimate(hybrid = 1) BicubicResizeMT(640, 480) Crop(6, 4, 628, 474, align=False) Code:
avs2pipemod -y4mp movie.avs | ffmpeg -y -i - -c:v libx264 -preset slower -tune film -crf 16 -pix_fmt yuv420p -g 48 -an -movflags +faststart "movie.mp4" |
|
14th September 2017, 19:52 | #15 | Link | ||||
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
The whole thing's a bit of a mess and I only partly understand the history, but the original ITU spec was based on sampling analogue video and if you follow the spec it works out to roughly 704x480 or 702x576 for 4:3 (which was usually rounded to 704x576). The mpeg4 PARs are the digital equivalent and result in almost exactly the same display aspect ratios as the ITU PARs but the numbers are simpler. Contrary to all that though, the HDMI spec seems to say 4:3 and 16:9 are exactly 4:3 and 16:9, and most digital devices resize to exactly 4:3 or 16:9. For reasons I don't understand (based on experience) pretty much all 4:3 DVDs follow the ITU/mpeg4 spec while the majority of 16:9 DVDs seem to use the generic PARs. What broadcasters may or may not do I have no idea. Quote:
Quote:
By the time it's cropped, you're down to 352x252 worth of picture. I assume 352x480 should be exactly 4:3, so the pixels would be twice as wide as mpeg4 for 20/11, although I tried three encoding programs and StaxRip assumed 20/11 while Handbrake and MeGUI apparently assume 16/9 (8/9 x 2) which seems a bit unlikely to me. Quote:
tfm().tdecimate() crop(8, 2, -14, -2) Spline36Resize(640,480) but the picture quality is only just a tad shy of disastrous and while there's no doubt ways to improve it, it's not something I do often, so I'll wait to see if someone clever comes along to help there. |
||||
14th September 2017, 22:24 | #16 | Link |
Registered User
Join Date: Aug 2015
Posts: 17
|
Only a very small percentage of my DVDs are 352x480. I selected that one by mistake. That being low-res and letterboxed, though, reflects some of the lowest quality video I have.
Most of them are 720x480, 256kbps, and recorded from TV (USA). All are NTSC. I'm guessing that 5%-10% have pretty extreme letterboxing and that 75% are black and white. My collection is very large, so I need some good default settings in case I can't tailor them to individual DVDs. |
15th September 2017, 05:27 | #17 | Link | |||
Registered User
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 266
|
Quote:
I like to do what the commercial DVD, BluRay, and broadcast industries do, which is to stick to mod-16 or at least mod-8 frame dimensions. I realize that many eccentric users don't like what the commercial industry does and that they feel some compulsion to re-invent the wheel, but since I've never had a problem playing products produced by the commercial video industry I place more trust in following their lead. 640 and 480 are two mod-16 numbers. So are 720, 704, 352, 576, 1280, 1440, and 1080. The only popular format dimension that isn't mod-16 is 1920, which is mod-8. Many Avisynth filters will insist on mod-8 images. If you want to play with mod-2 and mod-4, it's up to you. Two of the reworked video samples linked below are square-pixel and at least mod-8, and the anamorphic is mod-16. There's an obsession I guess with 4:3 Hollywood movie frames at exact 4:P3 sizes, but Hollywood never shot 4:3 movies except for Tv shows. Hollywood used several aspect ratios since the ancient 1880's, but 4:3 wasn't one of them. Most movies until the early 1950's were shot in the world-wide "Academy" format, or 1.37:1, which is a little wider than 1.333:1. The "4:3" samples you posted are movies that were all shot as 1.37:1. As far as I can tell, TV broadcasters have three ways of handling those 1.37:1 movies. They either crop from one or both edges to make the broadcast image 4:3, or they cleverly have a couple of pixels of top and bottom border that has a 1.37:1 image inside of it, or they just squish a 1.37:1 image into 1.333:1. The edge crop is the one I see most often. Determine what you're going to do with the two movies that were shot at an aspect ratio of 2.35:1. On a typical 1920x1080 display, if you want full width without playtime resizing, you need a square-pixel frame of 1920x816. No, you can't crop down to a single pixel -- at least, not with YV12. There's a 2-pixel minimum, and with interlace or telecine YV12 there's a 4-pixel minimum vertically. Quote:
Quote:
Where did you get these dark, low-bitrate videos? I'm afraid those low bitrates will hinder your effort to get clean resizes and re-encodes. Some samples are so dark they're unwatchable. If you try to brighten the details in those crushed blacks you'll find mostly noise and distortion, not detail. There's some bad object ripple and temporal warping, motion smear, block noise, some very noisy, simmering gradient areas, details and lines that disappar during motion, etc. After brightening, some of the segments look like late 50's tv kinescopes. That's quite a cleanup job ahead, I don't ency you. The more resizing and re-encoding you do, the more you'll see those defects. You can brighten the originals or not, or a little or a lot, whatever. Others might have better ideas. I resized the "49th Man" video from anamorphic 4:33 to 640x480 square pixel. I resized "The Apartment" from letterboxed 4:3 to 856x364 (2.35:1) in an 856x480 letterboxed 16x9 frame. You could get the same thing from "The Apartment" if you sized the 16x9 frame to 720x480 and encoded for 16:9 playback. Why not do it the anamorphic way? Because too many so-called smart TV's are too stupid to play anamorphic video properly (why do we call them smart?). Actually the anamorphic plays cleaner because only the height was resized for anamorphic rather than height and width for square pixel. In any case, all three of the linked mp4 reworks still need a lot more repair -- I'm certain many members here will offer their excellent solutions. frame 714 original played as 640x480 DAR in 16x9 display.jpg frame 714 new 640x480 square pixel in 16x9.jpg, won't fill very much of a 6x9 display. frame 714 new 856x480 in 16x9 display.jpg -- can get same results with the 16:9 anamorphic. Ideas for reworked samples: 49thMan_640x480_square.mp4 https://www.mediafire.com/file/eya69...480_square.mp4 Apartment_16x9_square.mp4 https://www.mediafire.com/file/2mzix...6x9_square.mp4 Apartment_16x9_anamorphic.mp4 https://www.mediafire.com/file/6ba3s...anamorphic.mp4 The color samples can be resized the same way as the others, but they're really too fuzzy for me right now, I lost so much patience with the other two samples I was too worn down to struggle with fuzz. Not that they're impossible, because overall color balance is about right. As for the 352x480 sample of "20,000 Leagues" recorded at a paltry 6-hour bitrate, that's a mistake that I hope you didn't repeat. Last edited by LemMotlow; 15th September 2017 at 13:28. |
|||
15th September 2017, 07:55 | #18 | Link | ||
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
https://arstechnica.com/civis/viewto...f=19&t=1268043 TV show: only DVD available, no Blu-ray, iTunes HD=what? upscaled? Quote:
That part of the conversation was referring to using the Avisynth resizers for cropping. They even accept float as cropping values so they can theoretically do sub pixel cropping. Last edited by hello_hello; 15th September 2017 at 08:05. |
||
19th September 2017, 02:58 | #19 | Link | ||||||
Registered User
Join Date: Aug 2015
Posts: 17
|
Quote:
Quote:
Although I just realized that the intros are always 4:3 fullscreen, and the movies often need to be cropped, and this would present a problem. In that case, what's a simple solution where both the intro and the movie can be in the same container, but be separate chapters or streams? Would you suggest MKV? I want to have compatibility and keep things simple for "dumb" players. (Which is why I'm leaning towards square pixels.) I've ripped over 1,000 DVDs, and I'm looking for a long-term solution which would work in various media servers, TVs, and video players. I'm thinking about x264/aac in MKV, with different video streams. So please give your thoughts. Quote:
I do want to improve them, but not if it's an enormous job. Again, I'm talking about a 1,000+ DVDs. For what it's worth, the people watching these are used to this quality and do not necessarily expect it to be improved, so maybe I can do some lighter touch-up. I can't spend endless time on it, so that's why I uploaded sample sections that represent the main categories of my DVDs. Maybe I can at least tailor my settings to all color films, all black and white films, etc. Quote:
Quote:
Quote:
|
||||||
19th September 2017, 04:27 | #20 | Link | |||
Registered User
Join Date: Mar 2011
Posts: 4,972
|
Quote:
I'd never add black borders to video myself. Unless you're encoding for "industry standard" compliance because you want to author a DVD/Bluray disc, and nobody does that any more, the player will simply add the required borders on playback according to the display's aspect ratio. When you play a 4:3 DVD with a widescreen picture on a 16:9 display and see that tiny picture in the middle surrounded by black, it's a perfect illustration as to why encoding back isn't a good idea... in my opinion. Quote:
For a constant frame rate output the standard method is to convert everything to a common frame rate with an Avisynth plugin such as TIVTC. I explained the process earlier in the thread. Quote:
Trim(0,999).Crop(12,2,10,-2).Spline36Resize(480,360).AddBorders(80,0,80,0)\ ++Trim(1000,0).Crop(2,56,-2,-58).Spline36Resize(640,360) That'd give you the intro as 460x360 with black borders at the sides for a total of 640x360 to match the rest. Of course you can resize to any 16:9 dimensions and add the appropriate borders but it requires manually setting it up. Mind you that sort of thing was my initial motivation for creating the script I mentioned earlier. To make doing that sort of thing easier. |
|||
Tags |
avisynth, ffmpeg, interlace, ivtc, telecine |
Thread Tools | Search this Thread |
Display Modes | |
|
|