Comments (7)
this would be a really helpful feature. i just had to do this manually on a 30 min video. has anyone started on it or even scripted a little workaround perhaps?
from subed.
i cooked up a basic hack to implement trimming overlapping subtitle times for srt subs
(defcustom subed-trim-overlapping-subtitle-times nil
"Whether overlapping subtitles should be adjusted on saving. A string of either 'start', to adjust the start time of the following subtitle or 'end', to adjust the end of the current subtitle. Defaults to nil."
:type 'string
:group 'subed)
(setq subed-trim-overlapping-subtitle-times "start")
(defun subed-srt--trim-overlap-end-times ()
"Check if end time of current subtitle is after start point of next.
If so, trim the end time of current subtitle to 1 milisecond less than next."
(interactive)
(let ((next-sub-start-time (save-excursion
(subed-srt--forward-subtitle-time-start)
(subed-srt--subtitle-msecs-start))))
(if (>= (subed-srt--subtitle-msecs-stop) next-sub-start-time)
(subed-srt--set-subtitle-time-stop
(1- next-sub-start-time)))))
(defun subed-srt--trim-overlap-start-times ()
"Check if end time of current subtitle is after start point of next.
If so, trim the start time of next subtitle to 1 milisecond more than prev."
(interactive)
(let ((this-sub-stop-time (subed-srt--subtitle-msecs-stop))
(next-sub-start-time (save-excursion
(subed-srt--forward-subtitle-time-start)
(subed-srt--subtitle-msecs-start))))
(if (>= this-sub-stop-time next-sub-start-time)
(save-excursion
(subed-srt--forward-subtitle-time-start)
(subed-srt--set-subtitle-time-start
(1+ this-sub-stop-time))))))
(defun subed-srt--sanitize-overlaps ()
"Adjust all overlapping times in current file.
Uses either `subed-srt--trim-overlap-start-times' or `subed-srt--trim-overlapping-end-times', the latter being the default. See `subed-trim-overlap-start-or-end' to customize this option."
(interactive)
(goto-char (point-min))
(save-excursion
(while (subed-srt--forward-subtitle-time-start)
(if (equal subed-trim-overlapping-subtitle-times "start")
(subed-srt--trim-overlap-start-times)
(if (equal subed-trim-overlap-start-or-end "end")
(subed-srt--trim-overlap-end-times))))))
;; add to existing subed-srt--sort:
(defun subed-srt--sort ()
"Sanitize, then sort subtitles by start time and re-number them."
(interactive)
(atomic-change-group
(subed-srt--sanitize)
(when subed-trim-overlapping-subtitle-times
(subed-srt--sanitize-overlaps))
(subed-srt--validate)
(subed-save-excursion
(goto-char (point-min))
(sort-subr nil
;; nextrecfun (move to next record/subtitle or to end-of-buffer
;; if there are no more records)
(lambda () (unless (subed-srt--forward-subtitle-id)
(goto-char (point-max))))
;; endrecfun (move to end of current record/subtitle)
#'subed-srt--jump-to-subtitle-end
;; startkeyfun (return sort value of current record/subtitle)
#'subed-srt--subtitle-msecs-start))
(subed-srt--regenerate-ids)))
a more elegant option might be to also allow custom respecting of subed-milliseconds-adjust
, rather than just using a single millisecond difference. but that may also make adjustments that are larger than what is wanted. another poss would be to split the overlap in half and add to each timecode.
this could also easily be adapted to just reporting/validating rather than actually changing, or left out of subed-srt--sort
to only be run interactively.
i don't know the subed code well at all, so i'm not sure if this is a very good way to do this.
from subed.
from subed.
hi @rndusr,
ah so i just edited the above to make it only run if the custom setting is non-nil, and set that as default.
santize-overlaps is already interactive, so can just be run by the user.
and you are right that it could be good to make it optional to run on loading a file, so you do it before making any manual adjustments. or ask on load.
happy to make it run on both formats, that's what i didn't understand v well with yr code.
i can have another play soon and if you like i can (try to!) submit a PR.
my personal case re 1ms is that while i use subed-subtitle-spacing generally, the gap is not imperative for me, so it makes a kinda sense to left them w no gap unless adjusted. but cd make it an option somehow.
from subed.
from subed.
If you could use only functions from subed-common.el to implement this, it should mean all formats are trimmed.
i took a look and i'm a little confused. did you maybe mean using the functions included in subed--generic-function-suffixes
? from what i see those functions are converted from generic to specific format funs when subed--init
is run, while subed-common.el doesn't seem to contain the funs this functionality would need.
because that variable contains the funs this code needs, it looks like simply reformatting everything using generic functions would work. is that correct?
i also added a custom option to use subed-subtitle-spacing
rather than +/- 1 millisecond. universal-arg prefix is easy done, will look into multi prefix options also.
from subed.
from subed.
Related Issues (20)
- can we use this for transcription of audio files? HOT 3
- Adopt REUSE standard for copyright and licensing HOT 6
- Debugger entered--Lisp error: (void-variable subed--init-alist) HOT 6
- subed recenters on save, breaking scroll-all-mode HOT 3
- Describe workflow for converting a series of lines like "2:34 foo bar" to subtitles? HOT 1
- subed fails to open the corresponding video file automatically HOT 8
- Define `subed-loop-seconds-before` and `subed-loop-seconds-after` in millisecond? HOT 2
- org-links to subtitles by number HOT 3
- adjust time of current subtitle end and next subtitle start? HOT 41
- saving subed buffer removes flyspell overlays HOT 5
- typo in subed.el (subed-prepare-for-save) HOT 4
- mark ring is emptied on save HOT 2
- How to read a property from mpv HOT 4
- How to use IINA with subed? HOT 3
- (error "Found invalid start time: \"00:00:00.000 --> 00:00:03.400\"") HOT 3
- How to use subed-scale-subtitles-forward? HOT 2
- The looping over period of timestamp do not change instantly after merge with the next subtitle. HOT 3
- subed-mpv--socket: Couldn’t make directory /scp:edrx@linode:/tmpsubed HOT 4
- Invalid function error in subed-waveform-toggle-show-all HOT 1
- Can't select "mov" files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subed.