Skip to content

Commit

Permalink
Merge pull request #8 from budius/add-raspberry-pi-hardware-accel-option
Browse files Browse the repository at this point in the history
Add raspberry pi hardware accel option
  • Loading branch information
budius authored Mar 24, 2019
2 parents 066a839 + e895fe4 commit 5d706a8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
2 changes: 1 addition & 1 deletion main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.budius.chromecast.converter.Main'
applicationName = 'cc_converter'
version = '2.1.0'
version = '2.2.1'

sourceCompatibility = 1.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private static String fromArray(List<String> list) {
OPTIONS.addOption("s", "speed", true, "Speed: " + fromArray(Settings.SPEED) + ". Default is slow (optional)");
OPTIONS.addOption("d", "delete", false, "Delete the original file upon successful conversion");
OPTIONS.addOption("f", "force", false, "Force conversion (even if input codecs are correct)");
OPTIONS.addOption("p", "pi", false, "Uses h264_omx to allow conversion on the Raspberry Pi");
OPTIONS.addOption(null, "DEBUG", false, "Debug mode with more logs");
}

Expand All @@ -51,6 +52,10 @@ public Arguments(String[] args) {
String outputString = cmd.getOptionValue("o", null);
String qualityString = cmd.getOptionValue("q", Settings.DEFAULT_QUALITY);
String speedString = cmd.getOptionValue("s", Settings.DEFAULT_SPEED);
boolean delete = cmd.hasOption("d");
boolean force = cmd.hasOption("f");
boolean pi = cmd.hasOption("p");
debug = cmd.hasOption("DEBUG");

// test valid input
if (inputString == null) {
Expand Down Expand Up @@ -103,10 +108,7 @@ public Arguments(String[] args) {
return;
}

settings = new Settings(inputFile, outputFile, speedString, quality,
cmd.hasOption("d"),
cmd.hasOption("f"));
debug = cmd.hasOption("DEBUG");
settings = new Settings(inputFile, outputFile, speedString, quality, delete, force, pi);

} catch (ParseException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
public class Main {

public static final String VERSION = "Chromecast Converter - V2.1.0";
public static final String VERSION = "Chromecast Converter - V2.2.1";

public static void main(String[] args) {

Expand Down
28 changes: 15 additions & 13 deletions main/src/main/java/com/budius/chromecast/converter/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,46 @@ public class Settings {


public static final List<String> SPEED = Arrays.asList(
"ultrafast",
"superfast",
"veryfast",
"faster",
"fast",
"medium",
"slow",
"slower",
"veryslow"
"ultrafast",
"superfast",
"veryfast",
"faster",
"fast",
"medium",
"slow",
"slower",
"veryslow"
);

public static final List<String> QUALITY = Arrays.asList(
"high", "normal", "low"
"high", "normal", "low"
);

public static final int[] I_ARRAY_QUALITY = {
18, 23, 26,};
18, 23, 26,};

public final File input;
public final File output;
public final String speed;
public final int quality;
public final boolean delete;
public final boolean force;
public final boolean pi;

public static final String DEFAULT_SPEED = "slow";
public static final String DEFAULT_QUALITY = "high";

public Settings(File input, File output, String speed, int quality, boolean delete, boolean force) {
public Settings(File input, File output, String speed, int quality, boolean delete, boolean force, boolean pi) {
this.input = input;
this.output = output;
this.speed = speed;
this.quality = quality;
this.delete = delete;
this.force = force;
this.pi = pi;
}

public Settings copy(File input) {
return new Settings(input, this.output, this.speed, this.quality, this.delete, this.force);
return new Settings(input, this.output, this.speed, this.quality, this.delete, this.force, this.pi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,29 @@ public class Video implements Processor {
&& !job.settings.force) {
job.ffmpegCmd.add("copy");
return Result.success();
} else {
}

// executing on Raspberry Pi
else if (job.settings.pi) {

// check ffmpeg supports h264_omx
if (!Utils.supportsCodec("h264_omx")) {
return Result.fail("No suitable video encoder available");
}

job.ffmpegCmd.add("h264_omx");
String videoBitRate = getVideoBitrate(job.ffProbe);
if (videoBitRate != null) {
job.ffmpegCmd.add("-b:v");
job.ffmpegCmd.add(videoBitRate);
}

return Result.success();

}

// execution on PC
else {

// check ffmpeg supports libx264
if (!Utils.supportsCodec("libx264")) {
Expand Down Expand Up @@ -105,19 +127,27 @@ public static boolean addCmd(Probe ffProbe, ArrayList<String> cmd, Settings sett

private static String getVideoBitrate(Probe ffProbe) {

/*
I found cases where mpeg1 streams return the uncompressed bitrate, rendering absurdly high bit rates.
So we're getting the smaller from the two
*/

long br_stream = getVideoBitrateBasedOnVideoStreamBitRate(ffProbe);
long br_file = getVideoBitrateBasedOnFileBitrate(ffProbe);
long br = br_file > br_stream ? br_stream : br_file;

if (br <= 0)
return null;
else
if (br_stream > 0 && br_file > 0) {
// I found cases where mpeg1 streams return the uncompressed bitrate
// rendering absurdly high bit rates.
// So we're getting the smaller from the two
long br = br_file > br_stream ? br_stream : br_file;
return Long.toString(br);
}

if (br_stream > 0) {
return Long.toString(br_stream);
}

if (br_file > 0) {
return Long.toString(br_file);
}

return null;
}

private static long getVideoBitrateBasedOnFileBitrate(Probe ffProbe) {
Expand Down

0 comments on commit 5d706a8

Please sign in to comment.