Skip to content

Commit

Permalink
Merge pull request #120 from brarcher/h264-preset-faster
Browse files Browse the repository at this point in the history
Set the 'preset' setting for h264 to 'faster'
  • Loading branch information
brarcher authored Jul 31, 2018
2 parents 8993c9c + b8b77ee commit 739d37a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ private List<String> getFfmpegEncodingArgs(String inputFilePath, Integer startTi
command.add(videoBitrateK + "k");
}

command.addAll(videoCodec.extraFfmpegArgs);

// Frame size
command.add("-s");
command.add(resolution);
Expand All @@ -699,13 +701,7 @@ private List<String> getFfmpegEncodingArgs(String inputFilePath, Integer startTi
command.add("-acodec");
command.add(audioCodec.ffmpegName);

if (audioCodec == AudioCodec.VORBIS)
{
// The vorbis encode is experimental, and needs other
// flags to enable
command.add("-strict");
command.add("-2");
}
command.addAll(audioCodec.extraFfmpegArgs);

// Sample rate
command.add("-ar");
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/java/protect/videotranscoder/media/AudioCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
*/
public enum AudioCodec
{
AAC("aac", Arrays.asList("1", "2")),
MP3("mp3", Arrays.asList("1", "2")),
OPUS("libopus", Arrays.asList("1", "2")),
VORBIS("vorbis", Collections.singletonList("2")),
NONE("none", Collections.EMPTY_LIST),
AAC("aac", Collections.EMPTY_LIST, Arrays.asList("1", "2")),
MP3("mp3", Collections.EMPTY_LIST, Arrays.asList("1", "2")),
OPUS("libopus", Collections.EMPTY_LIST, Arrays.asList("1", "2")),

// The vorbis encode is experimental, and needs other flags to enable
VORBIS("vorbis", Arrays.asList("-strict", "-2"), Collections.singletonList("2")),
NONE("none", Collections.EMPTY_LIST, Collections.EMPTY_LIST),
;

public final String ffmpegName;
public final List<String> extraFfmpegArgs;
public final List<String> supportedChannels;

AudioCodec(String ffmpegName, List<String> supportedChannels)
AudioCodec(String ffmpegName, List<String> extraFfmpegArgs, List<String> supportedChannels)
{
this.ffmpegName = ffmpegName;
this.extraFfmpegArgs = extraFfmpegArgs;
this.supportedChannels = Collections.unmodifiableList(supportedChannels);
}

Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/protect/videotranscoder/media/VideoCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@

import android.support.annotation.Nullable;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import protect.videotranscoder.R;

/**
* List of video codecs which the application may support
*/
public enum VideoCodec
{
H264("h264", "H.264", R.string.codecSlowExcellent),
MPEG4("mpeg4", "MPEG-4", R.string.codecFastGood),
MPEG2("mpeg2video", "MPEG-2", R.string.codecFastOk),
MPEG1("mpeg1video", "MPEG-1", R.string.codecFastLow),
GIF("gif", "GIF", null),
// The 'preset' setting for h264 is changed from its default of 'medium'. The
// 'faster' setting reduces encoding times by ~73% while only reducing quality
// a near imperceptible amount. This seems like a good trade-off for encoding
// on a mobile devices where power usage is a concern.
H264("h264", "H.264", Arrays.asList("-preset", "faster"), R.string.codecSlowExcellent),
MPEG4("mpeg4", "MPEG-4", Collections.EMPTY_LIST, R.string.codecFastGood),
MPEG2("mpeg2video", "MPEG-2", Collections.EMPTY_LIST, R.string.codecFastOk),
MPEG1("mpeg1video", "MPEG-1", Collections.EMPTY_LIST, R.string.codecFastLow),
GIF("gif", "GIF", Collections.EMPTY_LIST, null),
;

public final String ffmpegName;
public final String prettyName;
public final List<String> extraFfmpegArgs;
public final Integer helperTextId;

VideoCodec(String ffmpegName, String prettyName, Integer helperTextId)
VideoCodec(String ffmpegName, String prettyName, List<String> extraFfmpegArgs, Integer helperTextId)
{
this.ffmpegName = ffmpegName;
this.prettyName = prettyName;
this.extraFfmpegArgs = extraFfmpegArgs;
this.helperTextId = helperTextId;
}

Expand Down

0 comments on commit 739d37a

Please sign in to comment.