Skip to content

Commit 14339ab

Browse files
committed
more mpeg2 cutlist stuff from Gavin
1 parent 0205091 commit 14339ab

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

trunk/export_MPEG2_cut.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ package export_MPEG2_cut;
8484
return 0;
8585
}
8686

87-
my $command = "mpeg2cut $main::video_dir/$self->{episode}->{filename} $safe_outfile ";
87+
my $command = "mpeg2cut $main::video_dir/$self->{episode}->{filename} $safe_outfile $self->{episode}->{lastgop} ";
8888

8989
@cuts = split("\n",$self->{episode}->{cutlist});
9090
my @skiplist;

trunk/mpeg2cut

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Prerequisites:
77
# avidemux2 - http://fixounet.free.fr/avidemux/
88
# transcode - http://zebra.fh-weingarten.de/~transcode/
9-
# lvemux - http://lvempeg.sourceforge.net/
9+
# lvemux - http://lvempeg.sourceforge.net/
1010
# gdk2-cursed - http://zemljanka.sourceforge.net/cursed/
1111
#
1212
# Usage: mpeg2cut inputfile outputfile segmentList
@@ -16,58 +16,107 @@
1616
export LD_PRELOAD=libgdk-cursed-2.0.so:libgtk-cursed-2.0.so
1717

1818
FILENAME=$1
19-
OUTFILE=$2
2019
BASENAME=`basename ${FILENAME} .nuv`
20+
OUTFILE=$2
21+
LASTGOP=$3
22+
23+
# get the largest numbered mark of type 6 * (15 NTSC or 12 PAL), that's the
24+
# last GOP frame
2125

2226
echo Filename \"${FILENAME}\"
2327
echo OutFile \"${OUTFILE}\"
2428

25-
shift
26-
shift
29+
shift 3
2730
CUTLIST=$*
2831

32+
echo Last GOP index ${LASTGOP}
2933
echo Cutlist \"${CUTLIST}\"
3034

35+
echo -n Finding the AV Offset to use with lvemux:
36+
OFFSET=`(tcprobe -i ${FILENAME} 2> /dev/null) | grep av_fine_ms | \
37+
sed -e 's/^.*av_fine_ms //' | cut -d " " -f 1`
38+
OFFSET=$((-1 * ${OFFSET}))
39+
echo ${OFFSET}
40+
41+
echo -n Finding framerate:
42+
FRAMERATE=`(tcprobe -i ${FILENAME} 2> /dev/null) | grep "frame rate" | \
43+
sed -e 's/^.*-f //' | cut -d " " -f 1`
44+
echo ${FRAMERATE}
45+
46+
if [ .${FRAMERATE}. = .25.000. ]
47+
then
48+
GOPSPACE=12
49+
else
50+
GOPSPACE=15
51+
fi
52+
53+
LASTFRAME=$(( ${LASTGOP} * ${GOPSPACE} ))
54+
echo Last Frame ${LASTFRAME}
55+
3156
if [ ! -f ${FILENAME}.idx ]
3257
then
58+
echo Indexing the file with avidemux2
3359
nice -n 19 avidemux2 --index-mpeg ${FILENAME} ${FILENAME}.idx C0 \
34-
--audio-codec MP2 --quit 2> /dev/null
60+
--audio-codec MP2 --quit 2> /dev/null > /dev/null
3561
fi
3662

37-
OFFSET=`(tcprobe -i ${FILENAME} 2> /dev/null) | grep av_fine_ms | \
38-
sed -e 's/^.*av_fine_ms //' | cut -d " " -f 1`
3963

40-
count=0
41-
SLICELIST=""
64+
cat > ${BASENAME}.cut << EOF
65+
ADMW0002
66+
01 videos
67+
Name : ${FILENAME}.idx
68+
EOF
4269

70+
cat /dev/null > ${BASENAME}.cut2
71+
72+
count=0
4373
for i in ${CUTLIST}
4474
do
4575
START=`echo $i | cut -d '-' -f 1`
4676
END=`echo $i | cut -d '-' -f 2`
47-
SLICE=${BASENAME}_${count}
4877

49-
if [ .${START}. != .. ]
78+
if [ .${START}. = .. ]
5079
then
51-
START="--begin ${START}"
80+
START=0
5281
fi
5382

