Files

3.4 KiB

Create-FullSubtitle.ps1

Creates a full subtitle file from a video file and two SRT subtitle files by combining them with adjusted timing and sequential numbering.

Synopsis

This script:

  1. Extracts the video duration using ffprobe
  2. Parses the first subtitle file to find the last subtitle number
  3. Adjusts the second subtitle file's timing by adding the video duration
  4. Renumbers the second subtitle entries to continue from the first file
  5. Combines both into a single output SRT file

This is useful when you have two video parts with separate subtitle files and want to create a single combined subtitle file for the full video.

Parameters

  • -Video (required): Path to the video file (used to determine duration for offset)
  • -Subtitle1 (required): Path to the first subtitle file (SRT format)
  • -Subtitle2 (required): Path to the second subtitle file (SRT format)
  • -Output (required): Path to the output combined subtitle file (SRT format)

How It Works

Timing Adjustment:

The second subtitle file is assumed to start at 00:00:00,000 for its own video. The script adds the first video's duration to all timestamps in the second subtitle file.

Example: If the first video is exactly 3 minutes (00:03:00,000), then a subtitle entry from the second file at 00:00:05,000 becomes 00:03:05,000 in the output.

Numbering:

Subtitle entries are renumbered sequentially. If the first file ends with subtitle #45, the second file's entries start at #46.

Format:

All files use SRT (SubRip Subtitle) format:

1
00:00:01,000 --> 00:00:04,000
First subtitle text

2
00:00:05,000 --> 00:00:08,000
Second subtitle text

Examples

Basic usage:

.\Create-FullSubtitle.ps1 -Video "part1.mp4" -Subtitle1 "part1.srt" -Subtitle2 "part2.srt" -Output "combined.srt"

With absolute paths:

.\Create-FullSubtitle.ps1 `
    -Video "C:\Videos\part1.mp4" `
    -Subtitle1 "C:\Subtitles\part1.srt" `
    -Subtitle2 "C:\Subtitles\part2.srt" `
    -Output "D:\Output\full.srt"

Combine multiple parts:

# First combine part1 and part2
.\Create-FullSubtitle.ps1 -Video "part1.mp4" -Subtitle1 "part1.srt" -Subtitle2 "part2.srt" -Output "temp.srt"

# Then combine result with part3
.\Create-FullSubtitle.ps1 -Video "combined_1_2.mp4" -Subtitle1 "temp.srt" -Subtitle2 "part3.srt" -Output "final.srt"

Safe Execution

This script supports -WhatIf and -Confirm for safe execution:

  • -WhatIf: Simulate the operation without actually creating the output file. Shows what would be combined.
  • -Confirm: Prompt for confirmation before creating the output directory and writing the output file.

Simulate without creating files:

.\Create-FullSubtitle.ps1 -Video "video.mp4" -Subtitle1 "sub1.srt" -Subtitle2 "sub2.srt" -Output "out.srt" -WhatIf

Prompt before writing:

.\Create-FullSubtitle.ps1 -Video "video.mp4" -Subtitle1 "sub1.srt" -Subtitle2 "sub2.srt" -Output "out.srt" -Confirm

Existing Output

If the file given with -Output already exists, it is overwritten without a prompt. The folder is created when it does not exist. With -WhatIf, nothing is written.

Notes

  • Requires ffprobe in system PATH to extract video duration
  • All subtitle files must be in SRT format
  • Output file is written with UTF-8 encoding
  • The output directory is created if it does not exist
  • Subtitle timing is precise to the millisecond