VideoHelp Forum
+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 34
Thread
  1. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi,
    this is the formula i used to remove the logo, spreadout through out the video.
    After , processing, i found that not only logo, but also subtitle lines in the logo area is also getting removed through out the video.
    the forumula
    i used is similar to
    ffmpeg -i input.mp4 -vf "delogo=x=270:y=190:w=40:h=40" -c:a copy output.mp4
    would somebody give fix, to how to avoid the subtitle being removed
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    The filter will blur anything in the designated area. Surely this is obvious?
    Quote Quote  
  3. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    ?hi please give me fix.is there no fix
    Quote Quote  
  4. ffmpeg's delogo filter doesn't know what's a logo or what's a subtitle or what's the background. All it does is blur a rectangular portion of the picture. You will need something much smarter if you want to preserve subtitles that are in the same area as the logo.

    If the subs are easily distinguishable from the background you you might be able to remove the logo while protecting the subtitles using AviSynth. We would need a sample of the video though.
    Last edited by jagabo; 14th Jul 2020 at 09:37.
    Quote Quote  
  5. Here's an example using AviSynth. I don't have a video with both hard subs and an overlapping logo. But that doesn't really matter -- I can still use a delogo filter to blur a rectangular block (where there could have been a logo) without destroying the subtitles:

    Image
    [Attachment 54166 - Click to enlarge]


    On the left is the original frame. On the right you can see the rectangular blurred delogoed box near the lower left corner -- but the subtitles in that area are still clear. In this case I was able to isoloate the subtitles because of their yellow color.
    Last edited by jagabo; 14th Jul 2020 at 21:25.
    Quote Quote  
  6. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, could you say a little more. i do not know about avisynth. is thia also a kind of cmd based like ffmpeg.
    let me know, if i have to supply the formula or only input and select some menu
    i will look for the program in the mean while
    Quote Quote  
  7. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, is this the formula , that has been used.
    Please give your formula example, so that i could do at my end.
    LoadCPlugin("AVSInpaint.dll")
    Import("rm_logo.avs")

    AviSource("videowithlogo.avi")
    rm_logo(last, logomask="logo.bmp", loc="br", par=4.0/3.0, mode="both", percent=20, pp=1)
    i have downloaded the avisynth. please give me initial ideas
    should i just supply , the change of inupt at source in the brackets.
    should i convert any video to avi format
    Quote Quote  
  8. My logo removal script used DeKafaka() to blur the logo area and MaskHS() to build a mask for the subtitles:

    Code:
    LSmashVideoSource("video.mp4") 
    src = last  # remember original video
    
    # find yellow (subtitle) pixels
    hsmask = MaskHS(StartHue=150,    EndHue=180,  MinSat=40,     MaxSat=150).mt_expand().PointResize(width, height).ConvertToYV12(matrix="pc.601")
    
    nologo = dekafka(40, 372, 90, 90, 255)  # inpaint (simple interpolation) a box where the logo appears
    
    Overlay(nologo, src, mask=hsmask)  # fix the subtitles by taking pixels from the original video
    That will only work if your subtitles are yellow, and the logo isn't yellow. If your subtitles aren't yellow you'll have to find some other way of isolating them. That's why I asked for a sample of your video.
    Quote Quote  
  9. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, how to execute your code, i will try if it works.
    i asked permission of the author of the video and i will send it once i get it.
    would you say, how to execute the code.
    just copy in a notepad as bat and execute.
    i am new to this field altogether
    Quote Quote  
  10. The script uses several third party filters so you'll have to download and install them. LSMASH, dekafka, and MaskTools2. Create the script in a simple text editor like Notepad. Save it with .AVS as the extension (not .TXT). Then open the script with any editor/encoder that supports AviSynth, VirtualDub2, for example. Or ffmpeg or x264 CLI.

    http://avisynth.nl/index.php/Main_Page
    http://avisynth.nl/index.php/First_script
    http://avisynth.nl/index.php/Getting_started
    http://avisynth.nl/index.php/LSMASHSource
    http://avisynth.nl/index.php/DeKafka
    http://avisynth.nl/index.php/MaskTools2
    Quote Quote  
  11. would you say, how to execute the code.
    just copy in a notepad as bat and execute.
    No, the code must be saved with the .avs extension (AviSynth Script). Then (once Avisynth is installed on the system) you can open it with MPC-HC (video player), VirtualDub2 (video editor), or AVSPMod (special text editor with video preview which acts as a video editor based on Avisynth, it highlights functions, autocompletes known functions, and makes Avisynth scripting easier). The output is changed right away whenever you change the script (and reload the preview), so you can test various settings in "real time" with no need for a full encode each time.
    Then when the result is satisfying, since you are already using ffmpeg, you can encode the .avs script as if it were a video file :
    Code:
    ffmpeg -i input.avs -c:v x264 -crf 20 -preset slower -c:a copy output.mp4
    (The parameters "-crf" and "-preset" affect the compression quality and speed, and the size of the output ; "-crf 20" is generally considered a good quality/size compromise, if you want to retain quality a bit more use a lower value like "18", if you want a smaller file size use a higher value like "22" ; if "slower" is too slow for your computer, use a faster preset like "slow" or "medium" or "fast" or "faster", but either the size will be slightly superior or the quality will be slightly inferior, although it can be compensated with a lower "-crf" value. )
    Quote Quote  
  12. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, i learnt ffmpeg purely from jagabo asking him beginning queries on ffmpeg. That was a little bit easy compared to script editing.
    Hi, jagabo, i enclose the video which is 2.5mb size.
    it contains white subtitles with full vdieo logo coverage.
    Now , you could try and give me the solution..
    And just say the script that you used for this video so that i could just run the script,
    i see the links of avisynth, it is too mcuh descriptive to understand like a non programmer like me.
    ok , here is the video clip
    Image Attached Files
    Quote Quote  
  13. Oops, I saw your video last night just before going to bed. Then forgot about it today. The white text at the bottom of the frame is very similar to the subtitles so it's harder to remove without messing up the subs. I'll take a closer look at it tomorrow.
    Quote Quote  
  14. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, jagabo, actually, it was kind of issue i noticed .
    i used videosubfinder to extract hardcoded subtitles, and in the process, there was more number of images captured as images , not at all related to subtitles. So, i raised the query to the developer .
    I raised the query, and in the process of getting reply, i noticed the logos on the video, which has texts as subtitles.
    So, if each video frame, has logo as text is captured, then imagine the lines of subtitles of repetion of the logo texts .
    So, i asked the query , if it is possible to eliminate the logo, keeping the subtitles intact.
    i will wait to hear from you.
    Quote Quote  
  15. Are you doing this just so you can OCR the subs?

    Here's the result of only logo removal with dekafka() (frame 220 of the test clip):

    Image
    [Attachment 54185 - Click to enlarge]


    So far what I have is this with subtitle preservation:

    Image
    [Attachment 54184 - Click to enlarge]


    It's not perfect -- but is it good enough for you?
    Last edited by jagabo; 17th Jul 2020 at 12:00.
    Quote Quote  
  16. I can't speak for the OP, but your results look absolutely amazing to me.
    Quote Quote  
  17. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Amazing jagabo,
    Hi, i already siad that i have used vsf and subtitle eidt to extract a herdcoded subtitles from a video, as a learning process.
    In this connection, i had some problems, as my video contain logos, which arealso captures, as these repeated texts also captured as texts, when i use subtitle edit to extract subtitles after ulsing videosubfinder.
    So, i have raised this query at the developer forum site and in the meantime, i was told that developer is still on this problem.
    A person, generally sent the video with logo as example shot to the developer, who is still working on it.
    You know that i am not a programmer , but user of forumulas given by the members of this fourm and found to be a mode of learning and useful.
    So , i ask this query is newbie section of this fourm
    AS there was some confusion regarding delogo filters , which you have taught me in my previous threads, it removes logo but also the subtitles.
    When this has occured, with the sample video, i raised this query at this forum
    The rest is there to see
    Amazingly you have kept the subtitles and removed the logo with words in the area.
    You have already given the hint, about using 3 softwares, to accomplish this task.
    pleases if you could send the code also , the otherw will benefit as well as me.
    i will give the link of my query at the other forum so that you could understand why ask this query
    Thanks for your sharing , it is a kind of caring
    Link:
    https://sourceforge.net/p/videosubfinder/discussion/684990/thread/bddff843f5/?page=1
    Quote Quote  
  18. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, jagabo, please read my post 3day ago in the other forum
    the extraxct from reply;
    if suppose, this works, then one could first use this formula to remove only logo , and then attempt to create clear text images.
    Thanks jagabo
    Quote Quote  
  19. If you only need to make the logo less visible for OCR a simple script like this might be enough:

    Code:
    logox = 958
    logoy = 608
    logow = 260
    logoh = 96
    logoframe = 395
    
    LSmashVideoSource("vlc-record-2020-07-16-08h28m17s-abc.mkv-.mp4")
    
    logoonly = Trim(logoframe, logoframe).mt_binarize(150).Crop(logox, logoy, logow, logoh).GreyScale()
    
    Overlay(logoonly, x=logox, y=logoy, mode="Subtract", opacity=0.33)
    That darkens the logo a little -- maybe enough so the OCR won't see it.

    Image
    [Attachment 54188 - Click to enlarge]


    You can play around with the opacity value to reduce it more or less. If you set it too low the logo won't be reduced enough, too high and it may interfere with the OCR of the subs.

    I used frame 395 as a source for the logo. If you use this on the full video you'll need to change the frame number to a frame where the logo is clearly visible over a darkish (totally black would be best) background.

    I'll give the script for fully eliminating the logo while keeping the background later, after I've written up a description of what it's doing.
    Quote Quote  
  20. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, jagabo, thank you so much.
    i have still to learn basics of avisynth coding part.
    You have also given some useful hint at how to use avisynth.
    any how i gave the link to the developer of vsf , by referring your above reply.
    Quote Quote  
  21. The adjustments made in the post #19 script are very specific for your situation. They won't help much in the general case.
    Quote Quote  
  22. I decided it was too much work to document each step of the process. And at this point jraju probably wouldn't understand much of if anyway. So here's the script just some cursory comments:

    Code:
    # The location, width, and height of the logo we're going to remove,
    # and a frame where it stands out from the background.
    
    logox = 958
    logoy = 608
    logow = 260
    logoh = 96
    logoframe = 395
    
    # get the source video
    LSmashVideoSource("vlc-record-2020-07-16-08h28m17s-abc.mkv-.mp4")
    
    # Inpaint the FOX log at the top left
    dekafka(60,42,76,32,255)
    
    # get the logo and subtract a percentage of it from every frame
    # This darkens it a bit making it easier to to differentiate from
    # the subtitles.  Don't darken too much or it will interfere with
    # the subtitles.
    
    logoonly = Trim(logoframe, logoframe).mt_binarize(150).Crop(logox, logoy, logow, logoh).GreyScale()
    logo = Crop(logox, logoy, logow, logoh)
    logo = Overlay(logo, logoonly, mode="Subtract", opacity=0.33)
    
    # The subtitles are bright white text with a black outline and drop shadow.
    # This builds a matte of the subs by locating small bright white areas
    # (3 pixels thick or less) surrounded by black.
    
    brights = logo.mt_binarize(200)
    darks = logo.mt_binarize(40, upper=true).mt_expand().mt_expand().mt_expand().mt_inpand().mt_inpand().mt_inpand().GreyScale()
    subs = Overlay(darks, brights, mode="multiply").mt_expand().mt_expand(chroma="-128")
    subs = Overlay(subs, subs, x=3, y=3, mode="add")
    
    #Inpaint the entire logo area, including any subs in that area
    dekafka(logox, logoy, logow, logoh, 255)
    
    #Then restore the subtitles from the original video
    Overlay(last, logo, x=logox, y=logoy, mask=subs)
    Image Attached Files
    Quote Quote  
  23. Originally Posted by johnmeyer View Post
    I can't speak for the OP, but your results look absolutely amazing to me.
    Thanks!
    Quote Quote  
  24. Impressive work indeed. But some letters are not perfectly restored, like the "C" at 00:02 or the "h" and "g" at 00:09, all of which are located right at the border of the "inpaint" area. How can this be explained, since the subtitles are restored at the last step ?


    If you only need to make the logo less visible for OCR
    If the video happens to have been released with subtitles burnt-in, it should be possible to find those same subtitles as standalone SRT files.
    Quote Quote  
  25. Originally Posted by abolibibelot View Post
    Impressive work indeed. But some letters are not perfectly restored, like the "C" at 00:02 or the "h" and "g" at 00:09, all of which are located right at the border of the "inpaint" area. How can this be explained, since the subtitles are restored at the last step ?
    The mask didn't fully capture those letters. You can see a little notch in the mask (overlaid above the logo area).

    Image
    [Attachment 54190 - Click to enlarge]


    After looking more closely at the process of building the map I realized that the problem is in the drop shadow. The first "subs = Overlay..." line builds the mask for the white text and black outline:

    Image
    [Attachment 54193 - Click to enlarge]


    The second "subs = Overlay..." line builds the drop shadow three pixels to the right and three pixels down.

    Image
    [Attachment 54194 - Click to enlarge]


    There's a notch in the drop shadow corresponding to the missing part of the letter C in the first mask.

    To fix this the mask would have to include more of the image to the left so the missing parts of the C are available to fill in that small area. The annoying thing is that I originally built the mask using the entire frame but took the time to modify it to only the logo area (not anticipating this problem). So the original script didn't have the problem.
    Last edited by jagabo; 18th Jul 2020 at 16:48.
    Quote Quote  
  26. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, Jagabo,
    Eventhough i do not know the code details as such, i could read the comments and your reply of including the left shadow , shows, how you worked hard to help the situation. But for those who knows, it , it will be very helpful indeed.
    Jagabo, i did not know anything about video, before joining this forum and you are my teacher , as i already stated.
    Only one query
    Does the code you give at length, applicable to all videos to retain subtitles and remove logo, if we, change the details of parameters.
    or only works for the video i provided to you.
    Thanks
    Quote Quote  
  27. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    On reading the scripts, i think you have posted a general formula for all, marvellour
    your explanation at the first two lines of codes , gave the description to that effect.
    So, what i will do is just apply your code , after downloading the three software you mentioned, ok,
    it is enough if i know how to run the scripts,
    Quote Quote  
  28. No, almost everything in the scripts in post #19 and #22 is specific to this particular video. They may even need tweaking for other parts of your full video. The concepts can be adapted to other videos but that will require changes to the scripts.
    Last edited by jagabo; 19th Jul 2020 at 08:43.
    Quote Quote  
  29. Here's an updated script that avoids the notches in the subtitle mask of the script in post #22. Rather than building the mask using only the logo area this script builds the subtitle mask using the full frame, then crops the mask down to the logo area just before using it. I used my own BlurBox() function to blur the logo area rather than inpainting with dekafka(). That also allowed a more from fitting logo box.

    Code:
    #####################################################################################
    
    function BlurBox(clip v, int X, int Y, int W, int H, int "shade")
    {
        shade = default(shade, 0)
    
        bw = (((v.width / 32) + 4) / 2) * 2
        bh = (((v.height / 32) + 4) / 2) * 2
        bl = v.BilinearResize(bw, bh).BilinearResize(v.width, v.height).Crop(X, Y, W, H).ColorYUV(gain_y=shade)
        softedges = BlankClip(bl, color=$ffffff).Crop(2,2,-2,-2).AddBorders(2,2,2,2,color=$0).Blur(1.0).Blur(1.0).ColorYUV(cont_y=50)
        Overlay(v, bl, x=X, y=Y, mask=softedges)
    }
    
    #####################################################################################
    
    # The location, width, and height of the logo we're going to remove,
    # and a frame where it stands out from the background.
    
    logox = 958
    logoy = 624
    logow = 260
    logoh = 48
    logoframe = 395
    
    
    # get the source video
    LSmashVideoSource("vlc-record-2020-07-16-08h28m17s-abc.mkv-.mp4")
    
    
    # blur the FOX logo in the top left corner
    
    BlurBox(60,42,76,32,-64)
    
    
    # get the logo and subtract a percentage of it from every frame
    # This darkens it a bit making it easier to to differentiate from
    # the subtitles.  Don't darken too much or it will interfere with
    # the subtitles.
    
    logoonly = Trim(logoframe, logoframe).mt_binarize(150).Crop(logox, logoy, logow, logoh).GreyScale()
    logodarkened = Overlay(last, logoonly, mode="Subtract", opacity=0.33, x=logox, y=logoy)
    
    
    # The subtitles are bright white text with a black outline and drop shadow.
    # This builds a matte of the subs by locating small bright white areas
    # (3 pixels thick or less) surrounded by black.
    
    brights = logodarkened.mt_binarize(200)
    darks = logodarkened.mt_binarize(40, upper=true).mt_expand().mt_expand().mt_expand().mt_inpand().mt_inpand().mt_inpand().GreyScale()
    submask = Overlay(darks, brights, mode="multiply").mt_expand().mt_expand(chroma="-128")
    submask = Overlay(submask, submask, x=3, y=3, mode="add").Crop(logox, logoy, logow, logoh)
    
    
    # Blur the entire logo area
    BlurBox(logodarkened, logox, logoy, logow, logoh)
    
    #Then restore the subtitles from the video with the darkened logo
    Overlay(last, logodarkened.Crop(logox, logoy, logow, logoh), x=logox, y=logoy, mask=Submask)
    Image Attached Files
    Quote Quote  
  30. Member
    Join Date
    Dec 2012
    Location
    Male' Maldives
    Search PM
    Hi jagabo,

    Thank you for the the script. jraju and I were working on this clip together. I too am new pretty new to avs but over the last couple of days, I've managed to get the most recent Blurbox script to work. This would save a lot of time I spent fixing the OCR.

    Thanks again.
    Quote Quote  



Similar Threads

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