source: gs2-extensions/video-and-audio/trunk/src/bin/script/video_splitter.pl@ 29646

Last change on this file since 29646 was 29646, checked in by jmt12, 9 years ago

Example script for splitting TS video files into 10 minute segments (initial creation of bin/script directory too)

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6print "\n===== Split up HD Video =====\n";
7print "Splits any TS files found in the given directory into 600 second\n";
8print "segments. Requires FFMPEG.\n\n";
9
10if (!defined $ARGV[0] || !-d $ARGV[0])
11{
12 print "usage: video_splitter.pl <dir with ts files>\n";
13 exit();
14}
15
16opendir(DH, $ARGV[0]) or die("Failed to open directory for reading: " . $ARGV[0]);
17my @files = readdir(DH);
18closedir(DH);
19my $counter = 0;
20foreach my $file (@files)
21{
22 if ($file =~ /^(.*)\.ts$/)
23 {
24 my $file_prefix = $1;
25 print " * Processing: " . $file . "\n";
26 my $path = $ARGV[0] . '/' . $file;
27 my $mediainfo_command = 'mediainfo --Inform="Video;%Duration/String%" "' . $path . '"';
28 my $raw_duration = `$mediainfo_command`;
29 my $duration = 0;
30 if ($raw_duration =~ /(\d+)h/)
31 {
32 $duration += $1 * 60;
33 }
34 if ($raw_duration =~ /(\d+)mn/)
35 {
36 $duration += $1;
37 }
38 print " - video is $duration minutes\n";
39 if ($duration > 0)
40 {
41 my $offset = 0;
42 my $step = 10;
43 while (($offset < 60) && ($offset + $step < $duration))
44 {
45 $counter++;
46 my $output_file = sprintf($file_prefix . '-%03d.ts', $counter);
47 my $output_path = $ARGV[0] . '/' . $output_file;
48 my $ffmpeg_command = sprintf('ffmpeg -ss 00:%02d:00 -t 600 -i "%s" -vcodec copy -acodec copy -scodec copy "%s" > /dev/null 2>&1', $offset, $path, $output_path);
49 print " - cmd: $ffmpeg_command\n";
50 print " - generating " . $output_file . "\n";
51 `$ffmpeg_command`;
52 #rint "DEBUG: $result\n\n";
53 $offset += $step;
54 }
55 }
56 }
57}
58print "Complete!\n\n";
59exit;
601;
Note: See TracBrowser for help on using the repository browser.