Skip to content

Instantly share code, notes, and snippets.

@ci7lus
Last active August 21, 2021 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ci7lus/9bb52f183fa005ca472e729e3a244ddc to your computer and use it in GitHub Desktop.
Save ci7lus/9bb52f183fa005ca472e729e3a244ddc to your computer and use it in GitHub Desktop.
data = """
0:04:36.10 start
0:06:37.00 end
""".strip()
filename = "target.m2ts"
# vdr_to_ffmpeg_for_colab.py
# © 2021 ci7lus MIT License
current_seconds = 0
cmds = []
results = []
total = 0
for idx, start_set in enumerate(data.split("end\n")):
start, end = [i.replace("end", "").strip()
for i in start_set.split("start\n")]
print(start, end)
start_hour, start_minute, start_second = [
float(i) for i in start.split(":")]
start_seconds = start_hour * 60 * 60 + start_minute * 60 + start_second
print("start_sec", start_seconds)
length = start_seconds - current_seconds + 0.5
total += length
result = f"output_{idx}.ts"
cmds.append(
f"ffmpeg -ss {current_seconds} -i {filename} -t {length} -c copy {result}")
results.append(result)
end_hour, end_minute, end_second = [float(i) for i in end.split(":")]
end_seconds = end_hour * 60 * 60 + end_minute * 60 + end_second
print("end_seconds", end_seconds)
current_seconds = end_seconds - 0.5
print("Total seconds", total)
for cmd in cmds:
print("!" + cmd)
print(f'!ffmpeg -i "concat:{"|".join(results)}" -c copy output.m2ts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment