From 45c294ceb035909b4d375560d1eba221b32ca443 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 22 Dec 2015 02:43:13 +0100 Subject: [PATCH] #3 Added config file --- .travis.yml | 2 +- CHANGELOG.md | 3 +- README.md | 7 +- ffscreencast => bin/ffscreencast | 139 +++++++++++++++++++++++------ config/ffscreencastrc | 36 ++++++++ {img => doc/img}/ffscreencast.png | Bin {img => doc/img}/ffscreencast2.png | Bin 7 files changed, 156 insertions(+), 31 deletions(-) rename ffscreencast => bin/ffscreencast (91%) create mode 100644 config/ffscreencastrc rename {img => doc/img}/ffscreencast.png (100%) rename {img => doc/img}/ffscreencast2.png (100%) diff --git a/.travis.yml b/.travis.yml index 5b3ff89..e274965 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,6 @@ before_script: - gem install mdl script: - - shellcheck --shell=bash ffscreencast + - shellcheck --shell=bash bin/ffscreencast - mdl -c .mdlrc README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 0950fd8..d7979ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ CHANGELOG Version 0.7 (unreleased) ----------- -- none yet +- [Enh] Added config file in ~/.config/ffscreencast/ffscreencastrc +- [Enh] Faster bootstrap with cache variables Version 0.6 diff --git a/README.md b/README.md index 83ac350..107adc0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Besides that `ffscreencast` can act as an ffmpeg command generator. Every available option can also just show the corresponding ffmpeg command instead of executing it. Non-ffmpeg commands, such as how the camera resolution is pulled and others can also be shown instead of being executed. -![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/img/ffscreencast.png) +![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/doc/img/ffscreencast.png) **Supported platforms** @@ -40,6 +40,7 @@ Besides that `ffscreencast` can act as an ffmpeg command generator. Every availa ## 1. Features +* Config file for default configuration * Screen recording * Camera overlay * Audio support @@ -189,8 +190,8 @@ ffmpeg -hide_banner -loglevel info -f avfoundation -i "1" -f avfoundation -i Showing screen recording with and without camera overlay. -![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/img/ffscreencast.png) -![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/img/ffscreencast2.png) +![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/doc/img/ffscreencast.png) +![Screencast](https://raw.githubusercontent.com/cytopia/ffscreencast/master/doc/img/ffscreencast2.png) ## 4. Todo diff --git a/ffscreencast b/bin/ffscreencast similarity index 91% rename from ffscreencast rename to bin/ffscreencast index f4fe8c9..bf89e35 100755 --- a/ffscreencast +++ b/bin/ffscreencast @@ -17,9 +17,9 @@ INFO_AUTHOR="Patrick Plocke " INFO_GPGKEY="0x28BF179F" -INFO_DATE="2015-12-21" +INFO_DATE="2015-12-22" INFO_LICENSE="MIT" -INFO_VERSION="0.6" +INFO_VERSION="0.7-beta" INFO_NAME="ffscreencast" @@ -137,6 +137,73 @@ isint() { printf '%d' "$1" >/dev/null 2>&1 && return 0 || return 1; } +################################################################################ +# Config +################################################################################ + +write_config() { + + local dir + local conf + dir="${HOME}/.config/ffscreencast" + conf="${dir}/ffscreencastrc" + + if [ ! -f "${conf}" ]; then + if [ ! -d "${dir}" ]; then + $(which mkdir) -p "${dir}" + fi + + echo "# ~/.config/ffscreencast/ffscreencastrc" > "${conf}" + echo >> "${conf}" + + echo "# Default video container extension" >> "${conf}" + echo "# Alternatively: 'mp4' or 'avi'" >> "${conf}" + echo "OUTPUT_EXT=\"mkv\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default audio output codec" >> "${conf}" + echo "# Alternatively: 'pcm_s16le'" >> "${conf}" + echo "OUTPUT_ACODEC=\"libfaac\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default video output codec" >> "${conf}" + echo "# Alternatively: 'libx265'" >> "${conf}" + echo "OUTPUT_VCODEC=\"libx264\"" >> "${conf}" + echo >> "${conf}" + + + echo "# Default Screen recording arguments" >> "${conf}" + echo "S_ARGS=\"\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default audio recording arguments" >> "${conf}" + echo "A_ARGS=\"-ac 2\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default camera recording arguments" >> "${conf}" + echo "C_ARGS=\"\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default misc output arguments" >> "${conf}" + echo "O_ARGS=\"-crf 0 -preset ultrafast\"" >> "${conf}" + echo >> "${conf}" + + echo "# Default recording behavior" >> "${conf}" + echo "RECORD_S=\"yes\"" >> "${conf}" + echo "RECORD_A=\"no\"" >> "${conf}" + echo "RECORD_C=\"no\"" >> "${conf}" + echo >> "${conf}" + + echo "# What listed device number has been chosen to record?" >> "${conf}" + echo "CHOSEN_S_NUM=\"\"" >> "${conf}" + echo "CHOSEN_A_NUM=\"\"" >> "${conf}" + echo "CHOSEN_C_NUM=\"\"" >> "${conf}" + echo >> "${conf}" + fi + +} + + ################################################################################ # Info Function @@ -323,38 +390,50 @@ print_requirements() { ################################################################################ # Requirements ################################################################################ - +_CACHE_CAN_USE_OS="no" can_run_on_os() { - if [ "${UNAME}" != "Linux" ] && [ "${UNAME}" != "Darwin" ]; then - # Nope - return "${EXIT_ERR}" - else - # Good :-) + if [ "${_CACHE_CAN_USE_OS}" = "yes" ]; then return "${EXIT_OK}" - fi -} - -can_use_ffmpeg() { - if [ "${UNAME}" = "Darwin" ]; then - if ! ${FFMPEG} -f avfoundation -list_devices true -i "" 2>&1 | $GREP 'AVFoundation input device' > /dev/null 2>&1; then - # Nope, no AVFoundation found in ffmpeg - return "${EXIT_ERR}" - else - # All good :-) - return "${EXIT_OK}" - fi - elif [ "${UNAME}" = "Linux" ]; then - if ! ${FFMPEG} -version 2>&1 | $GREP '\-\-enable-x11grab' > /dev/null 2>&1; then - # Nope, no x11grab found in ffmpeg + else + if [ "${UNAME}" != "Linux" ] && [ "${UNAME}" != "Darwin" ]; then + # Nope return "${EXIT_ERR}" else - # All good :-) + # Good :-) + _CACHE_CAN_USE_OS="yes" return "${EXIT_OK}" fi fi +} - # Hmm, no supported OS found, not good! - return "${EXIT_ERR}" +_CACHE_CAN_USE_FFMPEG="no" +can_use_ffmpeg() { + if [ "${_CACHE_CAN_USE_FFMPEG}" = "yes" ]; then + return "${EXIT_OK}" + else + if [ "${UNAME}" = "Darwin" ]; then + if ! ${FFMPEG} -f avfoundation -list_devices true -i "" 2>&1 | $GREP 'AVFoundation input device' > /dev/null 2>&1; then + # Nope, no AVFoundation found in ffmpeg + return "${EXIT_ERR}" + else + # All good :-) + _CACHE_CAN_USE_FFMPEG="yes" + return "${EXIT_OK}" + fi + elif [ "${UNAME}" = "Linux" ]; then + if ! ${FFMPEG} -version 2>&1 | $GREP '\-\-enable-x11grab' > /dev/null 2>&1; then + # Nope, no x11grab found in ffmpeg + return "${EXIT_ERR}" + else + # All good :-) + _CACHE_CAN_USE_FFMPEG="yes" + return "${EXIT_OK}" + fi + fi + + # Hmm, no supported OS found, not good! + return "${EXIT_ERR}" + fi } can_screen_record() { @@ -696,6 +775,14 @@ get_camera_framerate() { ################################################################################ +if [ ! -f "${HOME}/.config/ffscreencast/ffscreencastrc" ]; then + # Write default config if it does not exist + write_config +else + # If there is a config, source it as default + . "${HOME}/.config/ffscreencast/ffscreencastrc" +fi + ############################################################ # 1.) Evaluate cmd arguments ############################################################ diff --git a/config/ffscreencastrc b/config/ffscreencastrc new file mode 100644 index 0000000..4de7d9a --- /dev/null +++ b/config/ffscreencastrc @@ -0,0 +1,36 @@ +# ~/.config/ffscreencast/ffscreencastrc + +# Default video container extension +# Alternatively: 'mp4' or 'avi' +OUTPUT_EXT="mp4" + +# Default audio output codec +# Alternatively: 'pcm_s16le' +OUTPUT_ACODEC="libfaac" + +# Default video output codec +# Alternatively: 'libx265' +OUTPUT_VCODEC="libx264" + +# Default Screen recording arguments +S_ARGS="" + +# Default audio recording arguments +A_ARGS="-ac 2" + +# Default camera recording arguments +C_ARGS="" + +# Default misc output arguments +O_ARGS="-crf 0 -preset ultrafast" + +# Default recording behavior +RECORD_S="yes" +RECORD_A="no" +RECORD_C="no" + +# What listed device number has been chosen to record? +CHOSEN_S_NUM="" +CHOSEN_A_NUM="" +CHOSEN_C_NUM="" + diff --git a/img/ffscreencast.png b/doc/img/ffscreencast.png similarity index 100% rename from img/ffscreencast.png rename to doc/img/ffscreencast.png diff --git a/img/ffscreencast2.png b/doc/img/ffscreencast2.png similarity index 100% rename from img/ffscreencast2.png rename to doc/img/ffscreencast2.png