arch1t3cht / Aegisub

Cross-platform advanced subtitle editor, with new feature branches. Read the README on the feature branch.
http://www.aegisub.org
Other
738 stars 32 forks source link

Is there a way to remove lead-in time without affecting karaoke timings? #88

Closed pizzaisdavid closed 6 months ago

pizzaisdavid commented 11 months ago

I am making subtitles with the karaoke effect.

Here is an example:

correct

Sometimes I want to experiment with the amount of lead time for a line.

Here I added an exaggerated amount of time (using the C hotkey.)

correct_adding_lead_in

Then committing, turning off karaoke mode, and dragging the red line back to near where it started results the rest of the timings being squished. See here:

outcome

And here is a comparison for easy viewing:

comparison

In my mind, the karaoke timings would be tied to the audio timing and not relative to the start of a line. -- As shifting a line does not change when an dialogue is said. I understand the ASS format may specify it that way, but the program could do something cool to avoid this problem.

Does anyone have any ideas or work-around?


Here is the files used: unexpected_behaviour.txt https://pixabay.com/sound-effects/welcomestranger-34421/

arch1t3cht commented 11 months ago

The easiest way to do this from within Aegisub is probably to use Subtitle > Split by Karaoke, delete the first line, and then Join the lines as karaoke again. Alternatively, this could easily be done with an automation script, though I don't know off-hand if there already exists a script for that somewhere.

pizzaisdavid commented 11 months ago

Thanks for the insights. It has pushed me towards making my first Lua script.

While figuring out how to precede, so far, I think I found some easy manual steps which achieve the goal:

  1. In the user interface, ensure the Time/Frame radio input is set to Time.
  2. Select the line you want to modify.
  3. Decide on the amount of lead-in time we want to remove (in centiseconds.)
  4. Add that amount to the Start Time input.
  5. Subtract that amount from the first non-zero k tag.

I always use a whole number of centiseconds because I am not sure how to handle the rounding for the k tag.

pizzaisdavid commented 11 months ago

Here's what I came up with, it seems to work well for my usecase:


--[[

ORIGINAL:
{
  "start_time": 1360, (1360 milliseconds / 136 centiseconds)
  "end_time": 2590,
  "text": "{\\k10}{\\k43}Hey,{\\k8} {\\k26}Ihr{\\k5} {\\k21}da.{\\k10}",
  ...
}

SHIFTED VIA THE AUTOMATION (THE GOAL):
{
  "start_time": 1370, <== added 10
  "end_time": 2590,
  "text": "{\\k9}{\\k43}Hey,{\\k8} {\\k26}Ihr{\\k5} {\\k21}da.{\\k10}"
  ...          ^== subtracted 1
}

]]

script_name='Remove lead-in without affecting karaoke'
script_description='works best when you set it to a hotkey'
script_author='pizzaisdavid'
script_version='1.0'

function macro_function(
  subtitles,
  selected_line_indices,
  active
)
  for _, selected_line_index in ipairs(selected_line_indices) do
    local line = subtitles[selected_line_index]

    line.start_time = line.start_time + 10
    line.text=line.text:gsub(
      '\\k(%d+)',
      function(duration)
        duration = tonumber(duration)
        duration = duration - 1
        new_tag = string.format('\\k%d', duration)
        return new_tag
      end,
      1
    )

    subtitles[selected_line_index] = line
  end
  return selected
end

aegisub.register_macro(
  script_name,
  script_description,
  macro_function
)

Filename is: remove-lead-in-without-affecting-karaoke Then copying it into the autoload folder and setting a free hot key. I did CTRL-SHIFT-. as it contains the > on my keyboard.