GithubHelp home page GithubHelp logo

smacke / ffsubsync Goto Github PK

View Code? Open in Web Editor NEW
6.5K 6.5K 262.0 3.85 MB

Automagically synchronize subtitles with video.

License: MIT License

Python 97.81% Makefile 0.36% Shell 1.84%
alignment audio caption captions fast-fourier-transform ffmpeg fft speech-detection srt srt-subtitles string-alignment subtitle subtitles sync synchronization vad video vlc vlc-media-player voice-activity-detection

ffsubsync's People

Contributors

0xflotus avatar ajitid avatar alucryd avatar eshrh avatar kocoten1992 avatar lucas-c avatar morpheus65535 avatar nicolasmaniotto avatar rlue avatar smacke avatar thatch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffsubsync's Issues

Command not found

Hi,
Sorry as i don't familiar with Python.
I try to install the package using "pip install git+https://github.com/smacke/subsync" but i'm not able to run the sync command, for example: "subsync video.mp4 -i unsynchronized.srt > synchronized.srt".

The system suggest me to install a package with the same name "subsync" using snap but i guess that not your package.(I'm using ubuntu 18.04)

Please help!

UnicodeEncodeError: 'ascii' codec can't encode character u'\ub098' in position 32: ordinal not in range(128)

Error output:

➜ subsync S01E01.mp4 -i S01E01.srt > synced.srt
extracting speech segments...
100%|█████████▉| 712.234666667/712.235 [00:02<00:00, 288.16it/s]
...done.
computing alignments...
...done.
auditok (278.0, -871)
webrtcvad (681.0, 69029)
offset seconds: 690.290
Traceback (most recent call last):
  File "/usr/local/bin/subsync", line 11, in <module>
    load_entry_point('subsync==0.1.1', 'console_scripts', 'subsync')()
  File "/usr/local/lib/python2.7/dist-packages/subsync/subsync.py", line 161, in main
    write_offset_file(args.srtin, args.srtout, offset_seconds)
  File "/usr/local/lib/python2.7/dist-packages/subsync/subsync.py", line 42, in write_offset_file
    write_srt_to_file(fwrite, subs)
  File "/usr/local/lib/python2.7/dist-packages/subsync/utils.py", line 61, in write_srt_to_file
    return sys.stdout.write(srt.compose(subs))
UnicodeEncodeError: 'ascii' codec can't encode character u'\ub098' in position 32: ordinal not in range(128)

The part of .srt file causing error was:

5
00:00:09,750 --> 00:00:11,477
나 잡아봐봐~
("Catch me if you can.")

After some hacking I managed to get it to work by adding an env var PYTHONIOENCODING=utf-8

PYTHONIOENCODING=utf-8 subsync S01E01.mp4 -i S01E01.srt > synced.srt 

And it synchronized subs perfectly. Thank you so much for this tool :)

Synchronization from a reference.srt did not work well for me.

subsync reference.srt -i unsynchronized.srt -o synchronized.srt

reference.srt

1
00:03:02,809 --> 00:03:04,686
Brichet, court today.

2
00:03:13,945 --> 00:03:17,365
Her and her damned doors!

3
00:03:30,378 --> 00:03:32,171
Marceau, court today.

unsynchronized.srt

1
00:03:03,000 --> 00:03:04,911
Brichet! O Tribunal de Justiça!

2
00:03:13,760 --> 00:03:17,025
Ela e suas malditas portas!

3
00:03:29,439 --> 00:03:31,350
Marceau! O Tribunal de Justiça!

synchronized.srt

1
00:07:33,770 --> 00:07:35,680
Brichet! O Tribunal de Justiça!

2
00:07:44,530 --> 00:07:47,790
Ela e suas malditas portas!

3
00:08:00,200 --> 00:08:02,120
Marceau! O Tribunal de Justiça!

Error while computing alignments...

Version: subsync 0.2.6

Hi,
I encountered this error while trying to sync some subs:

