Skip to content

Commit 3cf201c

Browse files
committed
Implement cut in terms of range_start and range_end
1 parent 6fe3f9a commit 3cf201c

1 file changed

Lines changed: 13 additions & 93 deletions

File tree

markut.go

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ func (context *EvalContext) typeCheckArgs(loc Loc, signature ...TokenKind) (args
140140
return
141141
}
142142

143-
type Cut struct {
144-
chunk int
145-
pad Millis
146-
}
147-
148143
type Range struct {
149144
startLoc Loc
150145
startOffset Millis
@@ -165,7 +160,6 @@ type EvalContext struct {
165160
chunks []Chunk
166161
chunksDefinedForCurrentInput int
167162
chapters []Chapter
168-
cuts []Cut
169163
ranges []Range
170164

171165
argsStack []Token
@@ -812,7 +806,7 @@ var Subcommands = map[string]Subcommand{
812806
startOffset = context.chunks[startChunk].Duration();
813807
}
814808
if startOffset > context.chunks[startChunk].Duration() {
815-
fmt.Printf("%s: TODO: overflowing start offset is not implemented yet", r.startLoc)
809+
fmt.Printf("%s: TODO: overflowing start offset is not implemented yet\n", r.startLoc)
816810
return false
817811
}
818812
endChunk := r.endChunk
@@ -822,7 +816,7 @@ var Subcommands = map[string]Subcommand{
822816
endOffset = context.chunks[endChunk].Duration();
823817
}
824818
if endOffset > context.chunks[endChunk].Duration() {
825-
fmt.Printf("%s: TODO: overflowing end offset is not implemented yet", r.endLoc)
819+
fmt.Printf("%s: TODO: overflowing end offset is not implemented yet\n", r.endLoc)
826820
return false
827821
}
828822
if startChunk >= endChunk {
@@ -881,81 +875,6 @@ var Subcommands = map[string]Subcommand{
881875
return true
882876
},
883877
},
884-
"cut": {
885-
Description: "Render specific cut of the final video",
886-
Run: func(name string, args []string) bool {
887-
subFlag := flag.NewFlagSet(name, flag.ContinueOnError)
888-
markutPtr := subFlag.String("markut", "MARKUT", "Path to the MARKUT file")
889-
890-
err := subFlag.Parse(args)
891-
if err == flag.ErrHelp {
892-
return true
893-
}
894-
895-
if err != nil {
896-
fmt.Printf("ERROR: Could not parse command line arguments: %s\n", err)
897-
return false
898-
}
899-
900-
context, ok := defaultContext()
901-
ok = ok && context.evalMarkutFile(nil, *markutPtr, false) && context.finishEval()
902-
if !ok {
903-
return false
904-
}
905-
906-
if len(context.cuts) == 0 {
907-
fmt.Printf("ERROR: No cuts are provided. Use `cut` command after a `chunk` command to define a cut\n")
908-
return false
909-
}
910-
911-
for _, cut := range context.cuts {
912-
if cut.chunk+1 >= len(context.chunks) {
913-
fmt.Printf("ERROR: %d is an invalid cut number. There is only %d of them.\n", cut.chunk, len(context.chunks)-1)
914-
return false
915-
}
916-
917-
cutChunks := []Chunk{
918-
{
919-
Start: context.chunks[cut.chunk].End - cut.pad,
920-
End: context.chunks[cut.chunk].End,
921-
InputPath: context.chunks[cut.chunk].InputPath,
922-
},
923-
{
924-
Start: context.chunks[cut.chunk+1].Start,
925-
End: context.chunks[cut.chunk+1].Start + cut.pad,
926-
InputPath: context.chunks[cut.chunk+1].InputPath,
927-
},
928-
}
929-
930-
for _, chunk := range cutChunks {
931-
err := ffmpegCutChunk(context, chunk)
932-
if err != nil {
933-
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk.Name(), err)
934-
}
935-
}
936-
937-
cutListPath := "cut-%02d-list.txt"
938-
listPath := fmt.Sprintf(cutListPath, cut.chunk)
939-
err = ffmpegGenerateConcatList(cutChunks, listPath)
940-
if err != nil {
941-
fmt.Printf("ERROR: Could not generate not generate cut concat list %s: %s\n", cutListPath, err)
942-
return false
943-
}
944-
945-
cutOutputPath := fmt.Sprintf("cut-%02d.mp4", cut.chunk)
946-
err = ffmpegConcatChunks(listPath, cutOutputPath)
947-
if err != nil {
948-
fmt.Printf("ERROR: Could not generate cut output file %s: %s\n", cutOutputPath, err)
949-
return false
950-
}
951-
952-
fmt.Printf("Generated %s\n", cutOutputPath)
953-
fmt.Printf("%s: NOTE: cut is defined in here\n", context.chunks[cut.chunk].Loc)
954-
}
955-
956-
return true
957-
},
958-
},
959878
"chunk": {
960879
Description: "Render specific chunk of the final video",
961880
Run: func(name string, args []string) bool {
@@ -1998,24 +1917,25 @@ func main() {
19981917
},
19991918
},
20001919
"cut": {
2001-
Description: "Define a new cut for `markut cut` command.",
1920+
Description: "Equivalent to `<offset> range_start <offset> range_end`.",
20021921
Category: "Misc",
2003-
Signature: "<padding:Timestamp> --",
1922+
Signature: "<offset:Timestamp> --",
20041923
Run: func(context *EvalContext, command string, token Token) bool {
20051924
args, err := context.typeCheckArgs(token.Loc, TokenTimestamp)
20061925
if err != nil {
20071926
fmt.Printf("%s: ERROR: type check failed for %s\n", token.Loc, command)
20081927
fmt.Printf("%s\n", err)
20091928
return false
20101929
}
2011-
pad := args[0]
2012-
if len(context.chunks) == 0 {
2013-
fmt.Printf("%s: ERROR: no chunks defined for a cut\n", token.Loc)
2014-
return false
2015-
}
2016-
context.cuts = append(context.cuts, Cut{
2017-
chunk: len(context.chunks) - 1,
2018-
pad: pad.Timestamp,
1930+
offset := args[0]
1931+
context.ranges = append(context.ranges, Range{
1932+
startLoc: token.Loc,
1933+
startOffset: offset.Timestamp,
1934+
startChunk: len(context.chunks) - 1,
1935+
endLoc: token.Loc,
1936+
endOffset: offset.Timestamp,
1937+
endChunk: len(context.chunks),
1938+
closed: true,
20191939
})
20201940
return true
20211941
},

0 commit comments

Comments
 (0)