Help Request for my Java app Running HandBrakeCLI

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
grecinos
New User
Posts: 1
Joined: Wed Jan 26, 2022 5:49 pm

Help Request for my Java app Running HandBrakeCLI

Post by grecinos »

Hello Handbrake Development Crew and Community,

This is my first post here, in such thanks for making this software open source. It works like a charm and has served me well!

A bit of history of myself… I’m a cyclist and I ride on a frequent basis. I take videos while riding using a GoPro camera. It usually generates over 4 video clips depending on the duration of my ride. Every time I get back home, I copy the videos to my PC and then re-encode them using HandBrake to occupy less storage space on my NAS. It saves me 50% in space and money for storage drives.

I’ve been developing an app in Java to streamline this process. The app acts as a “wrapper” for the HandBrakeCLI app. In short, it simplifies batch encoding process by using custom presets saved from the HandBrake app. It copies the video files and photos if present, performs the encoding procedure and renames the encoded files. Those files are subsequently saved to a directory. I’ve minimized the procedure to a few mouse clicks. It makes the encoding procedure a no brainer and saves me time. I purposely wrote it in Java so that it is cross platform compatible. If permissible and all goes well, I may release it as an open source project.

I ran into a snag the past few days, so I thought I might ask for help here…

In order to display the progress of the encoding procedure, my app “reads” the output generated by the HandbrakeCLI app. To do this, I’ve tried using the BufferReader and Scanner classes. It works perfect on Linux and Macs, but not for PC’s. The code snippet is as follows:

Code: Select all

this.process = Runtime.getRuntime().exec("cmd.exe /c " + command);  
//("command" is a string variable containing “HandBrakeCLI.exe” and parameters)

String strLine;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((strLine = reader.readLine()) != null) 
{
	if (strLine.toLowerCase().contains("task"))
	{		
		System.out.println("(Encoder Message - " + threadNum + "): " + strLine);								
	}                
}
I’m using HandBrakeCLI version 1.5.1. During execution, this code outputs just a few lines on a Windows 11 PC. It reads the output to completion on my Linux Ubuntu PC and Mac Mini M1 (with the latest OS and Java runtime versions).

I need to be able to read the output to completion for it to work properly on a PC. Any suggestions are appreciated.

Cheers,

George
Post Reply