mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 04:00:53 +00:00
Merge origin/master
This commit is contained in:
+52
-52
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import java.util.List;
|
||||
|
||||
public class PushShortIns extends InstructionDefinition implements PushIntegerTypeIns {
|
||||
|
||||
public PushShortIns() {
|
||||
super(0x25, "pushshort", new int[]{AVM2Code.OPT_U30_SHORT}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
lda.operandStack.push((long) (short) ins.operands[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
stack.push(new IntegerValueAVM2Item(ins, (long) (short) ins.operands[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackPushCount(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import java.util.List;
|
||||
|
||||
public class PushShortIns extends InstructionDefinition implements PushIntegerTypeIns {
|
||||
|
||||
public PushShortIns() {
|
||||
super(0x25, "pushshort", new int[]{AVM2Code.OPT_U30_SHORT}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
lda.operandStack.push((long) (short) ins.operands[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
|
||||
stack.push(new IntegerValueAVM2Item(ins, (long) (short) ins.operands[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackPushCount(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.types;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConvertException;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class ABCException implements Serializable, Cloneable {
|
||||
|
||||
public int start;
|
||||
|
||||
public int end;
|
||||
|
||||
public int target;
|
||||
|
||||
public int type_index;
|
||||
|
||||
public int name_index;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Exception: startServer=" + Helper.formatAddress(start) + " end=" + Helper.formatAddress(end) + " target=" + target + " type_index=" + type_index + " name_index=" + name_index;
|
||||
}
|
||||
|
||||
public String toString(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
return "Exception: startServer=" + Helper.formatAddress(start) + " end=" + Helper.formatAddress(end) + " target=" + target + " type=\"" + getTypeName(constants, fullyQualifiedNames) + "\" name=\"" + getVarName(constants, fullyQualifiedNames) + "\"";
|
||||
}
|
||||
|
||||
public String toString(AVM2ConstantPool constants, AVM2Code code, List<DottedChain> fullyQualifiedNames) {
|
||||
try {
|
||||
return "Exception: startServer=" + code.adr2pos(start) + ":" + code.code.get(code.adr2pos(start)).toStringNoAddress(constants, fullyQualifiedNames) + " end=" + code.adr2pos(end) + ":" + code.code.get(code.adr2pos(end)).toStringNoAddress(constants, fullyQualifiedNames) + " target=" + code.adr2pos(target) + ":" + code.code.get(code.adr2pos(target)).toStringNoAddress(constants, fullyQualifiedNames) + " type=\"" + getTypeName(constants, fullyQualifiedNames) + "\" name=\"" + getVarName(constants, fullyQualifiedNames) + "\"";
|
||||
} catch (ConvertException ex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinally() {
|
||||
return (name_index == 0) && (type_index == 0);
|
||||
}
|
||||
|
||||
public String getVarName(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
if (name_index == 0) {
|
||||
return "";
|
||||
}
|
||||
return constants.getMultiname(name_index).getName(constants, fullyQualifiedNames, false);
|
||||
}
|
||||
|
||||
public String getTypeName(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
if (type_index == 0) {
|
||||
return "*";
|
||||
}
|
||||
return constants.getMultiname(type_index).getName(constants, fullyQualifiedNames, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ABCException clone() {
|
||||
try {
|
||||
ABCException ret = (ABCException) super.clone();
|
||||
return ret;
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.types;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConvertException;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class ABCException implements Serializable, Cloneable {
|
||||
|
||||
public int start;
|
||||
|
||||
public int end;
|
||||
|
||||
public int target;
|
||||
|
||||
public int type_index;
|
||||
|
||||
public int name_index;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Exception: startServer=" + Helper.formatAddress(start) + " end=" + Helper.formatAddress(end) + " target=" + target + " type_index=" + type_index + " name_index=" + name_index;
|
||||
}
|
||||
|
||||
public String toString(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
return "Exception: startServer=" + Helper.formatAddress(start) + " end=" + Helper.formatAddress(end) + " target=" + target + " type=\"" + getTypeName(constants, fullyQualifiedNames) + "\" name=\"" + getVarName(constants, fullyQualifiedNames) + "\"";
|
||||
}
|
||||
|
||||
public String toString(AVM2ConstantPool constants, AVM2Code code, List<DottedChain> fullyQualifiedNames) {
|
||||
try {
|
||||
return "Exception: startServer=" + code.adr2pos(start) + ":" + code.code.get(code.adr2pos(start)).toStringNoAddress(constants, fullyQualifiedNames) + " end=" + code.adr2pos(end) + ":" + code.code.get(code.adr2pos(end)).toStringNoAddress(constants, fullyQualifiedNames) + " target=" + code.adr2pos(target) + ":" + code.code.get(code.adr2pos(target)).toStringNoAddress(constants, fullyQualifiedNames) + " type=\"" + getTypeName(constants, fullyQualifiedNames) + "\" name=\"" + getVarName(constants, fullyQualifiedNames) + "\"";
|
||||
} catch (ConvertException ex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinally() {
|
||||
return (name_index == 0) && (type_index == 0);
|
||||
}
|
||||
|
||||
public String getVarName(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
if (name_index == 0) {
|
||||
return "";
|
||||
}
|
||||
return constants.getMultiname(name_index).getName(constants, fullyQualifiedNames, false);
|
||||
}
|
||||
|
||||
public String getTypeName(AVM2ConstantPool constants, List<DottedChain> fullyQualifiedNames) {
|
||||
if (type_index == 0) {
|
||||
return "*";
|
||||
}
|
||||
return constants.getMultiname(type_index).getName(constants, fullyQualifiedNames, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ABCException clone() {
|
||||
try {
|
||||
ABCException ret = (ABCException) super.clone();
|
||||
return ret;
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,190 +1,190 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters;
|
||||
|
||||
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
||||
import com.jpexs.decompiler.flash.EventListener;
|
||||
import com.jpexs.decompiler.flash.RetryTask;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings;
|
||||
import com.jpexs.decompiler.flash.flv.FLVOutputStream;
|
||||
import com.jpexs.decompiler.flash.flv.FLVTAG;
|
||||
import com.jpexs.decompiler.flash.flv.VIDEODATA;
|
||||
import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.VideoFrameTag;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MovieExporter {
|
||||
|
||||
public List<File> exportMovies(AbortRetryIgnoreHandler handler, String outdir, List<Tag> tags, final MovieExportSettings settings, EventListener evl) throws IOException, InterruptedException {
|
||||
List<File> ret = new ArrayList<>();
|
||||
if (tags.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
File foutdir = new File(outdir);
|
||||
Path.createDirectorySafe(foutdir);
|
||||
|
||||
int count = 0;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof DefineVideoStreamTag) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int currentIndex = 1;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof DefineVideoStreamTag) {
|
||||
if (evl != null) {
|
||||
evl.handleExportingEvent("movie", currentIndex, count, t.getName());
|
||||
}
|
||||
|
||||
final DefineVideoStreamTag videoStream = (DefineVideoStreamTag) t;
|
||||
final File file = new File(outdir + File.separator + Helper.makeFileName(videoStream.getCharacterExportFileName() + ".flv"));
|
||||
new RetryTask(() -> {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
fos.write(exportMovie(videoStream, settings.mode));
|
||||
}
|
||||
}, handler).run();
|
||||
|
||||
if (evl != null) {
|
||||
evl.handleExportedEvent("movie", currentIndex, count, t.getName());
|
||||
}
|
||||
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] exportMovie(DefineVideoStreamTag videoStream, MovieExportMode mode) throws IOException {
|
||||
SWF swf = videoStream.getSwf();
|
||||
HashMap<Integer, VideoFrameTag> frames = new HashMap<>();
|
||||
SWF.populateVideoFrames(videoStream.characterID, swf.tags, frames);
|
||||
if (frames.isEmpty()) {
|
||||
return SWFInputStream.BYTE_ARRAY_EMPTY;
|
||||
}
|
||||
|
||||
//double ms = 1000.0f / ((float) frameRate);
|
||||
ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
||||
//CopyOutputStream cos = new CopyOutputStream(fos, new FileInputStream("f:\\trunk\\testdata\\xfl\\xfl\\_obj\\streamvideo 7.flv"));
|
||||
OutputStream tos = fos;
|
||||
FLVOutputStream flv = new FLVOutputStream(tos);
|
||||
flv.writeHeader(false, true);
|
||||
//flv.writeTag(new FLVTAG(0, SCRIPTDATA.onMetaData(ms * frames.size() / 1000.0, videoStream.width, videoStream.height, 0, frameRate, videoStream.codecID, 0, 0, false, 0, fileSize)));
|
||||
int horizontalAdjustment = 0;
|
||||
int verticalAdjustment = 0;
|
||||
int[] frameNumArray = Helper.toIntArray(frames.keySet());
|
||||
Arrays.sort(frameNumArray);
|
||||
for (int i = 0; i < frameNumArray.length; i++) {
|
||||
VideoFrameTag tag = frames.get(frameNumArray[i]);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int frameType = 1;
|
||||
|
||||
if ((videoStream.codecID == DefineVideoStreamTag.CODEC_VP6)
|
||||
|| (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA)) {
|
||||
SWFInputStream sis = new SWFInputStream(swf, tag.videoData.getRangeData());
|
||||
if (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA) {
|
||||
sis.readUI24("offsetToAlpha"); //offsetToAlpha
|
||||
}
|
||||
int frameMode = (int) sis.readUB(1, "frameMode");
|
||||
|
||||
if (frameMode == 0) {
|
||||
frameType = 1; //intra
|
||||
} else {
|
||||
frameType = 2; //inter
|
||||
}
|
||||
sis.readUB(6, "qp"); //qp
|
||||
int marker = (int) sis.readUB(1, "marker");
|
||||
if (frameMode == 0) {
|
||||
int version = (int) sis.readUB(5, "version");
|
||||
int version2 = (int) sis.readUB(2, "version2");
|
||||
sis.readUB(1, "interlace"); //interlace
|
||||
if (marker == 1 || version2 == 0) {
|
||||
sis.readUI16("offset"); //offset
|
||||
}
|
||||
int dim_y = sis.readUI8("dim_y");
|
||||
int dim_x = sis.readUI8("dim_x");
|
||||
sis.readUI8("render_y"); //render_y
|
||||
sis.readUI8("render_x"); //render_x
|
||||
horizontalAdjustment = (int) (dim_x * Math.ceil(((double) videoStream.width) / (double) dim_x)) - videoStream.width;
|
||||
verticalAdjustment = (int) (dim_y * Math.ceil(((double) videoStream.height) / (double) dim_y)) - videoStream.height;
|
||||
|
||||
}
|
||||
|
||||
SWFOutputStream sos = new SWFOutputStream(baos, swf.version);
|
||||
sos.writeUB(4, horizontalAdjustment);
|
||||
sos.writeUB(4, verticalAdjustment);
|
||||
}
|
||||
if (videoStream.codecID == DefineVideoStreamTag.CODEC_SORENSON_H263) {
|
||||
SWFInputStream sis = new SWFInputStream(swf, tag.videoData.getRangeData());
|
||||
sis.readUB(17, "pictureStartCode");//pictureStartCode
|
||||
sis.readUB(5, "version"); //version
|
||||
sis.readUB(8, "temporalReference"); //temporalReference
|
||||
int pictureSize = (int) sis.readUB(3, "pictureSize"); //pictureSize
|
||||
if (pictureSize == 0) {
|
||||
sis.readUB(8, "customWidth"); //customWidth
|
||||
sis.readUB(8, "customHeight"); //customHeight
|
||||
}
|
||||
if (pictureSize == 1) {
|
||||
sis.readUB(16, "customWidth"); //customWidth
|
||||
sis.readUB(16, "customHeight"); //customHeight
|
||||
}
|
||||
int pictureType = (int) sis.readUB(2, "pictureType");
|
||||
switch (pictureType) {
|
||||
case 0: //intra
|
||||
frameType = 1; //keyframe
|
||||
break;
|
||||
case 1://inter
|
||||
frameType = 2;
|
||||
break;
|
||||
case 2: //disposable
|
||||
frameType = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
baos.write(tag.videoData.getRangeData());
|
||||
flv.writeTag(new FLVTAG((int) Math.floor(i * 1000.0 / swf.frameRate), new VIDEODATA(frameType, videoStream.codecID, baos.toByteArray())));
|
||||
}
|
||||
return fos.toByteArray();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.exporters;
|
||||
|
||||
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
||||
import com.jpexs.decompiler.flash.EventListener;
|
||||
import com.jpexs.decompiler.flash.RetryTask;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings;
|
||||
import com.jpexs.decompiler.flash.flv.FLVOutputStream;
|
||||
import com.jpexs.decompiler.flash.flv.FLVTAG;
|
||||
import com.jpexs.decompiler.flash.flv.VIDEODATA;
|
||||
import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.VideoFrameTag;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MovieExporter {
|
||||
|
||||
public List<File> exportMovies(AbortRetryIgnoreHandler handler, String outdir, List<Tag> tags, final MovieExportSettings settings, EventListener evl) throws IOException, InterruptedException {
|
||||
List<File> ret = new ArrayList<>();
|
||||
if (tags.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
File foutdir = new File(outdir);
|
||||
Path.createDirectorySafe(foutdir);
|
||||
|
||||
int count = 0;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof DefineVideoStreamTag) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int currentIndex = 1;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof DefineVideoStreamTag) {
|
||||
if (evl != null) {
|
||||
evl.handleExportingEvent("movie", currentIndex, count, t.getName());
|
||||
}
|
||||
|
||||
final DefineVideoStreamTag videoStream = (DefineVideoStreamTag) t;
|
||||
final File file = new File(outdir + File.separator + Helper.makeFileName(videoStream.getCharacterExportFileName() + ".flv"));
|
||||
new RetryTask(() -> {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
fos.write(exportMovie(videoStream, settings.mode));
|
||||
}
|
||||
}, handler).run();
|
||||
|
||||
if (evl != null) {
|
||||
evl.handleExportedEvent("movie", currentIndex, count, t.getName());
|
||||
}
|
||||
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] exportMovie(DefineVideoStreamTag videoStream, MovieExportMode mode) throws IOException {
|
||||
SWF swf = videoStream.getSwf();
|
||||
HashMap<Integer, VideoFrameTag> frames = new HashMap<>();
|
||||
SWF.populateVideoFrames(videoStream.characterID, swf.tags, frames);
|
||||
if (frames.isEmpty()) {
|
||||
return SWFInputStream.BYTE_ARRAY_EMPTY;
|
||||
}
|
||||
|
||||
//double ms = 1000.0f / ((float) frameRate);
|
||||
ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
||||
//CopyOutputStream cos = new CopyOutputStream(fos, new FileInputStream("f:\\trunk\\testdata\\xfl\\xfl\\_obj\\streamvideo 7.flv"));
|
||||
OutputStream tos = fos;
|
||||
FLVOutputStream flv = new FLVOutputStream(tos);
|
||||
flv.writeHeader(false, true);
|
||||
//flv.writeTag(new FLVTAG(0, SCRIPTDATA.onMetaData(ms * frames.size() / 1000.0, videoStream.width, videoStream.height, 0, frameRate, videoStream.codecID, 0, 0, false, 0, fileSize)));
|
||||
int horizontalAdjustment = 0;
|
||||
int verticalAdjustment = 0;
|
||||
int[] frameNumArray = Helper.toIntArray(frames.keySet());
|
||||
Arrays.sort(frameNumArray);
|
||||
for (int i = 0; i < frameNumArray.length; i++) {
|
||||
VideoFrameTag tag = frames.get(frameNumArray[i]);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int frameType = 1;
|
||||
|
||||
if ((videoStream.codecID == DefineVideoStreamTag.CODEC_VP6)
|
||||
|| (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA)) {
|
||||
SWFInputStream sis = new SWFInputStream(swf, tag.videoData.getRangeData());
|
||||
if (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA) {
|
||||
sis.readUI24("offsetToAlpha"); //offsetToAlpha
|
||||
}
|
||||
int frameMode = (int) sis.readUB(1, "frameMode");
|
||||
|
||||
if (frameMode == 0) {
|
||||
frameType = 1; //intra
|
||||
} else {
|
||||
frameType = 2; //inter
|
||||
}
|
||||
sis.readUB(6, "qp"); //qp
|
||||
int marker = (int) sis.readUB(1, "marker");
|
||||
if (frameMode == 0) {
|
||||
int version = (int) sis.readUB(5, "version");
|
||||
int version2 = (int) sis.readUB(2, "version2");
|
||||
sis.readUB(1, "interlace"); //interlace
|
||||
if (marker == 1 || version2 == 0) {
|
||||
sis.readUI16("offset"); //offset
|
||||
}
|
||||
int dim_y = sis.readUI8("dim_y");
|
||||
int dim_x = sis.readUI8("dim_x");
|
||||
sis.readUI8("render_y"); //render_y
|
||||
sis.readUI8("render_x"); //render_x
|
||||
horizontalAdjustment = (int) (dim_x * Math.ceil(((double) videoStream.width) / (double) dim_x)) - videoStream.width;
|
||||
verticalAdjustment = (int) (dim_y * Math.ceil(((double) videoStream.height) / (double) dim_y)) - videoStream.height;
|
||||
|
||||
}
|
||||
|
||||
SWFOutputStream sos = new SWFOutputStream(baos, swf.version);
|
||||
sos.writeUB(4, horizontalAdjustment);
|
||||
sos.writeUB(4, verticalAdjustment);
|
||||
}
|
||||
if (videoStream.codecID == DefineVideoStreamTag.CODEC_SORENSON_H263) {
|
||||
SWFInputStream sis = new SWFInputStream(swf, tag.videoData.getRangeData());
|
||||
sis.readUB(17, "pictureStartCode");//pictureStartCode
|
||||
sis.readUB(5, "version"); //version
|
||||
sis.readUB(8, "temporalReference"); //temporalReference
|
||||
int pictureSize = (int) sis.readUB(3, "pictureSize"); //pictureSize
|
||||
if (pictureSize == 0) {
|
||||
sis.readUB(8, "customWidth"); //customWidth
|
||||
sis.readUB(8, "customHeight"); //customHeight
|
||||
}
|
||||
if (pictureSize == 1) {
|
||||
sis.readUB(16, "customWidth"); //customWidth
|
||||
sis.readUB(16, "customHeight"); //customHeight
|
||||
}
|
||||
int pictureType = (int) sis.readUB(2, "pictureType");
|
||||
switch (pictureType) {
|
||||
case 0: //intra
|
||||
frameType = 1; //keyframe
|
||||
break;
|
||||
case 1://inter
|
||||
frameType = 2;
|
||||
break;
|
||||
case 2: //disposable
|
||||
frameType = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
baos.write(tag.videoData.getRangeData());
|
||||
flv.writeTag(new FLVTAG((int) Math.floor(i * 1000.0 / swf.frameRate), new VIDEODATA(frameType, videoStream.codecID, baos.toByteArray())));
|
||||
}
|
||||
return fos.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user