$ subsync vid.mp4 -i subs.srt -o subs-synced.srt
INFO:subsync.subsync:computing alignments...
Traceback (most recent call last):
  File "/home/opens/.sources/subsync/bin/subsync", line 11, in <module>
    load_entry_point('subsync==0.2.6', 'console_scripts', 'subsync')()
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/subsync/subsync.py", line 63, in main
    srtin_pipe.fit_transform(args.srtin),
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/sklearn/pipeline.py", line 387, in fit_transform
    Xt, fit_params = self._fit(X, y, **fit_params)
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/sklearn/pipeline.py", line 317, in _fit
    **fit_params_steps[name])
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/joblib/memory.py", line 355, in __call__
    return self.func(*args, **kwargs)
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/sklearn/pipeline.py", line 716, in _fit_transform_one
    res = transformer.fit_transform(X, y, **fit_params)
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/sklearn/base.py", line 553, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/subsync/subtitle_parsers.py", line 96, in fit
    raise exc
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/subsync/subtitle_parsers.py", line 89, in fit
    max_subtitle_seconds=self.max_subtitle_seconds),
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/subsync/subtitle_parsers.py", line 22, in _srt_parse
    next_sub = next(subs)
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/srt.py", line 342, in parse
    _raise_if_not_contiguous(srt, expected_start, len(srt))
  File "/home/opens/.sources/subsync/lib/python3.7/site-packages/srt.py", line 359, in _raise_if_not_contiguous
    raise SRTParseError(expected_start, actual_start, unmatched_content)
