Subtitle Overlapping: How to comparing two timelines in subtitles (e.g. 00:18:06 vs 00:16:01) and overwriting...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I have a series of srt files (film subtitles) that some of their time-lines overlap each others on the video! This means that some of time-lines are displayed about 1-2 seconds longer than they are in the film and conflict with the next ones!



for example:



1
00:00:01.000 --> 00:00:07.000
The following content is provided

2
00:00:04.000 --> 00:00:10.000
under a Creative Commons license.


'07' overlaps '04'!



I want to overwrite the first part of time-lines on the 2nd part of their previous line. Be care that all time-lines do not interfere with each other. some of them are correct and shorter than their next timeline! The interference is only to some of them.










share|improve this question




















  • 2





    I don't understand what you mean by "If B Do nothing".

    – geirha
    Aug 15 '13 at 18:44











  • and that's what the code already does. Could you show an example where it doesn't?

    – geirha
    Aug 15 '13 at 19:42











  • If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

    – Greenish
    Jan 18 at 19:55


















2















I have a series of srt files (film subtitles) that some of their time-lines overlap each others on the video! This means that some of time-lines are displayed about 1-2 seconds longer than they are in the film and conflict with the next ones!



for example:



1
00:00:01.000 --> 00:00:07.000
The following content is provided

2
00:00:04.000 --> 00:00:10.000
under a Creative Commons license.


'07' overlaps '04'!



I want to overwrite the first part of time-lines on the 2nd part of their previous line. Be care that all time-lines do not interfere with each other. some of them are correct and shorter than their next timeline! The interference is only to some of them.










share|improve this question




















  • 2





    I don't understand what you mean by "If B Do nothing".

    – geirha
    Aug 15 '13 at 18:44











  • and that's what the code already does. Could you show an example where it doesn't?

    – geirha
    Aug 15 '13 at 19:42











  • If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

    – Greenish
    Jan 18 at 19:55














2












2








2


0






I have a series of srt files (film subtitles) that some of their time-lines overlap each others on the video! This means that some of time-lines are displayed about 1-2 seconds longer than they are in the film and conflict with the next ones!



for example:



1
00:00:01.000 --> 00:00:07.000
The following content is provided

2
00:00:04.000 --> 00:00:10.000
under a Creative Commons license.


'07' overlaps '04'!



I want to overwrite the first part of time-lines on the 2nd part of their previous line. Be care that all time-lines do not interfere with each other. some of them are correct and shorter than their next timeline! The interference is only to some of them.










share|improve this question
















I have a series of srt files (film subtitles) that some of their time-lines overlap each others on the video! This means that some of time-lines are displayed about 1-2 seconds longer than they are in the film and conflict with the next ones!



for example:



1
00:00:01.000 --> 00:00:07.000
The following content is provided

2
00:00:04.000 --> 00:00:10.000
under a Creative Commons license.


'07' overlaps '04'!



I want to overwrite the first part of time-lines on the 2nd part of their previous line. Be care that all time-lines do not interfere with each other. some of them are correct and shorter than their next timeline! The interference is only to some of them.







awk subtitle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 8:50









Sergiy Kolodyazhnyy

75.1k9155327




75.1k9155327










asked Aug 15 '13 at 18:26









minimini

64782247




64782247








  • 2





    I don't understand what you mean by "If B Do nothing".

    – geirha
    Aug 15 '13 at 18:44











  • and that's what the code already does. Could you show an example where it doesn't?

    – geirha
    Aug 15 '13 at 19:42











  • If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

    – Greenish
    Jan 18 at 19:55














  • 2





    I don't understand what you mean by "If B Do nothing".

    – geirha
    Aug 15 '13 at 18:44











  • and that's what the code already does. Could you show an example where it doesn't?

    – geirha
    Aug 15 '13 at 19:42











  • If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

    – Greenish
    Jan 18 at 19:55








2




2





I don't understand what you mean by "If B Do nothing".

– geirha
Aug 15 '13 at 18:44





I don't understand what you mean by "If B Do nothing".

– geirha
Aug 15 '13 at 18:44













and that's what the code already does. Could you show an example where it doesn't?

