Script of batch converting videos.

Mostly, there are lot of videos which can't be played under ios. So we have to convert them to appropriate format. Here is the batch converting script.

Running under Linux and ffmpeg and pv are needed.


#!/bin/bash

function convert_file() {
	src="$1"
	dst=$(echo "$src" | sed -e "s|\.mp4|\.mov|g")

	if [ ! -f "$src" ]; then
		echo "Not exists: \"$src\""
		return 
	fi

	if [ -f "$dst" ]; then
		rm -f "$dst"
	fi

	(pv "$src" | ffmpeg -i pipe:0 -acodec libmp3lame -f mov "$dst" > /dev/null 2>&1 ) &
}

function wait_for_proc() {
	job_ids=$(echo $(jobs -l | awk '{print $2}'))
	wait $job_ids
}

echo "Begin processing..."

i=0

# I only search for mp4, but you can specify any other formats as you like
find ./ -name *.mp4 | while read line; do
	convert_file "$line"
	i=$((i+1))

	if [[ $((i % 4)) == 0 ]]; then
		wait_for_proc
	fi
done

wait_for_proc

echo "...done"
echo "Total: $i file(s)"

Now, sit down and have a cup of tea. It will take a very loooooooooooooong while, 


Good luck!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章