package cubrikproject.tud.likelines.service.impl;

import java.io.IOException;

/**
 * The Transcoder class converts downloaded videos into a specific format required by the motion analysis tool.
 * 
 * Basically, it is a wrapper for:
 * ffmpeg -y -i SRC -target pal-vcd DST
 * 
 * @author R. Vliegendhart
 */
public class Transcoder {
	/** path to the binary */
	private final String ffmpegPath;

	/**
	 * Constructs a Transcoder object.
	 * @param ffmpegPath Path to ffmpeg
	 */
	public Transcoder(String ffmpegPath) {
		this.ffmpegPath = ffmpegPath;
	}
	
	/**
	 * Transcodes a file.
	 * 
	 * @param source The video to be transcoded
	 * @param destination The location to store the transcoded video
	 * @return A Process handle
	 * @throws IOException
	 */
	public Process transcode(String source, String destination) throws IOException {
		final ProcessBuilder pb = new ProcessBuilder(ffmpegPath, "-y", "-i", source, "-target", "pal-vcd", destination);
		return pb.start();
	}
	
	/**
	 * Transcodes a file (blocking).
	 * 
	 * @param source The video to be transcoded
	 * @param destination The location to store the transcoded video
	 * @return A Process handle
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public int transcodeAndWait(String source, String destination) throws IOException, InterruptedException {
		final Process proc = transcode(source, destination);
		return proc.waitFor();
	}
}

@@ -59,27 +59,92 @@
 java.io.
-IOException
+BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader
 ;%0A%0A/**%0A 
@@ -1441,32 +1441,153 @@
 , destination);%0A
+%09%09BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream()));%0A%09%09while (br.readLine() != null);%0A
 %09%09return proc.wa

Fix transcodeAndWait