– geirha
Aug 15 '13 at 19:42





and that's what the code already does. Could you show an example where it doesn't?

– geirha
Aug 15 '13 at 19:42













If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

– Greenish
Jan 18 at 19:55





If you have access to the original video (with subtitles) you can extract clean subtitles (with no overlaps) using ccextractor as ccextractor VIDEO.mp4 -noru -o SUBS.srt

– Greenish
Jan 18 at 19:55










1 Answer
1






active

oldest

votes


















2














I asked this question on #awk IRC an @geirha wrote the below great scripts. The script may be usable for other people. Subtitles overlapping problem is common because of Human error during subtitling a movie!



Suppose your timelines are in the below format:
A --> B
C --> D



Replacing B with C:



gawk '
BEGIN {
RS = "";
OFS = FS = "n";
getline;
n = split($0, prev_rec);
split($2, prev_time, / --> /);
}
{
split($2, a, / --> /);
if (a[1] < prev_time[2])
prev_rec[2] = prev_time[1]" --> "a[1];
for (i=1;i<=n;i++)
print prev_rec[i];
printf("n");
n = split($0, prev_rec);
split($2, prev_time, / --> /)
}
END {
print
}' SUBTITLE.srt > RESULT.srt


The above code compare B and C in this way:



If B > C => then run that charming command to replace B.

If B < C => Do nothing!





Replacing C with B:



gawk '
BEGIN {
RS="";
OFS=FS="n";
prev="00:00:00"
}
{
split($2,a,/ --> /);
if
(a[1] < prev) $2=prev" --> "a[2];
print $0"n"; prev=a[2]
}' SUBTITLE.srt > RESULT.srt




To use scripts on some amount of srt files in a folder:



for file in *.srt
do xxx "$file" > "$file.tmp" && mv "$file.tmp" "$file";
done


