Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless cli on Linux #3568

Closed
fstarkenberg opened this issue May 10, 2019 · 14 comments
Closed

Headless cli on Linux #3568

fstarkenberg opened this issue May 10, 2019 · 14 comments

Comments

@fstarkenberg
Copy link

I would like to run the application on a headless Linux server using mono but I get this error:

$ mono SubtitleEdit.exe /?
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at Nikse.SubtitleEdit.Program.Main () [0x0002d] in <a350741a374d4e31a818096ace4f9fe2>:0

This seems to work on Windows without any problem. Is there anyway to start the application without needing xserver/ a display?

@xylographe
Copy link
Member

You could try SE-3.5.9-headless.7z from this folder.
But, I doubt, /multiplereplace and some other things will work—most likely the same exception will be raised.

@fstarkenberg
Copy link
Author

Similar error unfortunately. I'm most interested in /fixcommonerrors and /removetextforhi.

$ mono SubtitleEdit.exe /?

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for
 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00005] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.Control..ctor () [0x000ea] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00014] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.Form..ctor () [0x00012] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at Nikse.SubtitleEdit.Forms.Main..ctor () [0x00126] in <3cf83f3f73744d7ea5df635a369e3383>:0
  at (wrapper remoting-invoke-with-check) Nikse.SubtitleEdit.Forms.Main:.ctor ()
  at Nikse.SubtitleEdit.Program.Main () [0x00000] in <3cf83f3f73744d7ea5df635a369e3383>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00005] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.Control..ctor () [0x000ea] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00014] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at System.Windows.Forms.Form..ctor () [0x00012] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
  at Nikse.SubtitleEdit.Forms.Main..ctor () [0x00126] in <3cf83f3f73744d7ea5df635a369e3383>:0
  at (wrapper remoting-invoke-with-check) Nikse.SubtitleEdit.Forms.Main:.ctor ()
  at Nikse.SubtitleEdit.Program.Main () [0x00000] in <3cf83f3f73744d7ea5df635a369e3383>:0

@badgolim
Copy link

badgolim commented Dec 11, 2019

+1 still waiting for it 👍

@stephenmcconnachie
Copy link

I'd also love to get a Linux headless version of this, even just for subtitle conversion (I'm running it in Windows in CLI to convert SRT to PAC and EBU-STL, works so brilliantly, thank you!). The 'headless' version in this comment has gone now, any chance of trying again? #3568 (comment)

@batatop
Copy link

batatop commented Aug 26, 2020

Hey, I got it working with Docker on a headless Linux environment. The same process should also work without Docker.
I used Subtitle Edit's Portable version, mono, and xvfb to achieve this.

xvfb is used to run GUI applications on headless environments using a virtual display.

  • This great reference a short explanation of why we need to use xvfb.
  • This great reference has several options to approach this issue. I checked "Option 2" to learn about xvfb-run, and also checked "Running Concurrent Builds" to learn about -a flag.

Part of my docker setup about Subtitle Edit:

# to add xvfb
RUN apt-get install -y xvfb

# these are all the necessary packages that were specified on https://nikse.dk/SubtitleEdit/Help#linux
RUN apt-get install -y mono-complete
RUN apt-get install -y libhunspell-dev
RUN apt-get install -y libmpv-dev
RUN apt-get install -y tesseract-ocr
RUN apt-get install -y vlc
RUN apt-get install -y ffmpeg

After that, I also got an error about saying something like: /etc/timezone is not found.
To fix this, I followed the solution on this link.

After you do all that stuff, the terminal command looks like this:
xvfb-run -a mono SubtitleEdit.exe /convert sub1.srt sami

@stephenmcconnachie
Copy link

stephenmcconnachie commented Aug 26, 2020

Hey, I got it working with Docker on a headless Linux environment. The same process should also work without Docker.
I used Subtitle Edit's Portable version, mono, and xvfb to achieve this.

xvfb is used to run GUI applications on headless environments using a virtual display.

  • This great reference a short explanation of why we need to use xvfb.
  • This great reference has several options to approach this issue. I checked "Option 2" to learn about xvfb-run, and also checked "Running Concurrent Builds" to learn about -a flag.

Part of my docker setup about Subtitle Edit:

# to add xvfb
RUN apt-get install -y xvfb

# these are all the necessary packages that were specified on https://nikse.dk/SubtitleEdit/Help#linux
RUN apt-get install -y mono-complete
RUN apt-get install -y libhunspell-dev
RUN apt-get install -y libmpv-dev
RUN apt-get install -y tesseract-ocr
RUN apt-get install -y vlc
RUN apt-get install -y ffmpeg

After that, I also got an error about saying something like: /etc/timezone is not found.
To fix this, I followed the solution on this link.

After you do all that stuff, the terminal command looks like this:
xvfb-run -a mono SubtitleEdit.exe /convert sub1.srt sami

Wonderful, I'll try this out thank you @batatop - perfect timing as I was just about to resign myself to learning some PowerShell to use in Windows CLI scriptin.

@niksedk
Copy link
Member

niksedk commented Aug 29, 2022

A dotnet 6 version of SE with cli only is now available here: https://github.com/SubtitleEdit/subtitleedit-cli
(you must have dotnet6 + download src + compile it in order to get it working)
Let me know if it works... ;)

The above solution from batatop is still nice - especially as SeCli does not support anything bitmap related incl. OCR.

@niksedk
Copy link
Member

niksedk commented Aug 29, 2022

And SeCli is a bit annoying to type... suggestions for better name welcome :)

@niksedk
Copy link
Member

niksedk commented Oct 1, 2022

Renamed to all lowercase seconv and the /convert parameter removed, so now it should be:

./seconv <pattern> <name-of-format-without-spaces> [<optional-parameters>]

(based on feedback)

@Wauter
Copy link

Wauter commented Oct 3, 2022

I packaged up @batatop 's solution with some wrapper around it as a premade docker container, specifically for use with on demand conversions. https://github.com/Wauter/subtitle-convert-docker

Just seen the SeCli info, SeCli in a container compiled for linux would make a much cleaner solution than using mono.

@batatop
Copy link

batatop commented Oct 3, 2022

I packaged up @batatop 's solution with some wrapper around it as a premade docker container, specifically for use with on demand conversions. https://github.com/Wauter/subtitle-convert-docker

Just seen the SeCli info, SeCli in a container compiled for linux would make a much cleaner solution than using mono.

Hey @Wauter, thanks for referencing my comment in your package 🍻

@Wauter
Copy link

Wauter commented Oct 3, 2022

You are very welcome!
I just managed to get SeCli running in a container as well, container image size reduction from 1.5GB to 185MB, its much faster. I'll publish it maybe tomorrow.

@Wauter
Copy link

Wauter commented Oct 4, 2022

@niksedk I've created a multistage dockerFile that can build + run seconv, see pull request. Let me know if that looks appropriate.

https://github.com/Wauter/subtitleedit-cli-docker

@niksedk
Copy link
Member

niksedk commented Oct 4, 2022

@Wauter: thx for the docker PR :)
SubtitleEdit/subtitleedit-cli#2

@niksedk niksedk closed this as completed Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants