#!/bin/bash

# ffmpeg -i "$*" -f wav  -filter_complex "aresample=22050" -acodec adpcm_ms -ac 1 war2.aud
# ffmpeg -i "$*" -f wav  -af "pan=mono|c0=0.5*FL+0.5*FR" -ar 44100 -acodec adpcm_ms -ac 1 war2.aud
#ffmpeg -i "$*" -f wav  -af "pan=mono|c0=.5*c0+.5*c1" -ar 44100 -acodec adpcm_ms -ac 1 war2.aud
#ffmpeg -i "$*" -f wav -ac 1 -acodec adpcm_ms war2.aud
# ffmpeg -i "$*" -ac 1 -acodec adpcm_ms war2.wav

#ffmpeg -i video.mp4 -af "pan=mono|c0=.5*c0+.5*c1" -c:v copy output.mp4

#ffmpeg -i "$*" -f wav  -filter_complex "asetrate=$RATE/$PITCH,aresample=44100,atempo=(1.0/($SPEED/$PITCH))" -acodec adpcm_ms -ac 1 war2.aud

FILENAME=$*
BASENAME="${FILENAME%.*}"
ffmpeg -i "$FILENAME" \
 	-filter_complex " \
 	[0:a]aresample=22050[a] \
 	" \
 	-map "[a]" \
	-acodec adpcm_ms "$BASENAME.wav"

# ffmpeg -hide_banner \
# 	-i "$FILENAME" \
# 	-filter_complex " \
# 	[0:a]asetrate=$RATE/$PITCH,aresample=44100,atempo=(1.0/($SPEED/$PITCH))[a] \
# 	" \
# 	-map "[a]" \
# 	-acodec adpcm_ms -ac 1 \
# 	"$BASENAME.TWITTER.wav"



## FILELENGTH=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$FILENAME")
## RATE=$(ffprobe -v error -show_entries stream=sample_rate -of default=noprint_wrappers=1:nokey=1 "$FILENAME")
## 
## PITCH="1.0"
## # SPEED=$(echo "(139/$FILELENGTH)"| bc -l)
## 
## SPEED="1.0"
## ## PITCH="1.5"

#SPEED=$(echo "(260/$FILELENGTH)"| bc -l)
#SPEED=0.25
## echo $FILELENGTH
## echo $FILENAME
## echo $BASENAME
## echo $RATE
## echo $SPEED
#

## ffmpeg -hide_banner \
## 	-i "$FILENAME" \
## 	-i "$SRT" \
## 	-strict -2 -c:s mov_text \
## 	-map 0:v:0 -map 0:a:0 \
## 	-map 1 -metadata:s:s:0 language=en -metadata:s:s:0 title="English" \
## 	-c:v copy -c:a copy \
## 	"$BASENAME.SUBS.MP4"
## 
## FILENAME="$BASENAME.SUBS.MP4"
## BASENAME="${FILENAME%.*}"

# ffmpeg -hide_banner \
# 	-i "$FILENAME" \
# 	-filter_complex " \
# 	[0:a]asetrate=$RATE/$PITCH,aresample=44100,atempo=(1.0/($SPEED/$PITCH))[a] \
# 	" \
# 	-map "[a]" \
# 	-acodec adpcm_ms -ac 1 \
# 	"$BASENAME.TWITTER.wav"

