Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

script monkeys, a hand please

  • 03-03-2003 07:31PM
    #1
    Moderators, Arts Moderators Posts: 36,233 Mod ✭✭✭✭


    I have a subtitle file for an AVI which is out of sync by 20 or so seconds, or 840 frames to be more precise. Therefore, I need to edit the frame numbers listed in the subtitle file (it's a textfile).
    Simple enough task, or so I thought, until I got bogged down in the pleasantries of sed/awk.

    The two sets of numbers in the sample below correspond to the beginning and end frames for displaying the subtitles. What I need to do is decrement all these numbers by 840.

    {148360}{148390}Say it!
    {148395}{148472}I won't come out|until nobody is around.
    {148477}{148561}Good boy, stubborn.
    {149220}{149252}Leave!
    {149257}{149305}Go away, dog!
    {149310}{149356}Go, dog!
    {149361}{149430}Leave.
    {149705}{149741}Good job, Ferruccio.
    {149746}{149829}It works.
    {150385}{150471}Is there anyone|called Dora here?

    The first line should thus read:

    {147520}{147550}Say it!

    I'll probably want to be able to run the script on other files, with a different decrement/increment, so the command line will be like:

    resynch_sub.sh 220 old.sub new.sub
    resynch_sub.sh -840 old.sub new.sub

    A bonus point for anyone who can name the film :)


Comments

  • Closed Accounts Posts: 286 ✭✭Kev


    Heres some perl to do it if thats any use.

    #!/usr/local/bin/perl -Wp

    s/{(\d+)}{(\d+)}/sprintf("{%d}{%d}", $1 - 840, $2 - 840)/e;

    __END__


    resynch_sub.pl old.sub > new.sub


  • Moderators, Arts Moderators Posts: 36,233 Mod ✭✭✭✭pickarooney


    I don't actually have perl installed - I'm trying to run this through a bash shell on windows. I can try installing a compiler though, I suppose.
    Cheers.


  • Registered Users, Registered Users 2 Posts: 1,186 ✭✭✭davej


    Ok off the top of my head (just built the expression as i went along so it's not efficient):


    cat filename| sed -e 's/[{}]/ /g'|awk '{print "{" $1-840 "} {"$2-840"} "$0}'|awk 'sub($3 "[ ]*" $4 "[ ]*", "", $0)'

    This with GNU Awk 3.1.0 and GNU sed version 3.02

    davej


  • Moderators, Arts Moderators Posts: 36,233 Mod ✭✭✭✭pickarooney


    You beauty! Thanks a million, Dave :)


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    la vita bella?


  • Advertisement
  • Moderators, Arts Moderators Posts: 36,233 Mod ✭✭✭✭pickarooney


    Yup. You now have 1 pickarooney point :)


  • Closed Accounts Posts: 95 ✭✭krinDar


    One line awk:

    awk -F} '{printf("{%s}{%s}%s\n",(substr($1,2)-840),substr($2,2)-840,$NF)}' filename

    In davej's version the cat is redundant, instead of doing:
    cat <filename> | sed,
    you can just do
    sed 'command' <filename>


Advertisement