Skip to content

Instantly share code, notes, and snippets.

@Maki-Daisuke
Created May 12, 2022 06:27
Show Gist options
  • Save Maki-Daisuke/21b54a90d29836af7d2f118be54e7772 to your computer and use it in GitHub Desktop.
Save Maki-Daisuke/21b54a90d29836af7d2f118be54e7772 to your computer and use it in GitHub Desktop.
Concatenate multiple .ts files into a single file using Ffmpeg
#!/usr/bin/env perl
use File::Temp qw/ tempfile /;
use File::Spec;
sub usage {
"Usage: $0 INPUT_FILE... OUTPUT_FILE"
}
my $ffmpeg = `which ffmpeg` || `which ffmpeg.exe` or die "Can't find ffmpeg\n\n@{[ usage ]}";
chomp $ffmpeg;
my $outfile = pop or die "Can't find output filename\n\n@{[ usage ]}";
@ARGV or die "Specify at least one input\n\n@{[ usage ]}";
my ($fh, $indexfile) = tempfile(SUFFIX => '.m3u8', DIR => '.');
END{ unlink $indexfile; }
for ( @ARGV ) {
printf $fh "file %s\n", File::Spec->rel2abs($_);
print STDERR "file %s\n", File::Spec->rel2abs($_);
}
close $fh or die "Can't close temp file";
system $ffmpeg, qw/-f concat -safe 0 -i/, $indexfile, qw/-c copy/, $outfile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment