Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created June 3, 2010 08:16
Show Gist options
  • Save andoriyu/423630 to your computer and use it in GitHub Desktop.
Save andoriyu/423630 to your computer and use it in GitHub Desktop.
anything2mp4 (iphone)
#!/usr/local/bin/bash
#Copyright (c) 2010 Andrey Cherkashin
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated #documentation files (the "Software"), to deal in the Software without restriction, including without
#limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
#the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
#conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial
#portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
#LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
#EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
#AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
#OR OTHER DEALINGS IN THE SOFTWARE.
file="$1"
FILE_NAME="${file%.*}"
ENCODE_DIR="/usr/encode_tmp"
ENCODE_TMP="$ENCODE_DIR/$FILE_NAME"
ENCODE_FINISH="/usr/encode_finish"
mkdir -p $ENCODE_TMP
rm -f $ENCODE_TMP/video.h264 $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav $ENCODE_TMP/video.y4m $ENCODE_FINISH/$FILE_NAME.mp4
mkfifo $ENCODE_TMP/video.y4m
mkfifo $ENCODE_TMP/audio.wav
mplayer -identify -frames 0 "$1" > /tmp/video.info
VIDEO_FPS=`cat /tmp/video.info |grep "ID_VIDEO_FPS" |cut -d'=' -f2`
x264 --crf 20 --profile baseline --level 3 --no-cabac --partitions p8x8,b8x8,i4x4 --me umh --subme 7 --vbv-bufsize 10000 --vbv-maxrate 10000 --threads auto --no-fast-pskip --output $ENCODE_TMP/video.h264 $ENCODE_TMP/video.y4m 2>/dev/null & \
mplayer "$1" -nosound -benchmark -vo yuv4mpeg:file=$ENCODE_TMP/video.y4m -sws 9 -vf scale=480:-10
faac -r -b 128 -w -s -o $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav & mplayer -nocorrect-pts -novideo -ao pcm:file=$ENCODE_TMP/audio.wav -benchmark "$1"
mp4box -add $ENCODE_TMP/video.h264 -add $ENCODE_TMP/audio.mp4 -tmp $ENCODE_TMP -fps $VIDEO_FPS -new $ENCODE_FINISH/$FILE_NAME.mp4
mp4box -add $ENCODE_TMP/audio.mp4 -tmp $ENCODE_TMP $ENCODE_FINISH/$FILE_NAME.mp4
rm -f $ENCODE_TMP/audio.wav $ENCODE_TMP/video.h264 $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav $ENCODE_TMP/video.y4m
@andoriyu
Copy link
Author

andoriyu commented Jun 3, 2010

!/usr/local/bin/bash

file="$1"
FILE_NAME="${file%.*}"
ENCODE_DIR="/usr/encode_tmp"
ENCODE_TMP="$ENCODE_DIR/$FILE_NAME"
ENCODE_FINISH="/usr/encode_finish"

mkdir -p $ENCODE_TMP
rm -f $ENCODE_TMP/video.h264 $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav $ENCODE_TMP/video.y4m $ENCODE_FINISH/$FILE_NAME.mp4
mkfifo $ENCODE_TMP/video.y4m
mkfifo $ENCODE_TMP/audio.wav

mplayer -identify -frames 0 "$1" > /tmp/video.info

VIDEO_FPS=cat /tmp/video.info |grep "ID_VIDEO_FPS" |cut -d'=' -f2
x264 --crf 20 --profile baseline --level 3 --no-cabac --partitions p8x8,b8x8,i4x4 --me umh --subme 7 --vbv-bufsize 10000 --vbv-maxrate 10000 --threads auto --no-fast-pskip --output $ENCODE_TMP/video.h264 $ENCODE_TMP/video.y4m 2>/dev/null &
mplayer "$1" -nosound -benchmark -vo yuv4mpeg:file=$ENCODE_TMP/video.y4m -sws 9 -vf scale=480:-10
faac -r -b 128 -w -s -o $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav & mplayer -nocorrect-pts -novideo -ao pcm:file=$ENCODE_TMP/audio.wav -benchmark "$1"
mp4box -add $ENCODE_TMP/video.h264 -add $ENCODE_TMP/audio.mp4 -tmp $ENCODE_TMP -fps $VIDEO_FPS -new $ENCODE_FINISH/$FILE_NAME.mp4
mp4box -add $ENCODE_TMP/audio.mp4 -tmp $ENCODE_TMP $ENCODE_FINISH/$FILE_NAME.mp4
rm -f audio.wav $ENCODE_TMP/video.h264 $ENCODE_TMP/audio.mp4 $ENCODE_TMP/audio.wav $ENCODE_TMP/video.y4m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment