From: p2p p2p-next-02 Date: Mon, 28 Mar 2011 11:15:02 +0000 (+0300) Subject: video handling scripts reform: unique all file conversion script; renaming; old scrip... X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=cf141e97f6aaf93699b07ec844f5143b260fbede;hp=f159138ee46507e6e5c3dacfd2ff43801a6bed81;p=video-handling.git video handling scripts reform: unique all file conversion script; renaming; old scripts are in 'old' --- diff --git a/cut-mts b/cut-mts new file mode 100755 index 0000000..834242e --- /dev/null +++ b/cut-mts @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script cuts .mts video file starting from a seek point +# with a desired duration. Seek point and duration are expressed in +# seconds or in the hh:mm:ss[.xx] format. +# + +if test $# -ne 4; then + echo "Usage: $0 mts-input-file mts-output-file seek-point duration" + exit 1 +fi + +MTS_IN="$1" +MTS_OUT="$2" +SEEK_POINT="$3" +DURATION="$4" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_IN"; then + echo "Error: No such file $MTS_IN" + exit 1 +fi + +"$FFMPEG" -ss "$SEEK_POINT" -t "$DURATION" -i "$MTS_IN" -f mpegts -acodec copy -vcodec copy "$MTS_OUT" diff --git a/extract-thumbnail b/extract-thumbnail new file mode 100755 index 0000000..92e4a1d --- /dev/null +++ b/extract-thumbnail @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script extracts a thumbnail from a random frame of a video file. +# +# + +if test $# -ne 3; then + echo "Usage: $0 input-video output-image resolution" + exit 1 +fi + +IN="$1" +OUT="$2" +RESOLUTION="$3" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$IN"; then + echo "Error: No such file $IN" + exit 1 +fi + +# Choose a random frame +DURATION=$(mediainfo --Inform="General;%Duration%" "$IN" | cut -d"." -f1) +SEEK_POINT=$(($DURATION * $RANDOM / 32767 / 1000)) + +"$FFMPEG" -i "$IN" -ss "$SEEK_POINT" -vframes 1 -s "$RESOLUTION" -f image2 "$OUT" diff --git a/extract-thumbnails-all b/extract-thumbnails-all new file mode 100755 index 0000000..4aed477 --- /dev/null +++ b/extract-thumbnails-all @@ -0,0 +1,30 @@ +#!/bin/bash +# +# 2010, Calin-Andrei Burloiu, calin.burloiu@gmail.com +# +# This scripts creates thumbnails for all videos with a specified suffix. +# +# + +if [ $# -ne 2 ]; then + echo "usage: $0 root_path suffix" + exit 1 +fi + +root_path="$1" +suffix="$2" + +( +IFS=$'\n' +for filename in $(find "$root_path" -name "*$suffix"); do + new_filename=$(dirname "$filename")/$(basename "$filename" "$suffix")_tmp.jpg + new_filename1=$(dirname "$filename")/$(basename "$filename" "$suffix")_small.jpg + new_filename2=$(dirname "$filename")/$(basename "$filename" "$suffix")_big.jpg + rm -f "$new_filename1" + rm -f "$new_filename2" + ./ffmpeg-extract-thumbnail "$filename" "$new_filename" 1280x720 + ffmpeg -i "$new_filename" -s 122x69 -f image2 "$new_filename1" + ffmpeg -i "$new_filename" -s 149x84 -f image2 "$new_filename2" + rm -f "$new_filename" +done +) diff --git a/old/ffmpeg-all-mts2avi b/old/ffmpeg-all-mts2avi new file mode 100755 index 0000000..cacebf4 --- /dev/null +++ b/old/ffmpeg-all-mts2avi @@ -0,0 +1,20 @@ +#!/bin/bash +# +# 2010, Calin-Andrei Burloiu, calin.burloiu@gmail.com +# +# This scripts converts all mts files to avi starting from a root directory +# recursively. The avi files are placed in the same directory as the +# original mts files. +# + +if [ $# -ne 1 ]; then + echo "usage: $0 root_path" +fi + +root_path="$1" + +for i in $(find "$root_path" -name "*.mts"); do + #echo $(dirname $i)/$(basename $i .mts).avi + ./ffmpeg-mts2avi "$i" "$(dirname $i)/$(basename $i .mts).avi" + +done diff --git a/old/ffmpeg-all-mts2avi-custom b/old/ffmpeg-all-mts2avi-custom new file mode 100755 index 0000000..2a6a8d0 --- /dev/null +++ b/old/ffmpeg-all-mts2avi-custom @@ -0,0 +1,23 @@ +#!/bin/bash +# +# 2010, Calin-Andrei Burloiu, calin.burloiu@gmail.com +# +# This scripts converts all mts files to avi starting from a root directory +# recursively. The avi files are placed in the same directory as the +# original mts files. +# + +if [ $# -ne 1 ]; then + echo "usage: $0 root_path" +fi + +root_path=$1 + +( +IFS=$'\n' +for filename in $(find "$root_path" -name '*.mts'); do + new_filename=$(dirname "$filename")/$(basename "$filename" .mts).avi + rm "$new_filename" + ./ffmpeg-mts2avi-custom "$filename" "$new_filename" 800x600 +done +) diff --git a/old/ffmpeg-all-mts2mp4-custom b/old/ffmpeg-all-mts2mp4-custom new file mode 100755 index 0000000..a11333a --- /dev/null +++ b/old/ffmpeg-all-mts2mp4-custom @@ -0,0 +1,26 @@ +#!/bin/bash +# +# 2010, Calin-Andrei Burloiu, calin.burloiu@gmail.com +# +# This scripts converts all mts files to avi starting from a root directory +# recursively. The avi files are placed in the same directory as the +# original mts files. +# + +if [ $# -ne 1 ]; then + echo "usage: $0 root_path" +fi + +root_path="$1" + +#resolution=960x720 # HD +resolution=800x600 # SD + +( +IFS=$'\n' +for filename in $(find "$root_path" -name '*.mts'); do + new_filename=$(dirname "$filename")/$(basename "$filename" .mts)_SD.mp4 + rm "$new_filename" + ./ffmpeg-mts2mp4-custom "$filename" "$new_filename" $resolution 700k +done +) diff --git a/old/ffmpeg-mts2avi b/old/ffmpeg-mts2avi new file mode 100755 index 0000000..6721e44 --- /dev/null +++ b/old/ffmpeg-mts2avi @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an AVI file, which +# contains an H.264 video stream and and an MP3 audio stream. +# + +if test $# -ne 2; then + echo "Usage: $0 mts-file avi-file" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such: file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f avi -acodec libmp3lame -ab 256k -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b 1400k -r 25 -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2avi-custom b/old/ffmpeg-mts2avi-custom new file mode 100755 index 0000000..232471c --- /dev/null +++ b/old/ffmpeg-mts2avi-custom @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an AVI file, which +# contains an H.264 video stream and and an MP3 audio stream. +# + +if test $# -ne 4; then + echo "Usage: $0 mts-file avi-file resolution bitrate" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +RESOLUTION="$3" +BITRATE="$4" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such: file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f avi -acodec libmp3lame -ab 256k -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$BITRATE" -r 25 -s $RESOLUTION -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2flv-custom b/old/ffmpeg-mts2flv-custom new file mode 100755 index 0000000..ee9c2f8 --- /dev/null +++ b/old/ffmpeg-mts2flv-custom @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an AVI file, which +# contains an H.264 video stream and and an MP3 audio stream. +# + +if test $# -ne 3; then + echo "Usage: $0 mts-file avi-file resolution" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +RESOLUTION="$3" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such: file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f flv -acodec libmp3lame -ab 256k -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b 1400k -r 25 -s $RESOLUTION -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2mp4-custom b/old/ffmpeg-mts2mp4-custom new file mode 100755 index 0000000..334407a --- /dev/null +++ b/old/ffmpeg-mts2mp4-custom @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an AVI file, which +# contains an H.264 video stream and and an MP3 audio stream. +# + +if test $# -ne 4; then + echo "Usage: $0 mts-file avi-file resolution bitrate" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +RESOLUTION="$3" +BITRATE="$4" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such: file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f mp4 -acodec libmp3lame -ab 192k -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$BITRATE" -r 25 -s "$RESOLUTION" -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2ogg b/old/ffmpeg-mts2ogg new file mode 100755 index 0000000..ce30094 --- /dev/null +++ b/old/ffmpeg-mts2ogg @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an WebM file, which +# contains a V8 video stream and and a Vorbis audio stream. +# + +if test $# -ne 2; then + echo "Usage: $0 mts-file avi-file" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f ogg -acodec libvorbis -ab 256k -ar 44100 -ac 2 -vcodec libtheora -b 1400k -r 25 -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2ogg-custom b/old/ffmpeg-mts2ogg-custom new file mode 100755 index 0000000..817d5d5 --- /dev/null +++ b/old/ffmpeg-mts2ogg-custom @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an WebM file, which +# contains a V8 video stream and and a Vorbis audio stream. +# + +if test $# -ne 4; then + echo "Usage: $0 mts-file avi-file resolution bitrate" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +RESOLUTION="$3" +BITRATE="$4" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f ogg -acodec libvorbis -ab 256k -ar 44100 -ac 2 -vcodec libtheora -b "$BITRATE" -r 25 -s $RESOLUTION -threads 0 "$AVI_FILE" + diff --git a/old/ffmpeg-mts2ts-custom b/old/ffmpeg-mts2ts-custom new file mode 100755 index 0000000..34e8361 --- /dev/null +++ b/old/ffmpeg-mts2ts-custom @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an AVI file, which +# contains an H.264 video stream and and an MP3 audio stream. +# + +if test $# -ne 4; then + echo "Usage: $0 mts-file ts-file bitrate resolution" + exit 1 +fi + +MTS_FILE="$1" +TS_FILE="$2" +BITRATE="$3" +RESOLUTION="$4" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such: file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f mpegts -acodec libmp3lame -ab 128k -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$BITRATE" -r 25 -s $RESOLUTION -threads 0 "$TS_FILE" diff --git a/old/ffmpeg-mts2webm b/old/ffmpeg-mts2webm new file mode 100755 index 0000000..6d5ddaf --- /dev/null +++ b/old/ffmpeg-mts2webm @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script converts an MTS file into an WebM file, which +# contains a V8 video stream and and a Vorbis audio stream. +# + +if test $# -ne 2; then + echo "Usage: $0 mts-file avi-file" + exit 1 +fi + +MTS_FILE="$1" +AVI_FILE="$2" +FFMPEG=/usr/bin/ffmpeg + +if test ! -f "$MTS_FILE"; then + echo "Error: No such file $MTS_FILE" + exit 1 +fi + +$FFMPEG -i "$MTS_FILE" -f webm -acodec libvorbis -ab 256k -ar 44100 -ac 2 -vcodec libvpx -b 1400k -r 25 -threads 0 "$AVI_FILE" + diff --git a/transcode-all b/transcode-all new file mode 100755 index 0000000..66f6ca6 --- /dev/null +++ b/transcode-all @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# +# This script transcodes all input videos with a specified extension to a new +# format with a given resolutin and video bitrate. The audio bitrate is hard +# coded to 192 kb/s. The output_path parameter is optional. If not given it +# puts all output files in the same folder as the corresponding input. +# + +if test $# -lt 4; then + echo "Usage: $0 input-path input-extension output-format resolution video-bitrate [output-suffix] [output_path]" + exit 1 +fi + +in_path="$1" +in_ext="$2" +out_format="$3" +resolution="$4" +bitrate="$5" +if [ ! -z "$6" ]; then + out_suffix="$6" +else + out_suffix="" +fi +if [ ! -z "$7" ]; then + out_path="$7" +fi + +FFMPEG=/usr/bin/ffmpeg +ABITRATE=192k + +( +IFS=$'\n' +for filename in $(find "$in_path" -name "*.$in_ext"); do + if [ ! -z "$out_path" ]; then + new_filename="${out_path}"$(basename "$filename" ."$in_ext")"$out_suffix"."$out_format" + else + new_filename=$(dirname "$filename")/$(basename "$filename" ."$in_ext")"$out_suffix"."$out_format" + fi + + case "$out_format" in + "avi" ) + $FFMPEG -i "$filename" -f avi -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename" + ;; + "flv" ) + $FFMPEG -i "$filename" -f flv -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename" + ;; + "mp4" ) + $FFMPEG -i "$filename" -f mp4 -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s "$resolution" -threads 0 "$new_filename" + ;; + "ogg" ) + $FFMPEG -i "$filename" -f ogg -acodec libvorbis -ab $ABITRATE -ar 44100 -ac 2 -vcodec libtheora -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename" + ;; + "webm" ) + $FFMPEG -i "$filename" -f webm -acodec libvorbis -ab $ABITRATE -ar 44100 -ac 2 -vcodec libvpx -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename" + ;; + "ts" ) + $FFMPEG -i "$filename" -f mpegts -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename" + ;; + + * ) + echo "Format $out_format is not implemented!" 1>&2 + exit 1 + ;; + esac + +done +)