pastebin

About this pastebin

Welcome to the bulix.org / pastebin. Please don't use this pastebin for illegal purposes, defamation or kitten-squashing.

This pastebin is written using PHP and MySQL and relies on Alex Gorbatchev's syntax hhighlighter (JavaScript based). To avoid spam, you will be required to complete a small mathematical challenge when adding a new paste.

Pastebin

Private paste #67863: Shell script to concatentate mpg videos with fade-to-black transitions

#!/bin/bash

declare -a MOVIE_FRAMES

if [ -z "`echo $@`" ]; then
	cat << EOF

Usage:
        $0 input1.mpg input2.mpg [...]

The following environmental variables matter:
        FADE_FRAMES        The number of frames to fade on
                             each side of each splice
                             [DEFAULT=50]
        BLACK_PICTURE_FILE The filename of your all-black
                             image file.
                             [DEFAULT="black.png"]
	OUTPUT_FILE        The output filename.
                             [DEFAULT="output.mpg"]

Caveats:
        This script makes no attempt to make sure that
        your input files are '.mpg', that they have the
        same frame rate, that they are the same size, or any-
        thing else. You *must* do this yourself. You will
        need ffmpeg patched with the pip vhook filter for
        this to work. You will also need to a solid still
        image file with the same dimensions as your videos (see
        BLACK_PICTURE_FILE above). JPG, PNG, GIF and probably
        some other formats are fine. You should probably
        rewrite all of this, especially the text processing on
	line 57.
EOF
exit
fi

if [ -z "$BLACK_PICTURE_FILE" ]; then
	BLACK_PICTURE_FILE="black.png"
fi

if [ -z "$FADE_FRAMES" ]; then
	FADE_FRAMES=50
fi

if [ -z "$OUTPUT_FILE" ]; then
	OUTPUT_FILE="output.mpg"
fi

COUNT=1

cat << EOF


 Determining number of frames each input movie.
 This could take some time. The only way to count
 the frames is to read the entire file, transcoding
 the video is a slow but convenient way to do this
 from a shell script. It would probably be easy to
 write a frame counter with libavcodec or libavfilter.


EOF

#Get the lengths and frame rates of the movies using ffmpeg
for movie in $@; do
	ffmpeg -i $movie -qscale 255 temp_testlength.mpg 2> temp_testlength
	MOVIE_FRAMES[$COUNT]=`echo \`cat temp_testlength | tr "\015" "\012" | grep frame= | tail -n 1 | cut -d = -f 2 | cut -d 'f' -f 1\``
	rm -f temp_testlength.mpg
	COUNT=$(($COUNT+1))
done

rm -f temp_testlength

COUNT=1

#Make one big movie
cat $@ > temp_movie.mpg

COUNT=1
TOTAL_FRAMES=0

#We need to build our command into a string because we don't know how many vhooks we'll need
FFMPEG_COMMAND="ffmpeg -i temp_movie.mpg "

#Insert the transitions into the ffmpeg command
for movie in $@; do
	FFMPEG_COMMAND="$FFMPEG_COMMAND -vhook '/usr/lib/vhook/pip.so -f "$BLACK_PICTURE_FILE" -t FFFFFF -x 0 -y 0 -s $((${MOVIE_FRAMES[$COUNT]}+$TOTAL_FRAMES-$FADE_FRAMES)) -e $((${MOVIE_FRAMES[$COUNT]}+$TOTAL_FRAMES+$FADE_FRAMES)) -d $FADE_FRAMES -m 0' "
	TOTAL_FRAMES=$(($TOTAL_FRAMES+${MOVIE_FRAMES[$COUNT]}))
done

FFMPEG_COMMAND="$FFMPEG_COMMAND -sameq \"$OUTPUT_FILE\""

echo Here\'s the command we\'re running:
echo
echo $FFMPEG_COMMAND
echo
echo

#Run the command!
bash -c "$FFMPEG_COMMAND"

if [ "$?" -eq 0 ]; then
	echo
	echo Success! Output file is: $OUTPUT_FILE
	echo
else
	echo
	echo Failure. ffmpeg could not create video.
	echo
fi

rm -f temp_movie.mpg

New paste

  Language:
Private   — Wrap long lines  —  1 + 2 =   —  

30 more recent public pastes


# Title Type Date
1 Untitled ASCII paste by 195.168.200.112 ASCII 20 Nov 2008, 21:48
2 Untitled ASCII paste by 91.172.54.239 ASCII 20 Nov 2008, 21:19
3 Untitled C++ paste by 24.190.28.19 C++ 20 Nov 2008, 01:26
4 aaaaa ASCII 19 Nov 2008, 20:11
5 Untitled ASCII paste by 116.49.67.17 ASCII 19 Nov 2008, 08:11
6 Untitled ASCII paste by 24.22.59.84 ASCII 19 Nov 2008, 00:25
7 Python xlutils Filters Python 19 Nov 2008, 00:09
8 Untitled ASCII paste by 85.195.3.209 ASCII 18 Nov 2008, 22:04
9 Untitled ASCII paste by 85.195.3.209 ASCII 18 Nov 2008, 22:02
10 Untitled ASCII paste by 86.138.25.57 ASCII 18 Nov 2008, 13:49
11 Untitled XML/HTML paste by 90.227.235.228 XML/HTML 18 Nov 2008, 13:37
12 xorg.conf ASCII 18 Nov 2008, 07:35
13 Untitled PHP paste by 168.120.50.72 PHP 17 Nov 2008, 05:53
14 Untitled ASCII paste by 76.106.0.187 ASCII 17 Nov 2008, 02:39
15 Common Functions PHP 17 Nov 2008, 01:19
16 Untitled PHP paste by 76.106.0.187 PHP 17 Nov 2008, 01:05
17 Untitled PHP paste by 76.106.0.187 PHP 17 Nov 2008, 00:57
18 Login PHP 17 Nov 2008, 00:55
19 Untitled Visual Basic paste by 217.211.80.109 Visual Basic 16 Nov 2008, 21:58
20 Untitled ASCII paste by 64.198.244.3 ASCII 16 Nov 2008, 20:34
21 Untitled ASCII paste by 64.198.244.3 ASCII 16 Nov 2008, 20:28
22 nvidia make log ASCII 15 Nov 2008, 15:33
23 Untitled ASCII paste by 86.164.113.159 ASCII 13 Nov 2008, 23:27
24 Untitled Java paste by 87.194.35.141 Java 13 Nov 2008, 16:43
25 Untitled ASCII paste by 82.243.231.30 ASCII 12 Nov 2008, 02:36
26 Untitled ASCII paste by 76.178.26.234 ASCII 11 Nov 2008, 23:34
27 java version ASCII 11 Nov 2008, 23:31
28 Untitled C++ paste by 86.129.206.36 C++ 11 Nov 2008, 22:51
29 Untitled C++ paste by 86.129.206.36 C++ 11 Nov 2008, 22:42
30 Untitled ASCII paste by 76.121.208.173 ASCII 11 Nov 2008, 13:00

Powered by the Bulix.org Code Pastebin, by Maxime Petazzoni. View pastebin statistics.