Skip to content

Commit

Permalink
Merge pull request #15 from actlaboratory/cat/cut
Browse files Browse the repository at this point in the history
Resolves #6 動画の先頭からカットするとpart1のファイルが作られなくてエラーになるのを修正
  • Loading branch information
yncat authored Mar 15, 2024
2 parents 80477e5 + 8bf73e0 commit dbb10ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions domain/cutMarker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Cut markers are used to determine the cut points of a video.
CutMarker has start and end points, and they are expressed as a position string like "00:00:00.000".
"""


Expand All @@ -8,3 +9,5 @@ def __init__(self, startPoint, endPoint):
self.startPoint = startPoint
self.endPoint = endPoint

def pointsFileTop(self):
return self.startPoint == "00:00:00.000"
4 changes: 3 additions & 1 deletion domain/ffmpegCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def cutVideoCommand(task):
raise ValueError("cutMarkers must not be empty")
# end if
cuts = []
cuts.append((millisecondsToPositionStr(0), cutMarkers[0].startPoint))
if not cutMarkers[0].pointsFileTop():
cuts.append((millisecondsToPositionStr(0), cutMarkers[0].startPoint))
# end if
for i in range(len(cutMarkers) - 1):
cuts.append((cutMarkers[i].endPoint, cutMarkers[i + 1].startPoint))
# end for
Expand Down
15 changes: 15 additions & 0 deletions test/domain_test/testFfmpegCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,18 @@ def test_cutVideoCommand(self):
self.assertEqual(cmd, "ffmpeg -y -i test.mp4 -ss 00:00:00.000 -to 00:00:01.000 -c copy %s" % os.path.join(concatDir, "test_part1.mp4"))
cmd = " ".join(set.nthCommand(2).command)
self.assertEqual(cmd, "ffmpeg -y -i test.mp4 -ss 00:00:02.000 -c copy %s" % os.path.join(concatDir, "test_part2.mp4"))

def test_cutVideoCommand_cuttingFromTop(self):
task = domain.CutVideoTask()
task.nthStep(1)._value = "test.mp4"
task.nthStep(2)._value = [
domain.CutMarker("00:00:00.000", "00:00:02.000"),
]
task.nthStep(3)._value = "test2.mp4"
chain = domain.cutVideoCommand(task)
self.assertEqual(chain.countCommandSets(), 2)
concatDir = os.path.join(os.getcwd(), "temp", "concats")
set = chain.nthCommandSet(1)
self.assertEqual(set.countCommands(), 1)
cmd = " ".join(set.nthCommand(1).command)
self.assertEqual(cmd, "ffmpeg -y -i test.mp4 -ss 00:00:02.000 -c copy %s" % os.path.join(concatDir, "test_part1.mp4"))

0 comments on commit dbb10ce

Please sign in to comment.