Skip to content

Instantly share code, notes, and snippets.

View zipizap's full-sized avatar

zipizap

View GitHub Profile
#!/bin/bash
[[ -r $1 ]] || { echo "Usage: $0 <videofile-to-be-resized> [<videofile2> ...]"; exit 1; }
for INPUT_FILE in $@; do
OUTPUT_MP4_FILE=$(echo $INPUT_FILE | sed 's/\.[^.]*$/.mp4/g')
#See https://trac.ffmpeg.org/wiki/x264EncodingGuide
avconv -y -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 1 -an -f mp4 /dev/null && \
avconv -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 2 -c:a libmp3lame -b:a 192k $OUTPUT_MP4_FILE
rm -f av2pass* &>/dev/null
@zipizap
zipizap / du_sort.sh
Created December 10, 2013 10:04
Solaris "du" does not have the option "--max-depth=1", and this simple script eases a little bit of that pain... Output is shown in Kb and sorted by size
du -k . | egrep -v '\/.*\/' | sort -n
red@ownc:/tmp$ cat a.sh
#!/bin/bash
# Activate debug
set -x
echo "hi"
ls
pwd
@zipizap
zipizap / gist:7947933
Last active December 31, 2015 06:29
Understanding better strace, in order to write up a good reply to C Evans comment :)
#
# This gist is related to C Evan's comment on
# http://zipizap.wordpress.com/2012/10/15/xkl-ubuntu-install-resizing-ntfs-partition-takes-too-long-check-ntfsresize-from-console-with-strace/
#
# Hi Evans :)
#
# I see what you mean: only strace the writes to stdout, and not all writes that
# also contain moved data of the resize... And it got me interested in better understanding
# the strace options, so I did a little "man strace" study and then a little program in C
@zipizap
zipizap / bash_local_variables
Created February 11, 2014 13:04
bash - global variables vs local variables
#!/usr/bin/env bash
# In bash all variables are defined by default as GLOBAL, even if defined inside functions
# To define a variable as LOCAL to a function, we have to prepend "local" in the definition
# This makes the variable only defined in the current function scope and so not global.
VAR_GLOBAL="im global - you can read and change me from anywhere, even inside functions - which may not always be a good thing"
echo "Seen from outside: $VAR_GLOBAL"
function my_func {
@zipizap
zipizap / run_as_user.sh
Last active August 29, 2015 13:56
bash function to run command as another user
function run_as_user {
local NEW_USER=$1
local CMDS=$2
sudo -u $NEW_USER -i bash -l -c "$CMDS"
}
#Use it like
run_as_user luke "echo $PWD; id"
@zipizap
zipizap / parse_multiple_args_in_bash_example.sh
Last active August 29, 2015 14:04
Example of how to parse mutliple arguments in bash
#!/bin/bash
[[ $# -gt 1 ]] || { echo "Usage: $0 <arg1> <arg2> ... <argN>"; exit 255; }
echo 'Dont forget to surround the "$@" with the double-quotes '' so that it does not divide arguments that contain spaces.'
echo 'Samewise, you also need to surround the "$ARG_I" var'
for ARG_I in "$@"; do
echo '$@ = '"$@"
echo '$ARG_I = '"$ARG_I"
done
@zipizap
zipizap / compress_video.sh
Created August 17, 2014 09:01
compress a video using avconv
#!/bin/bash
[[ -r $1 ]] || { echo "Usage: $0 <videofile-to-be-resized> [<videofile2> ...]"; exit 1; }
for INPUT_FILE in "$@"; do
OUTPUT_MP4_FILE=$(echo "$INPUT_FILE" | sed 's/\.[^.]*$/_resized.mp4/g')
#See https://trac.ffmpeg.org/wiki/x264EncodingGuide
avconv -y -i "$INPUT_FILE" -threads auto -c:v libx264 -preset medium -b:v 988k -pass 1 -an -f mp4 /dev/null && \
avconv -i "$INPUT_FILE" -threads auto -c:v libx264 -preset medium -b:v 988k -pass 2 -c:a libmp3lame -b:a 192k "$OUTPUT_MP4_FILE"
rm -f av2pass* &>/dev/null
# To keep it DRY (and fix some errors, put some improvements) I've updated the firewall info in this other gist:
# https://gist.github.com/zipizap/6935850
# Check it out :)
@zipizap
zipizap / show_video_audio_codecs.sh
Last active August 25, 2015 21:01
Show container/audio-codec/video-codec of media files (using ffmpeg -i)
#!/bin/bash
[ $# -lt 1 ] && { echo "Usage: $0 <myvideofile>"; exit 1; }
TMP_FILE=$(mktemp)
echo -e "MEDIA_FILE"\\t"EXTENSION"\\t"CONTAINER"\\t"AUDIO_CODEC"\\t"VIDEO_CODEC"
for MEDIA_FILE in "$@"; do
[[ -f $MEDIA_FILE ]] || continue
ffmpeg -i $MEDIA_FILE &> $TMP_FILE
BASE_FILENAME=$(basename "$MEDIA_FILE")
# MOV_0295.mp4