Created
October 11, 2016 22:07
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Data::Dump::Color; | |
use File::Basename; | |
use strict; | |
use warnings; | |
my @profiles = ( | |
# VideoBW, AudioBW, VideoHeight | |
["190k","48k","240p"], | |
["450k","64k","360p"], | |
["700k","128k","480p"], | |
#["2400k","256k","720p"], | |
#["4200k","384k","1080p"], | |
); | |
####################################################################### | |
# Get all the readable files from @ARGV | |
my @input = (); | |
foreach (@ARGV) { | |
if (-r $_) { | |
push(@input,$_); | |
} | |
} | |
if (!@input) { | |
die(usage()); | |
} | |
# Generate an ffmpeg command for each resolution | |
foreach my $p (@profiles) { | |
my $vid_bw = $p->[0]; | |
my $aud_bw = $p->[1]; | |
my $resolution = $p->[2]; | |
# Remove the 'p' from the resolution | |
$resolution =~ s/[a-zA-Z]//g; | |
foreach my $file (@input) { | |
my $basename = basename($file); | |
# Remove the 'k' from the bandwidth strings | |
my $vid_bw_raw = $vid_bw =~ s/[a-zA-Z]//r; | |
my $aud_bw_raw = $aud_bw =~ s/[a-zA-Z]//r; | |
my $vid_str = ($vid_bw_raw + $aud_bw_raw) . "k"; | |
# Where to put the output files | |
my $outdir = "/tmp/$basename/$vid_str/"; | |
# Make the output dir before we output to it | |
my $cmd = "mkdir -p '$outdir'"; | |
print "$cmd\n"; | |
$cmd = "ffmpeg -i '$file' -t 10000000 -vf scale=-2:$resolution,drawtext=\"text='$vid_str': fontcolor=white: fontsize=24: box=1: boxcolor=black\@0.5: boxborderw=5: x=20: y=20\" -hls_time 5 -vb $vid_bw -ab $aud_bw -hls_list_size 0 -hls_segment_filename '$outdir/file%03d.ts' '$outdir/content.m3u8'"; | |
print "$cmd\n"; | |
print "\n"; | |
} | |
} | |
sub usage { | |
return "$0 [file1.avi] [file2.mp4] [file3.mkv] ...\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment