Created
August 2, 2015 00:59
-
-
Save paselin/30d9d000639f46baddb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
INPUT="$1" | |
TMP=`echo $INPUT | cut -f3 -d "/"` | |
LEN=`expr ${#TMP} - 5` | |
FILENAME=`echo $TMP | cut -c 1-$LEN` | |
TMPOUT="./video/tmp/$FILENAME.mp4" | |
OUTPUT="./video/encoded/$FILENAME.mp4" | |
TARGET_HEIGHT="720" | |
## mediainfo | |
echo "check media info..." | |
MEDIA_INFO=`mediainfo --Inform='Video;%FrameRate%,%DisplayAspectRatio/String%,%BitRate%,%Width%,%Height%' "$1"` | |
FPS=`echo ${MEDIA_INFO} | awk -F',' '{print $1}'` | |
ASPECT_RATIO=`echo ${MEDIA_INFO} | awk -F',' '{print $2}'` | |
BIT_RATE=`echo ${MEDIA_INFO} | awk -F',' '{print $3}'` | |
SOURCE_WIDTH=`echo ${MEDIA_INFO} | awk -F',' '{print $4}'` | |
SOURCE_HEIGHT=`echo ${MEDIA_INFO} | awk -F',' '{print $5}'` | |
echo "source info -----------------" | |
echo " fps : ${FPS}fps" | |
echo " bit rate : ${BIT_RATE}bps" | |
echo " aspect ratio: ${ASPECT_RATIO}" | |
echo " width : ${SOURCE_WIDTH}px" | |
echo " height : ${SOURCE_HEIGHT}px" | |
## calc convert setting | |
TARGET_SCALE=`echo "scale=2; ${SOURCE_HEIGHT} / ${TARGET_HEIGHT}" | bc` | |
TARGET_WIDTH=`echo "scale=0; ${SOURCE_WIDTH} / ${TARGET_SCALE}" | bc` | |
TARGET_BIT_RATE=`echo "scale=0; ${BIT_RATE} / (${TARGET_SCALE} * 2)" | bc` | |
echo "convert settings ------------------" | |
echo " scale : ${TARGET_SCALE}" | |
echo " width : ${TARGET_WIDTH}px" | |
echo " height : ${TARGET_HEIGHT}px" | |
echo " bitrate : ${TARGET_BIT_RATE}" | |
## encode start | |
echo "encode start ------------------" | |
gst-launch-1.0 \ | |
filesrc location="${INPUT}" \ | |
! progressreport \ | |
! tsdemux name=demuxer demuxer. \ | |
! queue \ | |
! aacparse \ | |
! avdec_aac \ | |
! audioresample \ | |
! audioconvert dithering=0 \ | |
! voaacenc bitrate=192000 \ | |
! mux. mp4mux name=mux \ | |
! filesink location="${TMPOUT}" demuxer. \ | |
! queue \ | |
! mpegvideoparse \ | |
! omxmpeg2videodec \ | |
! videoconvert \ | |
! deinterlace \ | |
! omxh264enc target-bitrate=${TARGET_BIT_RATE} control-rate=variable \ | |
! video/x-h264,width=${TARGET_WIDTH},height=${TARGET_HEIGHT}, \ | |
stream-format=byte-stream,profile=high \ | |
! h264parse \ | |
! mux. | |
status=$? | |
echo "encode exit" | |
mv $TMPOUT $OUTPUT | |
exit $status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment