#!/usr/bin/python
#
# makoto.sugano@nokia.com
# stefan.kost@nokia.com
#

import os
import sys
import re
import commands

format = {
'avi': 'avimux',
}

video = {
#'THEORA': 'theoraenc',
'MPEG4-SP': 'ffenc_mpeg4',
'MPEG4-ASP': 'ffenc_mpeg4 max-bframes=1 flags=0x00000010',
#'MPEG4-ASP': 'mpeg4 -bf 1 -flags qpel', # -bf use b-frames
'H264': 'x264enc cabac=true byte-stream=true',
'MJPEG': 'ffenc_mjpeg',
}

audio = {
'RAW': 'identity',
#'VORBIS': 'vorbisenc',
'MP3': 'lame',
'AAC-LC': 'faac profile=1',
#'ALAW': 'alawenc',
#'MULAW': 'mulawenc',
}

for i in range(len(format.keys())):
	for j in range(len(audio.keys())):
		for k in range(len(video.keys())):
			filename = audio.keys()[j] + '_' + video.keys()[k] + '.' + format.keys()[i]
			command = "gst-launch filesrc location=input.avi ! decodebin name=d " + format[format.keys()[i]] + " name=m ! filesink location=" + filename + " d. ! audioconvert ! " + audio[audio.keys()[j]] + " ! queue name=audio_queue ! m.audio_00 d. ! ffmpegcolorspace ! " + video[video.keys()[k]] + " ! queue name=video_queue ! m.video_00"
			status, output = commands.getstatusoutput(command)
			if status != 0:
				print command, "\n", output, "\n"
				
