ffsubsync icon indicating copy to clipboard operation
ffsubsync copied to clipboard

[Feature Request] Add python API

Open uduse opened this issue 5 years ago • 10 comments

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.

uduse avatar May 08 '20 16:05 uduse

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

morpheus65535 avatar Jun 05 '20 23:06 morpheus65535

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

smacke avatar Jun 06 '20 20:06 smacke

I'll look into this, thanks!

morpheus65535 avatar Jun 07 '20 11:06 morpheus65535

I agree! I ran into this issue today.

incognit-o avatar Jul 29 '20 03:07 incognit-o

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.

incognit-o avatar Jul 29 '20 13:07 incognit-o

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

jessielw avatar Oct 21 '22 14:10 jessielw

Is there any update on this feature?

fcakyon avatar Nov 12 '22 18:11 fcakyon

Doesn't seem like it atm

jessielw avatar Nov 12 '22 18:11 jessielw

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.

smacke avatar Nov 12 '22 22:11 smacke

Thanks for the update man. I understand!

jessielw avatar Nov 13 '22 04:11 jessielw