54-
if [ .${END}. != .. ]
83+
if [ ${START} -ge ${LASTFRAME} ]
5584
then
56-
END="--end ${END}"
85+
continue
5786
fi
5887

59-
nice -n 19 avidemux2 --load ${FILENAME} ${START} ${END} \
60-
--audio-codec MP2 --save-raw-video ${SLICE}.m2v \
61-
--save-raw-audio ${SLICE}.mp2 --quit 2> /dev/null
62-
nice -n 19 lvemux -sh $((-1 * ${OFFSET})) -v ${SLICE}.m2v \
63-
-a ${SLICE}.mp2 -o ${SLICE}.mpg
64-
rm ${SLICE}.m2v ${SLICE}.m2v.idx ${SLICE}.mp2
88+
if [ .${END}. = .. ]
89+
then
90+
END=${LASTFRAME}
91+
fi
92+
LENGTH=$((${END} - ${START} + 1))
6593

66-
SLICELIST="${SLICELIST} ${SLICE}.mpg"
94+
cat >> ${BASENAME}.cut2 << EOF
95+
Start : ${START}
96+
Size : ${LENGTH}
97+
Ref : 0
98+
EOF
6799
count=$((${count} + 1))
68100
done
101+
echo ${count} segments >> ${BASENAME}.cut
102+
103+
cat ${BASENAME}.cut2 >> ${BASENAME}.cut
104+
cat >> ${BASENAME}.cut << EOF
105+
Audio codec : none
106+
Audio filter : audioNormalizeMode=0 audioResampleMode=0 audioDRC=0 audioShift=0
107+
audioDelay=0 audioFreq=48000
108+
Audio conf : audioProcessMode=0 audioMP3mode=0 audioMP3bitrate=128
109+
EOF
110+
111+
echo Cutting out commercials with avidemux2
112+
nice -n 19 avidemux2 --load-workbench ${BASENAME}.cut \
113+
--audio-codec MP2 --save-raw-video ${BASENAME}.m2v \
114+
--save-raw-audio ${BASENAME}.mp2 --quit 2> /dev/null > /dev/null
115+
116+
echo Remultiplexing video
117+
nice -n 19 lvemux -r -1 -v ${BASENAME}.m2v -a ${BASENAME}.mp2 -o "${OUTFILE}"
69118

70-
echo Concatenating ${count} segments
71-
nice -n 19 cat ${SLICELIST} > ${OUTFILE}
72-
rm ${SLICELIST} ${FILENAME}.idx
119+
echo Cleaning up
120+
rm ${FILENAME}.idx ${BASENAME}.m2v ${BASENAME}.mp2 ${BASENAME}.m2v.idx
121+
rm ${BASENAME}.cut ${BASENAME}.cut2
73122

trunk/nuvexport

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
245245

246246
# Parse out the record data for each file
247247
$q = "SELECT title, subtitle, description, hostname, cutlist FROM recorded WHERE chanid=? AND starttime=? AND endtime=?";
248+
my $q2 = "SELECT mark FROM recordedmarkup WHERE chanid=? AND starttime=? AND type=6 ORDER BY mark DESC LIMIT 1";
249+
248250
$sh = $dbh->prepare($q);
251+
my $sh2 = $dbh->prepare($q2);
252+
249253
foreach $file (@Files) {
250254
next unless ($file =~ /\.nuv$/);
251255
# Pull out the various parts that make up the filename
@@ -263,6 +267,10 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
263267
my ($show, $episode, $description, $show_hostname, $cutlist) = $sh->fetchrow_array;
264268
# Unknown file - someday we should report this
265269
next unless ($show);
270+
271+
$sh2->execute($channel, "$syear$smonth$sday$shour$sminute$ssecond")
272+
or die "Could not execute ($q2): $!\n\n";
273+
my ($lastgop) = $sh2->fetchrow_array;
266274
#$description =~ s/(?:''|``)/"/sg;
267275
push @{$Shows{$show}}, {'filename' => $file,
268276
'channel' => $channel,
@@ -274,6 +282,7 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
274282
'description' => ($description or 'No Description'),
275283
'hostname' => $show_hostname,
276284
'cutlist' => $cutlist,
285+
'lastgop' => $lastgop,
277286
'showtime' => generate_showtime($syear, $smonth, $sday, $shour, $sminute, $ssecond)};
278287
}
279288
$sh->finish();

0 commit comments

Comments
 (0)