srt.SRTParseError: Expected contiguous start of match or end of input at char 0, but started at char 278494 (unmatched content: 'ÿþ1\x00\r\x00\n\x000\x000\x00:\x000\x005\x00:\x003\x000\x00,\x007\x004\x007\x00 \x00-\x00-\x00>\x00 \x000\x000\x00:\x000\x005\x00:\x003\x003\x00,\x007\x004\x009\x00\r\x00\n\x00[\x00E\x00N\x00G\x00I\x00N\x00E\x00S\x00 \x00R\x00E\x00V\x00]\x00\r\x00\n\x00\r\x00\n\x002\x00\r\x00\n\x000\x000\x00:\x000\x006\x00:\x004\x003\x00,\x002\x007\x007\x00 \x00-\x00-\x00>\x00 \x000\x000\x00:\x000...

Unable to read the content of some directories

When trying to load subtitles or video files located in a HDD mounted in /run/media/nameoftheHDD, Subsync fails to read the content:

Screenshot from 2019-04-21 03:35:18

I have tried other directories just in case, and this doesn't happen only for /run. However, weirdly, some other directories seem to be read properly even though they belong to root:root as well.

Is that something wrong in my folders, or something to improve with Subsync?

Anyway, thanks for this great tool!

Synced subtitles still out-sync

Command:
subsync walking_dead_10x03.mkv -i walking_dead_10x03.srt -o walking_dead_10x03.nl.srt

Unsynced sub:

1
00:00:00,016 --> 00:00:01,936
Het begint.
- Sluit de poorten voor vanavond...

2
00:00:01,992 --> 00:00:03,868
en verdubbel de beveiliging op de muur.

3
00:00:04,356 --> 00:00:06,593
Wat voorafging in The Walking Dead.

4
00:00:07,579 --> 00:00:10,251
De mensen schijten
in hun broek van angst.

Synced Subs:

1
00:00:01,004 --> 00:00:02,404
We gaan terug.

2
00:00:06,369 --> 00:00:08,385
6u

3
00:00:08,559 --> 00:00:10,418
Uur 7

4
00:00:32,316 --> 00:00:34,156
Uur 2

It seems the original subs are complete wrong. Looks like a different episode. But after the sync its looks alot better. But still few sec out-sync

When i`ll try another file: man with a plan s03e9
Unsynced:

1
00:00:01,585 --> 00:00:03,353
Here's to the sale of our flip house.

2
00:00:03,378 --> 00:00:05,878
Much like me, it looks
good on the outside,

3
00:00:05,914 --> 00:00:07,797
but it has a questionable foundation.

Synced:

1
00:00:06,615 --> 00:00:08,383
Here's to the sale of our flip house.

2
00:00:08,408 --> 00:00:10,908
Much like me, it looks
good on the outside,

3
00:00:10,944 --> 00:00:12,827
but it has a questionable foundation.

This one is complete out-sync. The first one must start around: 00:00:02,200 --> 00:00:04,100

Maybe add a command to check synchronization?

Hey! Thanks for the amazing work!

What I think would be very useful would be a command to check if the subtitles are already synced with the media. This could help tremendously with large libraries instead of manually checking or blindly running the sync command.

Awesome idea, room for improvement

This is extremely interesting.

I'm the author of Sub-Zero for Plex and a contributor of Bazarr, which take a different approach to "syncing" subtitles to media by matching the release and media metadata to user generated content.

The subsync approach is one I wanted to do for ages.

Sub-Zero (and, at its core, subliminal) relies on proper offset alignment based on user generated content - this works 95% of the time, as subtitles are usually created for a specific release of a media file.

Being able to sync a subtitle based on its start point is awesome, but it's at least as error prone compared to the matching of metadata and relying on the subtitle author to not mess up.

There are a couple of factors that would need to be addressed before subsync could be integrated into one of the existing solutions (just off the top of my head):

  • hearing impaired tags mess up the detection
  • commercial breaks and cuts distort the timing of subtitles even after the initial sub entry has been synced correctly
  • multiline subtitle entries can mess up the entry point of subsync and subsequent entries

I massively applaud the effort and I hope this can be extended to do a lot more and be a lot more accurate.

Another thought for sub synchronization

First, I want to say, very great job and big thanks!

I've been considering writing a subsync-like tool for a long time and have wrote a prototyping code for validation before. Though this repo shocks me and I'm thrilled to the FFT algorithm for aligning, I do want to share my initial thought when i implemented my code:

Because most subtitles are not synchronized in a way either the frame rate is wrong (eg: 25 fps subtitle for a 24 fps movie) or there is some kind of offset in the beginning, or both, most of them can be synced by applying a linear transformation to the time. So the problem here is kinda like a linear regression problem and the vital point is to find the corresponding points between the subtitles and the audio or a reference sub. So, similarly, I transform subs into long vectors where 1 for sub on and 0 for sub off. And inspired by the feature detection algorithm in computer vision, I choose SIFT(Scale-invariant feature transform) algorithm and modify it so it can by applied in lower dimension (computer vision is 2D and this is 1D). SIFT-1D will return a set of interesting points (timestamps, and their feature vectors) for each sub. After that I use the common methods to compare the distances between the two sets of feature vectors, match them as pairs and then use RANSAC or other linear regression algorithms to calculate the linear transformation coefficients (scale and offset). The entire progress will cost several seconds when the resolution is 0.1s. In most cases it works fine but there are cases you have to adjust the parameters for SIFT-1D or RANSAC, or the result can turn really ugly, and the result is often unstable (there are some randomness in RANSAC). Also the speed is not optimized. I'm not sure whether the problems lie in the entire thought or my codes.

When I came up with your repo, I noticed that it doesn't support scaling but only offset. I was hoping SIFT-1D may be a solution when properly reimplemented. However I agree that

If you lower the split-penalty it can even correct the framerate difference because it automatically finds that splitting the movies in 3-4 (almost) equal parts with slightly different offsets optimizes the alignment rating.

@kaegi mentioned in #10. So it may not be that necessary.

Well, any comment is welcome ^~^

Issue on Windows x64

The "fcntl" module doesn't exist !

from .speech_transformers import SubtitleSpeechTransformer, VideoSpeechTransformer
File "c:\users\avign\appdata\local\programs\python\python37-32\lib\site-packages\subsync\speech_transformers.py", line 2, in
import fcntl
ModuleNotFoundError: No module named 'fcntl'

Are you planning to expand to cover foreign languages?

Hi,

Not sure if this is the right place to ask this as this isn't a bug. Are you planning to expand to cover foreign movies other than English spoken ones? I tried using this tool to sync up some of my Korean movies subtitles, but got the error for not having the dictionary for it. So, just wondering if this is something that you would be covering or not in the future, thanks.

Support Windows 10

Another user wrote:

Windows 10 / Python 3

Installed ffmpeg with chocolaty.

When I run the following command it outputs the following and does nothing:

subsync 01.mkv -i 01.srt -o 01x.srt
extracting speech segments...
0%| | 0/3575.168 [00:00<?, ?it/s]

I see that ffmpeg is running with the following options but it seems to be doing nothing.

ffmpeg.exe -i 01.mkv -f s16le -ac 1 -acodec pcm_s16le -ar 48000 -

See #4

Accept music files (mp3, wav, ogg)

I am using SubSync to sync lyrics with mp3 files. But to do so, I have to convert the mp3 files to wmv format, just to be compatible with the format requirement.

Since the README states that "the most expensive step is actually extraction of raw audio", having an option to load raw music files instead of movie files would be a nice improvement in terms of performance and ergonomy.

About Python2 and Windows 10

I tried it on my MPB with Python2 first and it failed. But it worked fine with Python3 an I used it on a whole movie file (more than 1 GB in size and 130 minutes long). Also, i tried it on Windows but couldn't install it. So, will it ever support Windows 10?

Danish dialogue support + "basic mode" feature request

First of all thank you for this awesome software, it's genius!

I noticed that currently the spoken Danish is not supported so I was wondering if there's any plan to support this. Also I like a lot the option to synchronise subtitles with subtitles instead of video. Often movies come with strange subtitles format and OCR them is not easy/quick/simple so download a plain .srt version from Internet and using subsync is a wonderful function to have! Well done.

Beside this I have a minor feature request:

assuming the source subtitle file is simply offset compared to the dialog in the video file (great majority of the cases unless it's a re-edited/remasters/director-cut version), could SubSync have a "basic mode" where instead of trying to understand what the dialog says it would just try to match "voice" with "text"? This could be the default action if the audio language is left to "Unknown"...

Regardless many thanks for the fantastic software!!

Measuring FFT process time

I am interested in calculating the time of FFT process. I tried to add datetime function before and after the FFT calculations in the aligners.py file and printing out the time, before the installation. However, when I installed it didn't work out. I was wondering how i can do some modifications to your code (like this issue that I mentioned) before the installation.

Thanks very much

get rid of scikit-learn dependency

We're only using the pipeline functionality as a convenient way to string together transformations and cache intermediates; probably no need to bring all the extra baggage that comes along with sklearn.

subsync silently fails to process lines with 4 digit miliseconds

Hi Stephen,
I was syncing a foreign movie with English subs and I noticed that the resulting srt file was a lot smaller than the original file (subsync usually produces smaller files but this one was 85kb smaller).
subsync showed no errors of any kind and just reported that it finished processing:

INFO:subsync.speech_transformers:...done.
INFO:subsync.aligners:computing alignments...
INFO:subsync.aligners:...done
INFO:subsync.subsync:offset seconds: 0.060

After looking at the resulting file, I noticed that it cut off everything after the line 78. I couldn't immediately tell what was wrong (srt file looked normal to my eyes) but after opening the srt with Aegisub and re-saving it, and comparing the differences, I noticed that Aegisub replaced the following:

79
00:08:54,009 --> 00:08:55,1000
blah

with:

79
00:08:54,009 --> 00:08:55,100
blah

Running the exported file through subsync produced a valid, synced, srt file. I've confirmed that changing the milliseocnds to 1000 or some other 4 digit number will cause the same bug with other files too.

CLI Issue on Windows 10 x64

Hello and thank you for this incredible piece of software!
I'm trying to run the following command line:

subsync.exe v.mkv -i s.srt -o ss.srt

(I'm in the path where subsync.exe is located; also v.mkv and s.srt exist and are valid files). I'm on Microsoft Windows [Version 10.0.17134.885], and the subsync has been downloaded yesterday.

I'm getting the following error:

error

from che GUI I can successfully proceed with the syncronization.

Any idea of what I am doing wrong?

thanks!

ffmpeg._run.Error: ffprobe error

While trying to run the program in Arch Linux 64 bit I see this error :

INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
Traceback (most recent call last):
  File "/home/nirjhor/.local/bin/subsync", line 11, in <module>
    load_entry_point('subsync==0.2.10', 'console_scripts', 'subsync')()
  File "/home/nirjhor/.local/lib/python3.7/site-packages/subsync/subsync.py", line 74, in main
    reference_pipe.fit_transform(args.reference)
  File "/home/nirjhor/.local/lib/python3.7/site-packages/sklearn/pipeline.py", line 393, in fit_transform
    return last_step.fit_transform(Xt, y, **fit_params)
  File "/home/nirjhor/.local/lib/python3.7/site-packages/sklearn/base.py", line 553, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "/home/nirjhor/.local/lib/python3.7/site-packages/subsync/speech_transformers.py", line 54, in fit
    total_duration = float(ffmpeg.probe(fname)['format']['duration']) - self.start_seconds
  File "/home/nirjhor/.local/lib/python3.7/site-packages/ffmpeg/_probe.py", line 23, in probe
    raise Error('ffprobe', out, err)
ffmpeg._run.Error: ffprobe error (see stderr output for detail)

What I tried:

  • Installing as user in pip

  • reinstalling subsync

  • tried with --encoding utf-8 & utf-16

What I expect to happen:

The program should run

What happens:

I see the above-mentioned error

TypeError Exception

On Fedora29, running subsync reference.srt -i unsync.srt -o sync.srt raises this exception:

Traceback (most recent call last):
  File "/home/rmassidda/.local/bin/subsync", line 11, in <module>
    sys.exit(main())
  File "/home/rmassidda/.local/lib/python2.7/site-packages/subsync/subsync.py", line 50, in main
    reference_pipe = make_srt_speech_pipeline(args.reference_encoding or 'infer')
TypeError: make_srt_speech_pipeline() takes exactly 2 arguments (1 given)

ValueError: Attempted relative import in non-package

Hello!

After the installation I can't launch Subsync the correct way:
$ subsync reference.srt -i unsynchronized.srt -o synchronized.srt

So I tried from the install folder:
$ python ~/.local/lib/python2.7/site-packages/subsync/subsync.py movie.en.srt -i movie.it.srt" -o movie.2.it.srt"

Unfortunately I've got this error:
Traceback (most recent call last): File "/home/username/.local/lib/python2.7/site-packages/subsync/subsync.py", line 16, in <module> from .utils import read_srt_from_file, write_srt_to_file, srt_offset ValueError: Attempted relative import in non-package

I'm on Ubuntu 18.04 with Python 2.7 installed.

Do you know how I can correct this error?

Thanks!

Subcync cutting out 18min of subtitles

I have a particular video and subtitle file and subsync thinks that every subtitle entry before 00:18:17,348 has a start time of <0 seconds.

INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
INFO:subsync.speech_transformers:extracting speech segments from video Line.of.Duty.S02E01.Status.Zero.1080p.Amazon.WEB-DL.DD+2.0.x264-QOQ.mkv...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉| 3698.656/3698.695 [00:10<00:00, 364.24it/s]
INFO:subsync.speech_transformers:...done.
INFO:subsync.aligners:computing alignments...
INFO:subsync.aligners:...done
INFO:subsync.subsync:offset seconds: -1097.210
WARNING:srt:Skipped subtitle at index 1: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 2: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 3: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 4: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 5: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 6: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 7: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 8: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 9: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 10: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 11: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 12: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 13: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 14: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 15: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 16: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 17: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 18: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 19: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 20: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 21: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 22: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 23: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 24: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 25: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 26: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 27: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 28: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 29: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 30: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 31: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 32: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 33: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 34: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 35: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 36: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 37: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 38: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 39: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 40: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 41: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 42: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 43: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 44: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 45: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 46: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 47: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 48: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 49: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 50: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 51: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 52: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 53: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 54: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 55: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 56: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 57: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 58: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 59: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 60: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 61: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 62: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 63: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 64: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 65: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 66: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 67: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 68: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 69: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 70: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 71: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 72: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 73: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 74: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 75: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 76: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 77: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 78: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 79: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 80: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 81: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 82: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 83: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 84: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 85: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 86: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 87: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 88: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 89: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 90: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 91: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 92: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 93: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 94: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 95: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 96: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 97: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 98: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 99: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 100: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 101: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 102: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 103: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 104: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 105: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 106: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 107: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 108: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 109: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 110: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 111: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 112: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 113: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 114: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 115: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 116: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 117: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 118: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 119: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 120: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 121: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 122: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 123: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 124: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 125: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 126: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 127: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 128: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 129: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 130: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 131: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 132: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 133: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 134: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 135: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 136: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 137: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 138: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 139: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 140: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 141: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 142: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 143: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 144: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 145: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 146: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 147: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 148: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 149: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 150: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 151: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 152: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 153: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 154: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 155: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 156: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 157: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 158: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 159: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 160: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 161: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 162: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 163: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 164: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 165: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 166: Start time < 0 seconds
WARNING:srt:Skipped subtitle at index 167: Start time < 0 seconds

Video duration is 61:38 minutes, srt duration is 00:58:25,918

Error when not using --progress-only

When I run the command subsync video.avi -i unsynced.srt -o sync.srt, I get this error

Traceback (most recent call last):
  File "/usr/local/bin/subsync", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/subsync/subsync.py", line 150, in main
    make_webrtcvad_detector()
  File "/usr/local/lib/python3.7/site-packages/subsync/subsync.py", line 101, in get_speech_segments_from_media
    say('extracting speech segments...', file=sys.stderr)
  File "/usr/local/lib/python3.7/site-packages/subsync/subsync.py", line 24, in say
    print(*args **kwargs)
TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'dict'

But when I use the --progress-only flag, everything work as expected.

subsync video.avi -i unsynced.srt -o sync.srt --progress-only
7
15
...

By the way thanks for this tool, it saved my movie night XD

Specs

  • MacOS 10.14.3
  • Python 3.7.2
  • ffmpeg version 4.1.1

Subsync won't keep original subtitle encoding on synchronized one

Hi, Thanks for this interesting command line tool. There is one bug that makes a problem when using this tool on languages like Persian. When synchronizing Persian subtitle, it doesn't preserve encoding of the original file, which make the synchronized subtitle unusable.

cmd_2019-03-08_15-34-49

Unable to run

This is awesome! Can't wait to have it running.

$ python -V
Python 2.7.15+

$ pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

$ pip install git+https://github.com/smacke/subsync
Collecting git+https://github.com/smacke/subsync
  Cloning https://github.com/smacke/subsync to /tmp/pip-knBFFV-build
Collecting argparse (from subsync==0.2.0)
  Using cached https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl
Collecting ffmpeg-python (from subsync==0.2.0)
  Using cached https://files.pythonhosted.org/packages/d0/76/d04cf269e20bbb0357d2641e20a4d8b9e1bec7cb8485389a001a6ace6018/ffmpeg_python-0.1.17-py2-none-any.whl
Collecting future (from subsync==0.2.0)
Collecting numpy>=1.12.0 (from subsync==0.2.0)
  Using cached https://files.pythonhosted.org/packages/c4/33/8ec8dcdb4ede5d453047bbdbd01916dbaccdb63e98bba60989718f5f0876/numpy-1.16.2-cp27-cp27mu-manylinux1_x86_64.whl
Collecting srt (from subsync==0.2.0)
Collecting tqdm (from subsync==0.2.0)
  Using cached https://files.pythonhosted.org/packages/6c/4b/c38b5144cf167c4f52288517436ccafefe9dc01b8d1c190e18a6b154cd4a/tqdm-4.31.1-py2.py3-none-any.whl
Collecting webrtcvad (from subsync==0.2.0)
Installing collected packages: argparse, future, ffmpeg-python, numpy, srt, tqdm, webrtcvad, subsync
  Running setup.py install for subsync ... done
Successfully installed argparse-1.4.0 ffmpeg-python-0.1.17 future-0.17.1 numpy-1.16.2 srt-1.10.0 subsync-0.2.0 tqdm-4.31.1 webrtcvad-2.0.10

My opinion of pip (and every other poor implementation of apt) is it's only useful for Docker containers or while working on the code. On a system it's idiotic to have to run pip install --upgrade, npm update, composer update, etc to upgrade. I run Debian, it uses apt. Once I figure out how to run this utility I'll Dockerize it so I won't have to deal with this down the road and save others the headache known as pip. I'm running guessit (utility that downloads subtitles) in a docker container, utilities like this are awesome in Docker.

$ pip show subsync                                                                                                                                                                                              
Name: subsync
Version: 0.2.0
Summary: Language-agnostic synchronization of subtitles with video via speech detection.
Home-page: https://github.com/smacke/subsync
Author: Stephen Macke
Author-email: [email protected]
License: MIT
Location: /home/michael/.local/lib/python2.7/site-packages
Requires: argparse, ffmpeg-python, future, numpy, srt, tqdm, webrtcvad

Looks like I can install some of them the right way:

$ sudo apt-get install python-future
$ sudo apt-get install python-numpy
$ sudo apt-get install python-tqdm
$ ls -al /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py
-rw-rw-r-- 1 michael michael 6104 Mar  7 18:42 /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py

$ /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py
zsh: permission denied: /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py

$ chmod 764 /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py

$ /home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py
Traceback (most recent call last):
  File "/home/michael/.local/lib/python2.7/site-packages/subsync/subsync.py", line 13, in <module>
    from .utils import read_srt_from_file, write_srt_to_file, srt_offset
ValueError: Attempted relative import in non-package

No idea how to run it...

Does it sync the whole srt file...

...or just put an offset at the beginning?

I mean, if the subtitles start right, but then get delayed in the middle of the sequence (like +200ms), will it be fixed / resynchronized?

Installation fails on dependency tensorflow?

I'm not too familiar with the python ecosystem, so forgive me if I'm missing something obvious.

I'm trying to install subsync system-wide, and getting the following error:

$ sudo pip3 install subsync
Collecting subsync
...
Collecting tensorflow==1.5.1 (from subsync)
  ERROR: Could not find a version that satisfies the requirement tensorflow==1.5.1 (from subsync) (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.14.0rc0, 1.14.0rc1, 2.0.0a0, 2.0.0b0)
ERROR: No matching distribution found for tensorflow==1.5.1 (from subsync)

Obviously tensorflow 1.5.1 exists in the pypi repos; I don't know if this is a python2 vs python3 issue, but manually installing 1.5.1 fails with the same error.

Is there maybe something wrong with the way I have pip configured? Is it a viable option to upgrade the version of tensorflow that subsync depends on?

File not found (WinError 2)

The script doesn't work at all when i'm trying to sync. It gives me this error:

INFO:subsync.subsync:computing alignments...
INFO:subsync.speech_transformers:extracting speech segments from subtitles...
Traceback (most recent call last):
  File "C:\Users\*****\AppData\Local\Programs\Python\Python37-32\Scripts\subsync-script.py", line 11, in <module>
    load_entry_point('subsync==0.2.8', 'console_scripts', 'subsync')()
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\site-packages\subsync\subsync.py", line 73, in main
    reference_pipe.fit_transform(args.reference)
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\site-packages\sklearn\pipeline.py", line 393, in fit_transform
    return last_step.fit_transform(Xt, y, **fit_params)
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\site-packages\sklearn\base.py", line 553, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\site-packages\subsync\speech_transformers.py", line 53, in fit
    total_duration = float(ffmpeg.probe(fname)['format']['duration']) - self.start_seconds
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\site-packages\ffmpeg\_probe.py", line 20, in probe
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "c:\users\*****\appdata\local\programs\python\python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

(It's in french, but it says file is not found... Doesn't tell which file it's talking about...)

Using Windows 10 and python 3

Specify start time for processing?

It seems to me that if there's an introduction sequence to the video (theme song, etc), subsync keys off of audio for that and moves the sub timing too early.
Feature request here: Add an option to have subsync start its analysis at/after a specific timestamp?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.