Last active
August 29, 2015 13:56
-
-
Save jaehwang/8845282 to your computer and use it in GitHub Desktop.
LG TV 타임머신으로 녹화한 동영상을 MP4로 변환하기.
This file contains hidden or 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 Getopt::Std; | |
use File::Basename; | |
my %opts; | |
getopts('i:t:s:e:mh',\%opts); | |
my $mts = $opts{i}; | |
my $stime = $opts{s}; | |
my $etime = $opts{e}; | |
my $mobile = $opts{m}; | |
sub usage_exit | |
{ | |
my $st = shift; | |
print <<HELP; | |
$0 -i input [-t title] [-s h:m:s] [-e h:m:s] [-m] | |
-i input filename | |
-t title | |
-s start time | |
-e end time | |
-m suitable for mobile devices | |
HELP | |
exit $st; | |
} | |
usage_exit(0) if $opts{h}; | |
unless ($mts && -f $mts) { | |
print "No such input file: $mts\n"; | |
usage_exit(1); | |
} | |
my ($name,$path,$ext) = fileparse($mts, '.ts') if $mts; | |
$name = $opts{t} if $opts{t}; | |
my @cmd = ('ffmpeg','-y','-i', $mts); | |
my $stime_sec = 0; | |
my $etime_sec = -1; | |
if ($stime =~ /(\d+):(\d+):(\d+)/) { | |
$stime_sec = $1*3600 + $2*60 + $3; | |
push @cmd, ('-ss', $stime_sec); | |
} | |
if ($etime =~ /(\d+):(\d+):(\d+)/) { | |
$etime_sec = $1*3600 + $2*60 + $3 - $stime_sec; | |
if ($etime_sec < 1) { | |
print "End time must be later than start time!\n"; | |
usage_exit(1); | |
} | |
push @cmd, ('-t', $etime_sec); | |
} | |
if ($mobile) { | |
push @cmd, | |
('-threads', 0, '-vcodec', 'libx264', '-preset', 'medium', | |
'-vb', '1100k', '-x264opts', '8x8dct=0:weightp=0', | |
'-sws_flags', 'lanczos', | |
'-vf', | |
'yadif=0:-1, crop=in_w-2*16:in_h-2*16, scale=768:432, setsar=1:1', | |
'-r', '30000/1001', '-acodec', 'aac', | |
'-strict', 'experimental', '-ab', '192k', '-ac', 2, | |
$name.'.432p_30fps.x264_1100k.aac_160k.ipad.mobile.mp4'); | |
} else { | |
push @cmd, ('-vcodec', 'libx264', '-acodec', 'copy', $name.'.x264.mp4'); | |
} | |
print join(' ', @cmd),"\n"; | |
open my $fh, '-|', @cmd; | |
while (my $line = <$fh>) { | |
print $line; | |
} | |
close $fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment