Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

script monkeys, a hand please

  • 03-03-2003 6:31pm
    #1
    Moderators, Arts Moderators Posts: 35,741 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: 35,741 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: 35,741 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: 35,741 Mod ✭✭✭✭pickarooney


    Yup. You now have 1 pickarooney point :)


  • Closed Accounts Posts: 96 ✭✭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