Skip to content

Commit

Permalink
Remove -y flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Jan 14, 2024
1 parent 218d3ee commit fa74c1b
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions markut.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ func millisToSecsForFFmpeg(millis Millis) string {
return fmt.Sprintf("%d.%03d", millis/1000, millis%1000)
}

func ffmpegCutChunk(context EvalContext, chunk Chunk, y bool) error {
func ffmpegCutChunk(context EvalContext, chunk Chunk) error {
// TODO: Maybe we should remove this check? We already pass -n to
// ffmpeg down there...
_, err := os.Stat(chunk.Name())
if err == nil {
fmt.Printf("INFO: %s is already rendered\n", chunk.Name());
Expand All @@ -572,9 +574,9 @@ func ffmpegCutChunk(context EvalContext, chunk Chunk, y bool) error {
ffmpeg := ffmpegPathToBin()
args := []string{}

if y {
args = append(args, "-y")
}
// Rendering chunks is expensive. So if the chunk already exists,
// we do not rerender it.
args = append(args, "-n");

args = append(args, "-ss", millisToSecsForFFmpeg(chunk.Start))
args = append(args, "-i", chunk.InputPath)
Expand Down Expand Up @@ -614,13 +616,14 @@ func ffmpegCutChunk(context EvalContext, chunk Chunk, y bool) error {
return os.Rename(unfinishedChunkName, chunk.Name())
}

func ffmpegConcatChunks(listPath string, outputPath string, y bool) error {
func ffmpegConcatChunks(listPath string, outputPath string) error {
ffmpeg := ffmpegPathToBin()
args := []string{}

if y {
args = append(args, "-y")
}
// Unlike ffmpegCutChunk(), concatinating chunks is really
// cheap. So we can just allow ourselves to always do that no
// matter what.
args = append(args, "-y")

args = append(args, "-f", "concat")
args = append(args, "-safe", "0")
Expand Down Expand Up @@ -675,7 +678,6 @@ func ffmpegGenerateConcatList(chunks []Chunk, outputPath string) error {
func finalSubcommand(args []string) bool {
subFlag := flag.NewFlagSet("final", flag.ContinueOnError)
markutPtr := subFlag.String("markut", "", "Path to the Markut file with markers (mandatory)")
yPtr := subFlag.Bool("y", false, "Pass -y to ffmpeg")
patchPtr := subFlag.Bool("patch", false, "Patch modified cuts")

err := subFlag.Parse(args)
Expand Down Expand Up @@ -703,21 +705,21 @@ func finalSubcommand(args []string) bool {
if *patchPtr {
for _, i := range context.modified_cuts {
chunk := context.chunks[i]
err := ffmpegCutChunk(context, chunk, *yPtr)
err := ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk, err)
}
if i+1 < len(context.chunks) {
chunk = context.chunks[i+1]
err = ffmpegCutChunk(context, chunk, *yPtr)
err = ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk.Name(), err)
}
}
}
} else {
for _, chunk := range context.chunks {
err := ffmpegCutChunk(context, chunk, *yPtr)
err := ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk.Name(), err)
}
Expand All @@ -732,7 +734,7 @@ func finalSubcommand(args []string) bool {
}

outputPath := "output.mp4"
err = ffmpegConcatChunks(listPath, outputPath, *yPtr)
err = ffmpegConcatChunks(listPath, outputPath)
if err != nil {
fmt.Printf("ERROR: Could not generated final output %s: %s\n", outputPath, err)
return false
Expand All @@ -746,7 +748,6 @@ func finalSubcommand(args []string) bool {
func cutSubcommand(args []string) bool {
subFlag := flag.NewFlagSet("cut", flag.ContinueOnError)
markutPtr := subFlag.String("markut", "", "Path to the Markut file with markers (mandatory)")
yPtr := subFlag.Bool("y", false, "Pass -y to ffmpeg")

err := subFlag.Parse(args)
if err == flag.ErrHelp {
Expand Down Expand Up @@ -794,7 +795,7 @@ func cutSubcommand(args []string) bool {
}

for _, chunk := range cutChunks {
err := ffmpegCutChunk(context, chunk, *yPtr)
err := ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk.Name(), err)
}
Expand All @@ -809,7 +810,7 @@ func cutSubcommand(args []string) bool {
}

cutOutputPath := fmt.Sprintf("cut-%02d.mp4", cut.chunk)
err = ffmpegConcatChunks(listPath, cutOutputPath, *yPtr)
err = ffmpegConcatChunks(listPath, cutOutputPath)
if err != nil {
fmt.Printf("ERROR: Could not generate cut output file %s: %s\n", cutOutputPath, err)
return false
Expand Down Expand Up @@ -857,7 +858,6 @@ func chunkSubcommand(args []string) bool {
subFlag := flag.NewFlagSet("chunk", flag.ContinueOnError)
markutPtr := subFlag.String("markut", "", "Path to the Markut file with markers (mandatory)")
chunkPtr := subFlag.Int("chunk", 0, "Chunk number to render")
yPtr := subFlag.Bool("y", false, "Pass -y to ffmpeg")

err := subFlag.Parse(args)

Expand Down Expand Up @@ -888,7 +888,7 @@ func chunkSubcommand(args []string) bool {

chunk := context.chunks[*chunkPtr]

err = ffmpegCutChunk(context, chunk, *yPtr)
err = ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("ERROR: Could not cut the chunk %s: %s\n", chunk.Name(), err)
return false
Expand Down Expand Up @@ -985,7 +985,6 @@ func pruneSubcommand(args []string) bool {
func watchSubcommand(args []string) bool {
subFlag := flag.NewFlagSet("watch", flag.ContinueOnError)
markutPtr := subFlag.String("markut", "", "Path to the Markut file with markers (mandatory)")
yPtr := subFlag.Bool("y", false, "Pass -y to ffmpeg")

err := subFlag.Parse(args)

Expand Down Expand Up @@ -1023,7 +1022,7 @@ func watchSubcommand(args []string) bool {
}

if _, err := os.Stat(chunk.Name()); errors.Is(err, os.ErrNotExist) {
err = ffmpegCutChunk(context, chunk, *yPtr)
err = ffmpegCutChunk(context, chunk)
if err != nil {
fmt.Printf("ERROR: Could not cut the chunk %s: %s\n", chunk.Name(), err)
return false
Expand Down Expand Up @@ -1054,7 +1053,7 @@ func watchSubcommand(args []string) bool {
}

outputPath := "output.mp4"
err = ffmpegConcatChunks(listPath, outputPath, *yPtr)
err = ffmpegConcatChunks(listPath, outputPath)
if err != nil {
fmt.Printf("ERROR: Could not generated final output %s: %s\n", outputPath, err)
return false
Expand Down

0 comments on commit fa74c1b

Please sign in to comment.