VideoHelp Forum
+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 48
Thread
  1. I have some VHS video material encoded by MPEG-2 but those files have a large size for my purposes. Their size is about 4-5 GB, would like to compress it (preferable size less than 1-2 GB) and maintain (as much as it's possible) the quality. They all have an interlaced (TFF) scanning and variable bit rate. Is the best way (from the aspect of quality) to do it using AviSynth scripts? Please, can someone give a recommendation about the parameters I should pay attention to and give an example of the script?
    Quote Quote  
  2. Reencoding them to a smaller size is only going to reduce the quality. But if you must...

    I would use AviSynth and x264. Build an index file with DgIndex and open the video with Mpeg2Source() (both are part of the DGMpegdec package). Use Mpeg2Source's dereing filters but not it's deblocking filters (they're too strong and you'll lose detail). If you need deblocking use a filter loke deblock_qed(). If the videos are telecined film I would inverse telecine with ITVTC and encode progressive. If they're pure interlaced either encode interlaced or bob deinterlace with QTGMC (this is one of the hardest filters to get set up if you're a beginner with AviSynth) and encode progressive. Encode with x264 (either CLI or some front end like MeGUI or VidCoder). Use the Slow or VerySlow preset along with tuning for your source (animation, film, grain, etc.). Single pass CRF mode with a quantizer between 12 and 20.
    Last edited by jagabo; 19th May 2019 at 23:19.
    Quote Quote  
  3. Great post, Jagabo. +1 to everything you said.
    Quote Quote  
  4. Dinosaur Supervisor KarMa's Avatar
    Join Date
    Jul 2015
    Location
    US
    Search Comp PM
    x264 supports encoding interlaced videos, or you can deinterlace it before encoding to get rid of it.
    Quote Quote  
  5. Originally Posted by jagabo View Post
    Reencoding them to a smaller size is only going to reduce the quality. But if you must...

    I would use AviSynth and x264. Build an index file with DgIndex and open the video with Mpeg2Source() (both are part of the DGMpegdec package). Use Mpeg2Source's dereing filters but not it's deblocking filters (they're too strong and you'll lose detail). If you need deblocking use a filter loke deblock_qed(). If the videos are telecined film I would inverse telecine with ITVTC and encode progressive. If they're pure interlaced either encode interlaced or bob deinterlace with QTGMC (this is one of the hardest filters to get set up if you're a beginner with AviSynth and encode progressive. Encode with x264 (either CLI or some front end like MeGUI or VidCoder). Use the Slow or VerySlow preset along with tuning for your source (animation, film, grain, etc.). Single pass CRF mode with a quantizer between 12 and 20.
    First, thanks for the brief but conceptually useful and precise answer. Second, my goal with this conversion is simple, I want to use H.264 to decrease the file size of these SD VHS videos and maintain the quality as much as it's possible (without de-interlacing and other changes). I have HD videos of a similar duration which are compressed by H.264 at similar bitrates as these VHS videos and are only slightly bigger in size, thus I find the file size of VHS videos problematic taking their visual quality into account. You wrote that the quality would be reduced, but how significant visually is this reduction in case of VHS videos and a minimal possible quality reduction? Based on experience, what is the compression ratio I could expect in the best case? And finally, is there any way to preprocess the video and exploit its characteristics in a way to adapt it better for the H.264 compression algorithm and get a higher compression ratio? What would be results if I de-interlace the video before re-encoding?

    I know that I packed many questions here, but hope you or someone else who is more experienced can concisely explain the possibilities of H.264 from the practical point of view.
    Last edited by Santuzzu; 19th May 2019 at 23:54.
    Quote Quote  
  6. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    The better the original quality (better cam, hd, better lighting/focusing/stability), the more efficiently compressible a piece might be.
    So if you have poor vhs, even as sd, it still is having to devote a lot of compression resources to cover the peculiarties. While a similar sd recording done on a pro camera and recording method (e.g. Betacam SP), is much more compressible for the same quality (or conversely, equally compressed but much better quality).

    No real surprise.

    Scott
    Quote Quote  
  7. Originally Posted by Santuzzu View Post
    ….Please, can someone give a recommendation about the parameters I should pay attention to and give an example of the script?
    We can't just propose a useful script and x.264 commandine without knowing a bit more about your source and your Avisynth and x264 skills. Maybe you want to upload a sample of your source for getting better advice.
    You say the mpeg-2 source is interlaced. Is it TFF or BFF? Is it anamorphic or square pixel? Resolution? PAL or NTSC? Is the video noisy or blocky? What is your target container format (.ts, .mp4, .mkv)? Does your source include audio? If so, what should the target audio format be? What is your playback scenario / device?

    If you don't feel comfortable with jagabo's recommendations and just want to reduce the file size for occasional viewing you may just throw your files at handbrake, select a preset and let it do the job.
    In any case, keep your mpeg-2 "originals" in a safe place as you might come to different conclusions about what fits your needs best at a later stage.
    Last edited by Sharc; 20th May 2019 at 03:57. Reason: typos
    Quote Quote  
  8. Thanks for the advice. I'm aware that more noisy recordings are less compressible due to the nature of the (block-based) compression algorithms. That's why I have asked about the preprocessing techniques that could increase the compression ratio (deinterlacing, denoising, and so on). Generally, AviSynth skills and other technical stuff are not problematic for me, all possible solutions come into consideration. I'm familiar with algorithms, programming, and how those things work, but compression algorithms are not my main area of interests and I need more experienced people to confirm my theoretical assumptions and give some advice about the existing software solutions. I want a shortcut because at this moment I don't feel like exploring everything alone because it would take some time.

    I attached a sample video in this post.
    Image Attached Files
    Quote Quote  
  9. Why don't you just do the conversion and judge for yourself? I'm not sure why you are asking first without actually having tried it. Just use Handbrake.
    Quote Quote  
  10. Originally Posted by johnmeyer View Post
    Why don't you just do the conversion and judge for yourself? I'm not sure why you are asking first without actually having tried it. Just use Handbrake.
    Because I don't want to wander and reinvent the wheel if there is a well-known solution for such cases. Anyway, I will experiment a little bit with Handbrake and see results.
    Quote Quote  
  11. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Ok here's an attempt I did; I encoded it in Vidcoder which is based on Handbrake.

    Crop 2 top, 8 bottom for the head switching noise, allow Anamorphic sizing
    I used Yadif de-interlace with Bob
    Denoise - NLMeans / medium
    Framerate 50 / peak
    x264 slow/ CRF 22

    Because of the nature of the source, the bitrate remains quite high, achieving only
    38% reduction, approx. You can certainly reduce the strength of the noise reduction, giving more of
    the original grain, but the file size jumps up quite a bit. It's all a compromise
    Image Attached Files
    Quote Quote  
  12. Your MPG video is way over compressed. Here it is with some very heavy filtering:

    Code:
    Mpeg2Source("BAY-ARS_2005.d2v", CPU2="ooooxx", Info=3) 
    Deblock_qed_i(32,24)
    Crop(4,0,-12,-0)
    ColorYUV(gain_y=-15)
    BilinearResize(440, height)
    QTGMC(preset="slow")#, EZDenoise=1.5, DenoiseMC=true)
    MergeChroma(last, aWarpSharp2(depth=10))
    TemporalDegrain(SAD1=200, SAD2=150, sigma=8)
    nnedi3_rpow2(2, cshift="Spline36Resize", fwidth=704, fheight=576)
    x264 --preset=slow --crf=22
    Image Attached Files
    Quote Quote  
  13. Thanks to both of you for help. This looks quite good with a halved file size, but I have a problem with Deblock_qed_i function. I could call only Deblock_QED function. What's the difference between them?
    Quote Quote  
  14. I attached the file I got with the same script as above with the exception of Deblock_qed_i function which was replaced with Deblock_QED.
    Image Attached Files
    Quote Quote  
  15. Deblock_qed_i() is for interlaced video. The version I have is:


    Code:
    # Deblock_QED for interlaced video
    
    function Deblock_QED_i ( clip clp, int "quant1", int "quant2", 
     \                     int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
    {
    
    quant1 = default( quant1, 24 ) # Strength of block edge deblocking
    quant2 = default( quant2, 26 ) # Strength of block internal deblocking
    
    aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
    aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
    bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
    bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors
    
    uv    = default( uv, 3 )    # u=3 -> use proposed method for chroma deblocking
                                # u=2 -> no chroma deblocking at all (fastest method)
                                # u=1|-1 -> directly use chroma debl. from the normal|strong deblock()
    
    last=clp
    par=getparity()
    SeparateFields().PointResize(width,height)
    Deblock_QED(last, quant1, quant2, aOff1, aOff2, bOff1, bOff2, uv)
    AssumeFrameBased()
    SeparateFields()
    Merge(SelectEven(),SelectOdd())
    par ? AssumeTFF() : AssumeBFF()
    Weave() 
    }
    Quote Quote  
  16. That's it, I didn't have this one. Thank you.

    Just one question more, I think this topic is suitable for this question. Was there any attempt to design some sophisticated algorithm for intelligent video upscaling having high-quality photos of the event and/or existing HD frames from the same SD video as an input?
    Quote Quote  
  17. You can use nnedi3_rpow2(), aWarpSharp2(), and Sharpen() to further enlarge the frame and retain sharp edges without aliasing artifacts. That will work better than a simple Spline36Resize() (or other). But it will still be obvious it's upscaled SD. It will not look like real HD video or an HD photograph.
    Quote Quote  
  18. Sorry, first I have to get back to your script... I tried it after adding Deblock_qed_i() function and got different results than the video you uploaded previously. These are the first 2 frames of your (last two) and my (first two) video.

    Click image for larger version

Name:	00.png
Views:	94
Size:	772.2 KB
ID:	49119Click image for larger version

Name:	0.png
Views:	104
Size:	767.9 KB
ID:	49120
    Click image for larger version

Name:	2.png
Views:	92
Size:	784.0 KB
ID:	49121Click image for larger version

Name:	22.png
Views:	74
Size:	787.6 KB
ID:	49122

    It's visible on the logo in the bottom left corner of my video that it's different on each 2 separated frames from a field after deinterlacing, so I guess it has something to do with deinterlacing. What could be the problem?
    Quote Quote  
  19. I wouldn't worry about the first few frames of your clip. It has orphaned B frames from an open GOP at the start. Different decoders will do different things with that.
    Quote Quote  
  20. What makes problems is this difference between frames. When I watch your video, there is no flickering. If you take a look on my video you will see how 2 frames from the same field are different in constant details and it creates flickering. It happens all the time, not just with the first few frames.
    Quote Quote  
  21. I downloaded your video in post #14 -- I see the flickering you are talking about. What deinterlacer did you use? Post your the entire script.
    Quote Quote  
  22. I had some old script so I used it and just pasted your code there, that's why it looks chaotic.

    Code:
    SetMemoryMax(512)
    SetMTMode(3,4)
    PluginPath = "C:\Program Files (x86)\MeGUI\tools\avisynth_plugin\"
    LoadPlugin(PluginPath+"MaskTools2.dll")
    LoadPlugin(PluginPath+"DePan.dll")
    LoadPlugin(PluginPath+"DePanEstimate.dll")
    LoadPlugin(PluginPath+"MVTools2.dll")
    LoadPlugin(PluginPath+"nnedi3.dll")
    LoadPlugin(PluginPath+"RgTools.dll")
    LoadPlugin(PluginPath+"Deblock.dll")
    LoadPlugin(PluginPath+"DCTFilter.dll")
    LoadPlugin(PluginPath+"aWarpsharpMT.dll")
    LoadPlugin(PluginPath+"hqdn3d.dll")
    Import(PluginPath+"SMDegrain.avsi")
    Import(PluginPath+"QTGMC.avsi")
    Import(PluginPath+"Deblock_QED_MT2Mod.avsi")
    Import(PluginPath+"TemporalDegrain.avs")
    LoadPlugin("C:\Program Files (x86)\MeGUI\tools\dgindex\DGDecode.dll")
    DGDecode_mpeg2source("C:\Users\Computer\Desktop\BAY-ARS2.d2v", CPU2="ooooxx", info=3)
    LoadPlugin("C:\Program Files (x86)\MeGUI\tools\avisynth_plugin\ColorMatrix.dll")
    SetMTMode(2)
    Deblock_qed_i(32,24)
    Crop(4,0,-12,-0)
    ColorYUV(gain_y=-15)
    BilinearResize(440, height)
    QTGMC(preset="slow")#, EZDenoise=1.5, DenoiseMC=true)
    MergeChroma(last, aWarpSharp2(depth=10))
    TemporalDegrain(SAD1=200, SAD2=150, sigma=8)
    nnedi3_rpow2(2, cshift="Spline36Resize", fwidth=704, fheight=576)
    Quote Quote  
  23. There's no way QTGMC(preset="slow") produced those bobbing edges.
    Quote Quote  
  24. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Could it be a side-effect of using SetMTMode ?
    Quote Quote  
  25. No. Try encoding again. Or use VirtualDub to open your script and step through frame by frame.
    Quote Quote  
  26. Problem solved. I had to update Avisynth and its plugins to the latest version. By the way, what determines the bitrate of the encoded video? I see that its size is ~31 MB in my case, whereas one of the encoded videos uploaded here had the size of ~41 MB using the same encoding settings.
    Quote Quote  
  27. With CRF encoding you specify the quality you want. The encoder uses whatever bitrate is necessary to achieve that quality. So you know what the quality of the result will be but you don't know the size.

    If you want a specific size you use bitrate based encoding. You know what the size will be but you don't know the quality.
    Quote Quote  
  28. Yes, I understand these approaches. But how it happens that resulting bitrate is different in case of two different encoding runs using the same specified quality? I guess it's some randomized algorithm working in the background and giving different outputs. Honestly, I have never analyzed in depth video encoding algorithms and their nature, that's why I'm curious about this.
    Quote Quote  
  29. Originally Posted by Santuzzu View Post
    But how it happens that resulting bitrate is different in case of two different encoding runs using the same specified quality?
    Different filtering will result in different sizes.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!