smacke / ffsubsync

Automagically synchronize subtitles with video.
MIT License
6.76k stars 280 forks source link

[Feature Request] Add python API #70

Open uduse opened 4 years ago

uduse commented 4 years ago

I read subsync/subsync.py and it seems there's too much processing in that. Maybe we should extract a Python API layer between the CLI and core code so users can choose between using either CLI or Python API.

morpheus65535 commented 4 years ago

It would be really great and make it easier to integrate in Bazarr. :-)

smacke commented 4 years ago

I agree that refactoring the entrypoint is probably a good idea. It will take a while to do so, unfortunately. Until then, a workaround is to build up a command line argument string, import ffsubsync's parser and use it to parse this, and then call ffsubsync.run(args) similar to what we do in test_integration.py

morpheus65535 commented 4 years ago

I'll look into this, thanks!

ghost commented 4 years ago

I agree! I ran into this issue today.

ghost commented 4 years ago
video = ".../somepath/video.mp4"
sub = ".../some/path/sub.srt"

unparsed_args = [video, "-i", sub, "-o", sub]

parser = ffsubsync.make_parser()
args = parser.parse_args(unparsed_args)

ffsubsync.run(args)

The output would look like this.

[08:48:36] INFO     extracting speech segments from reference    ffsubsync.py:98
                    'somemovie.m4v'...                                                 
           INFO     Checking video for subtitles      speech_transformers.py:240
                    stream...                                                   
[08:48:37] INFO     Video file appears to lack        speech_transformers.py:245
                    subtitle stream                                             
           WARNING  [Errno 2] No such file or         speech_transformers.py:251
                    directory: 'ffprobe': 'ffprobe'                             
0it [00:00, ?it/s]
Traceback (most recent call last):
  File "sync.py", line 150, in <module>
    test = ffsubsync.run(args)
  File ".../venv/lib/python3.7/site-packages/ffsubsync/ffsubsync.py", line 99, in run
    reference_pipe.fit(args.reference)
  File ".../venv/lib/python3.7/site-packages/ffsubsync/sklearn_shim.py", line 214, in fit
    self._final_estimator.fit(Xt, y, **fit_params)
  File ".../venv/lib/python3.7/site-packages/ffsubsync/speech_transformers.py", line 319, in fit
    'Unable to detect speech. Perhaps try specifying a different stream / track, or a different vad.'
ValueError: Unable to detect speech. Perhaps try specifying a different stream / track, or a different vad.

I tried calling ffsubsync using a subprocess call, executing the command with os.system(), and tried passing "--ffmpeg-path /usr/bin" (I can verify that ffprobe and ffmpeg exist in that directory but ffsubsync refuse to acknowledge it).

So, I had the same error with all of those.

NOTE: Doing it manually from the terminal works fine. Frustrating.

jessielw commented 1 year ago

Has there been any work done on making this an importable python module to be used with an api?

fcakyon commented 1 year ago

Is there any update on this feature?

jessielw commented 1 year ago

Doesn't seem like it atm

smacke commented 1 year ago

Nope, no updates I'm afraid. Work and life have both been keeping my pretty busy (in the past year, got married, bought a house, etc), and most of my OSS efforts recently have been towards ipyflow. That's not to say I haven't forgotten about this project, and I fully intend to get back into adding new features, improvements, API support, etc -- but right now I have no concrete timeline on it.

jessielw commented 1 year ago

Thanks for the update man. I understand!