media/multimedia/ VlcPlaylistStuff
Making clip playlists
Here are a couple of Python scripts for making m3u lists of clips.
Script 1: generate m3u from files and times
The first, following the example from http://scriptun.com/other/m3u, takes input files with lines in the form
/path/to/video.mp4|from|to|num
/path/to/video.mp4|from|+dur|num
/path/to/video2.mp4|from
/path/to/video2.mp4|from|+dur
where the +dur
adds the 'from' value to dur to calculate the stop time. This generates m3u files in the format
#EXTM3U
#EXTINFO:-1,video.mp4
#EXTVLCOPT:start-time=10.000000
#EXTVLCOPT:stop-time=20.000000
#EXTVLCOPT:input-repeat=3
/path/to/video.mp4
#EXTINFO:-1,video2.mp4
#EXTVLCOPT:start-time=300.000000
#EXTVLCOPT:stop-time=305.000000
/path/to/video2.mp4
which you can then play with Vlc. The script (a bit of quickndirty perl) is:
#!/usr/bin/perl
# name|from|to|repeat
# name|from|+dur|repeat
# from,to/+dur,repeat are optional
@input = ();
for $a(@ARGV) {
open F, "$a";
push @input, <F>;
close F;
}
@output = ("#EXTM3U");
for $a(@input) {
chomp $a;
next if $a =~ /^#/;
@b = split "\\|", $a;
$c = $b[0];
@c = split "/", $c;
$f = $c[$#c];
push @output, "#EXTINFO:-1,$f";
$s = 0;
$t = 0;
$r = 0;
if(int(@b) >= 2) {
$s = sprintf "%f", $b[1];
push @output, "#EXTVLCOPT:start-time=$s";
}
if(int(@b) >= 3) {
$x = $b[2];
if($x =~ /^\+(.*)$/) {
$x = $s + $1;
}
$t = sprintf "%f", $x;
push @output, "#EXTVLCOPT:stop-time=$t";
}
if(int(@b) >= 4) {
$r = int($b[3]);
push @output, "#EXTVLCOPT:input-repeat=$r";
}
if(int(@b) >= 1) {
push @output, "$c";
}
}
print "".(join "\n",@output)."\n";
Script 2: generate input for Script 1, for multiple clips from one file
If you have a file from which you want multiple clips, e.g. /path/to/video.mp4
, you specify the file on the first line, and the options on later lines. Thus
/path/to/video.mp4
|607|1034
|2723|2852
|3188|3263
becomes
/path/to/video.mp4|607|1034
/path/to/video.mp4|2723|2852
/path/to/video.mp4|3188|3263
Basically this simply produces the output file by taking each line after the first, appending it to the first line, and printing the result out. The script is:
#!/usr/bin/perl
$a = <STDIN>; chomp $a;
for(<STDIN>) { print "$a$_"; }
In this case, send the input to stdin, and the output is printed to stdout.
Notes
Both scripts as written take a list of input files as arguments, and write the output to stdout. This is easy enough for any competent perl scripter to change. One could easily rewrite this in Python3, or a more modern language, but for scripts such as this, I find Perl's many shorthands too useful to ignore (I get the initial sketch script written quicker).