Replace xxx with the right script codes!






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f333056%2fsubtitle-overlapping-how-to-comparing-two-timelines-in-subtitles-e-g-001806%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I asked this question on #awk IRC an @geirha wrote the below great scripts. The script may be usable for other people. Subtitles overlapping problem is common because of Human error during subtitling a movie!



    Suppose your timelines are in the below format:
    A --> B
    C --> D



    Replacing B with C:



    gawk '
    BEGIN {
    RS = "";
    OFS = FS = "n";
    getline;
    n = split($0, prev_rec);
    split($2, prev_time, / --> /);
    }
    {
    split($2, a, / --> /);
    if (a[1] < prev_time[2])
    prev_rec[2] = prev_time[1]" --> "a[1];
    for (i=1;i<=n;i++)
    print prev_rec[i];
    printf("n");
    n = split($0, prev_rec);
    split($2, prev_time, / --> /)
    }
    END {
    print
    }' SUBTITLE.srt > RESULT.srt


    The above code compare B and C in this way:



    If B > C => then run that charming command to replace B.

    If B < C => Do nothing!





    Replacing C with B:



    gawk '
    BEGIN {
    RS="";
    OFS=FS="n";
    prev="00:00:00"
    }
    {
    split($2,a,/ --> /);
    if
    (a[1] < prev) $2=prev" --> "a[2];
    print $0"n"; prev=a[2]
    }' SUBTITLE.srt > RESULT.srt




    To use scripts on some amount of srt files in a folder:



    for file in *.srt
    do xxx "$file" > "$file.tmp" && mv "$file.tmp" "$file";
    done


    Replace xxx with the right script codes!






    share|improve this answer






























      2














      I asked this question on #awk IRC an @geirha wrote the below great scripts. The script may be usable for other people. Subtitles overlapping problem is common because of Human error during subtitling a movie!



      Suppose your timelines are in the below format:
      A --> B
      C --> D



      Replacing B with C:



      gawk '
      BEGIN {
      RS = "";
      OFS = FS = "n";
      getline;
      n = split($0, prev_rec);
      split($2, prev_time, / --> /);
      }
      {
      split($2, a, / --> /);
      if (a[1] < prev_time[2])
      prev_rec[2] = prev_time[1]" --> "a[1];
      for (i=1;i<=n;i++)
      print prev_rec[i];
      printf("n");
      n = split($0, prev_rec);
      split($2, prev_time, / --> /)
      }
      END {
      print
      }' SUBTITLE.srt > RESULT.srt


      The above code compare B and C in this way:



      If B > C => then run that charming command to replace B.

      If B < C => Do nothing!





      Replacing C with B:



      gawk '
      BEGIN {
      RS="";
      OFS=FS="n";
      prev="00:00:00"
      }
      {
      split($2,a,/ --> /);
      if
      (a[1] < prev) $2=prev" --> "a[2];
      print $0"n"; prev=a[2]
      }' SUBTITLE.srt > RESULT.srt




      To use scripts on some amount of srt files in a folder:



      for file in *.srt
      do xxx "$file" > "$file.tmp" && mv "$file.tmp" "$file";
      done


      Replace xxx with the right script codes!






      share|improve this answer




























        2












        2








        2







        I asked this question on #awk IRC an @geirha wrote the below great scripts. The script may be usable for other people. Subtitles overlapping problem is common because of Human error during subtitling a movie!



        Suppose your timelines are in the below format:
        A --> B
        C --> D



        Replacing B with C:



        gawk '
        BEGIN {
        RS = "";
        OFS = FS = "n";
        getline;
        n = split($0, prev_rec);
        split($2, prev_time, / --> /);
        }
        {
        split($2, a, / --> /);
        if (a[1] < prev_time[2])
        prev_rec[2] = prev_time[1]" --> "a[1];
        for (i=1;i<=n;i++)
        print prev_rec[i];
        printf("n");
        n = split($0, prev_rec);
        split($2, prev_time, / --> /)
        }
        END {
        print
        }' SUBTITLE.srt > RESULT.srt


        The above code compare B and C in this way:



        If B > C => then run that charming command to replace B.

        If B < C => Do nothing!





        Replacing C with B:



        gawk '
        BEGIN {
        RS="";
        OFS=FS="n";
        prev="00:00:00"
        }
        {
        split($2,a,/ --> /);
        if
        (a[1] < prev) $2=prev" --> "a[2];
        print $0"n"; prev=a[2]
        }' SUBTITLE.srt > RESULT.srt




        To use scripts on some amount of srt files in a folder:



        for file in *.srt
        do xxx "$file" > "$file.tmp" && mv "$file.tmp" "$file";
        done


        Replace xxx with the right script codes!






        share|improve this answer















        I asked this question on #awk IRC an @geirha wrote the below great scripts. The script may be usable for other people. Subtitles overlapping problem is common because of Human error during subtitling a movie!



        Suppose your timelines are in the below format:
        A --> B
        C --> D



        Replacing B with C:



        gawk '
        BEGIN {
        RS = "";
        OFS = FS = "n";
        getline;
        n = split($0, prev_rec);
        split($2, prev_time, / --> /);
        }
        {
        split($2, a, / --> /);
        if (a[1] < prev_time[2])
        prev_rec[2] = prev_time[1]" --> "a[1];
        for (i=1;i<=n;i++)
        print prev_rec[i];
        printf("n");
        n = split($0, prev_rec);
        split($2, prev_time, / --> /)
        }
        END {
        print
        }' SUBTITLE.srt > RESULT.srt


        The above code compare B and C in this way:



        If B > C => then run that charming command to replace B.

        If B < C => Do nothing!





        Replacing C with B:



        gawk '
        BEGIN {
        RS="";
        OFS=FS="n";
        prev="00:00:00"
        }
        {
        split($2,a,/ --> /);
        if
        (a[1] < prev) $2=prev" --> "a[2];
        print $0"n"; prev=a[2]
        }' SUBTITLE.srt > RESULT.srt




        To use scripts on some amount of srt files in a folder:



        for file in *.srt
        do xxx "$file" > "$file.tmp" && mv "$file.tmp" "$file";
        done


        Replace xxx with the right script codes!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:23


























        community wiki





        4 revs
        mini































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f333056%2fsubtitle-overlapping-how-to-comparing-two-timelines-in-subtitles-e-g-001806%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:香港粉麵

            List *all* the tuples!

            Channel [V]