videoshell is a standalone shell script to transform MTS videos in the FLV or AVI formats. Tests were implemented and proposed to the author.
test framework
Since there are no wide spread tests framework for shell scripts, it was decided to embed the tests within the script itself. The -test option was added : it calls the test_all function that will execute all the test functions in trace mode:
set -xe PS4=' ${FUNCNAME[0]}: $LINENO: '
The script is divided into functions that makes it easier to prepare for tests. The option parsing was encapsulated in a run function so that it could be called multiple time during the tests. The only line that is not in a function is the call to the run function itself:
run "$@"
A sample source video was added to the repository by Thomas Monjalon earlier this week to be used by tests. If the file is not available, some tests will be disabled:
MTS=tests/avchd-lite-tz7.mts if [ -f $MTS ] ; then test_menu $MTS test_flv $MTS test_avi $MTS else printf "skip some tests because $MTS is not a file" fi
testing interactive mode
With the -i option, videoshell will display an interactive menu.
avchd-lite-tz7.mts -> avchd-lite-tz7.flv 1) format = FLV 2) file name = short 3) audio bitrate = 32 Kbps 4) video bitrate = 600 Kbps 5) video width = 500 pixels 6) video crop = 7) video rotate = 8) simple cut = 9) live cuts = e) encoder = ffmpeg p) play mode = normal size i) play input t) transform q) quit > 5 width = 500
The tests simulate the user input with echo and pipe them to the menu function. When doing this, the menu function runs in a sub shell and will not be able to set the variables of the calling shell. The variable to be checked (WIDTH in the following) is displayed for checking in the parent:
test_menu () { INPUT=$1 INPUT_EXT=mts OUTPUT_EXT=flv get_tools_defaults get_output_defaults local width=250 [ $( ( echo -n 5 ; echo $width ; echo -n q ) | ( menu > /dev/null ; echo $WIDTH ) ) = $width ] }
realistic tests
If the mts file is available, it is transformed into an flv and avi file. A sanity check (the width of the output video) is done with ffprobe on the result to check that a video file has been created.
local width=250 run -width $width $mts flv [ $(ffprobe -show_format $OUTPUT 2>/dev/null | perl -ne 'print $1 if(/TAG:width=(\d+)/)') = $width ]
bash dependency
The interactive mode relies on a read bashism. The hash line was upgraded to
#!/bin/bash -e
as a warning.
contributing
A clone was made on gitorious and the changes were submitted in a merge request to the videoshell repository.
licensing
Thomas Monjalon decided to distribute the software under the GPLv3+ license. It was done by adding a copyright notice (as found at the end of the license itself) in the header of the script, together with the names of the authors.