Skip to content
This repository has been archived by the owner on Feb 9, 2018. It is now read-only.

Commit

Permalink
Merge pull request #9 from UniversalMediaServer/AviSynth-Framerates
Browse files Browse the repository at this point in the history
AviSynth framerates
  • Loading branch information
SubJunk committed Jun 24, 2012
2 parents ab9a0fb + 936a5ad commit c8f8a72
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
39 changes: 35 additions & 4 deletions src/main/java/net/pms/encoders/FFMpegVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected ProcessWrapperImpl getFFMpegTranscode(
//cmdArray[6] = pipeprefix + videoPipe + (PMS.get().isWindows()?".2":"");
cmdArray[6] = videoP.getOutputPipe();
} else if (avisynth()) {
File avsFile = getAVSScript(fileName, params.sid, params.fromFrame, params.toFrame);
File avsFile = getAVSScript(fileName, params.sid, params.fromFrame, params.toFrame, "", "");
cmdArray[6] = ProcessUtil.getShortFileNameIfWideChars(avsFile.getAbsolutePath());
}
}
Expand Down Expand Up @@ -311,24 +311,55 @@ protected ProcessWrapperImpl getFFMpegTranscode(
}

public static File getAVSScript(String fileName, DLNAMediaSubtitle subTrack) throws IOException {
return getAVSScript(fileName, subTrack, -1, -1);
return getAVSScript(fileName, subTrack, -1, -1, null, null);
}

public static File getAVSScript(String fileName, DLNAMediaSubtitle subTrack, int fromFrame, int toFrame) throws IOException {
public static File getAVSScript(String fileName, DLNAMediaSubtitle subTrack, int fromFrame, int toFrame, String frameRateRatio, String frameRateNumber) throws IOException {
String onlyFileName = fileName.substring(1 + fileName.lastIndexOf("\\"));
File file = new File(PMS.getConfiguration().getTempFolder(), "pms-avs-" + onlyFileName + ".avs");
PrintWriter pw = new PrintWriter(new FileOutputStream(file));

/*
* Prepare the framerate variables
*/
String numerator;
String denominator;

if (frameRateRatio != null && frameRateNumber != null) {
if (frameRateRatio.equals(frameRateNumber)) {
// No ratio was available
numerator = frameRateRatio;
denominator = "1";
} else {
String[] frameRateNumDen = frameRateRatio.split("/");
numerator = frameRateNumDen[0];
denominator = "1001";
}
} else {
// No framerate was given so we should try the most common one
numerator = "24000";
denominator = "1001";
frameRateNumber = "23.976";
}

String assumeFPS = ".AssumeFPS(" + numerator + "," + denominator + ")";

String directShowFPS = "";
if (!"0".equals(frameRateNumber)) {
directShowFPS = ", fps=" + frameRateNumber;
}

String convertfps = "";
if (PMS.getConfiguration().getAvisynthConvertFps()) {
convertfps = ", convertfps=true";
}

File f = new File(fileName);
if (f.exists()) {
fileName = ProcessUtil.getShortFileNameIfWideChars(fileName);
}

String movieLine = "DirectShowSource(\"" + fileName + "\"" + convertfps + ")";
String movieLine = "DirectShowSource(\"" + fileName + "\"" + directShowFPS + convertfps + ")" + assumeFPS;
String mtLine1 = "";
String mtLine2 = "";
String mtLine3 = "";
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/net/pms/encoders/MEncoderVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,16 @@ public ProcessWrapper launchTranscode(
cmdArray[3] = "-quiet";
}

String frameRateRatio = null;
String frameRateNumber = null;

if (media != null) {
frameRateRatio = media.getValidFps(true);
frameRateNumber = media.getValidFps(false);
}

if (avisynth && !fileName.toLowerCase().endsWith(".iso")) {
File avsFile = FFMpegVideo.getAVSScript(fileName, params.sid, params.fromFrame, params.toFrame);
File avsFile = FFMpegVideo.getAVSScript(fileName, params.sid, params.fromFrame, params.toFrame, frameRateRatio, frameRateNumber);
cmdArray[4] = ProcessUtil.getShortFileNameIfWideChars(avsFile.getAbsolutePath());
} else {
cmdArray[4] = fileName;
Expand Down Expand Up @@ -1794,14 +1802,8 @@ public ProcessWrapper launchTranscode(
cmdArray[cmdArray.length - 6] = "-ofps";
cmdArray[cmdArray.length - 5] = "24000/1001";

String frameRate = null;

if (media != null) {
frameRate = media.getValidFps(true);
}

if (frameRate != null) {
cmdArray[cmdArray.length - 5] = frameRate;
if (frameRateRatio != null) {
cmdArray[cmdArray.length - 5] = frameRateRatio;

if (configuration.isMencoderForceFps()) {
if (configuration.isFix25FPSAvMismatch()) {
Expand All @@ -1815,10 +1817,10 @@ public ProcessWrapper launchTranscode(
}

// Make MEncoder output framerate correspond to InterFrame
if (avisynth() && configuration.getAvisynthInterFrame() && !"60000/1001".equals(frameRate) && !"50".equals(frameRate) && !"60".equals(frameRate)) {
if ("25".equals(frameRate)) {
if (avisynth() && configuration.getAvisynthInterFrame() && !"60000/1001".equals(frameRateRatio) && !"50".equals(frameRateRatio) && !"60".equals(frameRateRatio)) {
if ("25".equals(frameRateRatio)) {
cmdArray[cmdArray.length - 5] = "50";
} else if ("30".equals(frameRate)) {
} else if ("30".equals(frameRateRatio)) {
cmdArray[cmdArray.length - 5] = "60";
} else {
cmdArray[cmdArray.length - 5] = "60000/1001";
Expand Down Expand Up @@ -2514,14 +2516,17 @@ private String[] getSpecificCodecOptions(String codecParam, DLNAMediaInfo media,
interpreter.set("samplerate", params.aid.getSampleRate());
}

String framerate = media.getValidFps(false);
String frameRateNumber = null;
if (media != null) {
frameRateNumber = media.getValidFps(false);
}

try {
if (framerate != null) {
interpreter.set("framerate", Double.parseDouble(framerate));
if (frameRateNumber != null) {
interpreter.set("framerate", Double.parseDouble(frameRateNumber));
}
} catch (NumberFormatException e) {
LOGGER.debug("Could not parse framerate from \"" + framerate + "\"");
LOGGER.debug("Could not parse framerate from \"" + frameRateNumber + "\"");
}

interpreter.set("duration", media.getDurationInSeconds());
Expand Down

0 comments on commit c8f8a72

Please sign in to comment.