From 196d9523ea049f39379aa83d5f4dbeea8958806a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Tue, 5 Mar 2013 20:45:36 +0100 Subject: [PATCH] exporting MP3 --- .../src/com/jpexs/decompiler/flash/Main.java | 2 +- trunk/src/com/jpexs/decompiler/flash/SWF.java | 45 +++++++++++++------ .../decompiler/flash/gui/ExportDialog.java | 2 +- .../jpexs/decompiler/flash/gui/MainFrame.java | 9 ++-- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/Main.java b/trunk/src/com/jpexs/decompiler/flash/Main.java index 4459d63cb..4a073a466 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/Main.java @@ -555,7 +555,7 @@ public class Main { exfile.exportMovies(outDir.getAbsolutePath()); exportOK = true; } else if (exportFormat.equals("sound")) { - exfile.exportSounds(outDir.getAbsolutePath()); + exfile.exportSounds(outDir.getAbsolutePath(), true); exportOK = true; } else { exportOK = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 888129b10..2789f0322 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -485,11 +485,11 @@ public class SWF { exportMovies(outdir, tags); } - public void exportSounds(String outdir) throws IOException { - exportSounds(outdir, tags); + public void exportSounds(String outdir, boolean mp3) throws IOException { + exportSounds(outdir, tags, mp3); } - public void exportSounds(String outdir, List tags) throws IOException { + public void exportSounds(String outdir, List tags, boolean mp3) throws IOException { if (!(new File(outdir)).exists()) { (new File(outdir)).mkdirs(); } @@ -501,25 +501,44 @@ public class SWF { if (t instanceof DefineSoundTag) { id = ((DefineSoundTag) t).soundId; } - fos = new FileOutputStream(outdir + File.separator + id + ".flv"); - FLVOutputStream flv = new FLVOutputStream(fos); - flv.writeHeader(true, false); + if (mp3) { + } + if (t instanceof DefineSoundTag) { DefineSoundTag st = (DefineSoundTag) t; - flv.writeTag(new FLVTAG(0, new AUDIODATA(st.soundFormat, st.soundRate, st.soundSize, st.soundType, st.soundData))); + if ((st.soundFormat == 2) && mp3) { + fos = new FileOutputStream(outdir + File.separator + id + ".mp3"); + fos.write(st.soundData); + } else { + fos = new FileOutputStream(outdir + File.separator + id + ".flv"); + FLVOutputStream flv = new FLVOutputStream(fos); + flv.writeHeader(true, false); + flv.writeTag(new FLVTAG(0, new AUDIODATA(st.soundFormat, st.soundRate, st.soundSize, st.soundType, st.soundData))); + } } if (t instanceof SoundStreamHeadTypeTag) { SoundStreamHeadTypeTag shead = (SoundStreamHeadTypeTag) t; List blocks = new ArrayList(); List objs = new ArrayList(this.tags); populateSoundStreamBlocks(objs, t, blocks); - int ms = (int) (1000.0f / ((float) frameRate)); - for (int b = 0; b < blocks.size(); b++) { - byte data[] = blocks.get(b).getData(SWF.DEFAULT_VERSION); - if (shead.getSoundFormat() == 2) { //MP3 - data = Arrays.copyOfRange(data, 4, data.length); + if ((shead.getSoundFormat() == 2) && mp3) { + fos = new FileOutputStream(outdir + File.separator + id + ".mp3"); + for (int b = 0; b < blocks.size(); b++) { + fos.write(blocks.get(b).getData(SWF.DEFAULT_VERSION)); + } + } else { + fos = new FileOutputStream(outdir + File.separator + id + ".flv"); + FLVOutputStream flv = new FLVOutputStream(fos); + flv.writeHeader(true, false); + + int ms = (int) (1000.0f / ((float) frameRate)); + for (int b = 0; b < blocks.size(); b++) { + byte data[] = blocks.get(b).getData(SWF.DEFAULT_VERSION); + if (shead.getSoundFormat() == 2) { //MP3 + data = Arrays.copyOfRange(data, 4, data.length); + } + flv.writeTag(new FLVTAG(ms * b, new AUDIODATA(shead.getSoundFormat(), shead.getSoundRate(), shead.getSoundSize(), shead.getSoundType(), data))); } - flv.writeTag(new FLVTAG(ms * b, new AUDIODATA(shead.getSoundFormat(), shead.getSoundRate(), shead.getSoundSize(), shead.getSoundType(), data))); } } } finally { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java index 54ea56eaf..8401fe17b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java @@ -21,7 +21,7 @@ public class ExportDialog extends JDialog { {"SVG"}, {"PNG/JPEG"}, {"FLV (No audio)"}, - {"FLV (Audio only)"}, + {"MP3/FLV","FLV (Audio only)"}, {"AS", "PCODE"} }; String optionNames[] = { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 5fe589ad4..5801cb78b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1074,7 +1074,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } if (e.getActionCommand().startsWith("EXPORT")) { - ExportDialog export = new ExportDialog(); + final ExportDialog export = new ExportDialog(); export.setVisible(true); if (!export.cancelled) { JFileChooser chooser = new JFileChooser(); @@ -1087,7 +1087,8 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi Main.startWork("Exporting..."); final String selFile = chooser.getSelectedFile().getAbsolutePath(); Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath()); - final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; + final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; + final boolean isMp3 = export.getOption(ExportDialog.OPTION_SOUNDS) == 0; final boolean onlySel = e.getActionCommand().endsWith("SEL"); (new Thread() { @Override @@ -1137,7 +1138,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi SWF.exportImages(selFile + File.separator + "images", images, jtt); SWF.exportShapes(selFile + File.separator + "shapes", shapes); swf.exportMovies(selFile + File.separator + "movies", movies); - swf.exportSounds(selFile + File.separator + "sounds", sounds); + swf.exportSounds(selFile + File.separator + "sounds", sounds, isMp3); if (abcPanel != null) { for (int i = 0; i < tlsList.size(); i++) { TreeLeafScript tls = tlsList.get(i); @@ -1158,7 +1159,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi swf.exportImages(selFile + File.separator + "images"); swf.exportShapes(selFile + File.separator + "shapes"); swf.exportMovies(selFile + File.separator + "movies"); - swf.exportSounds(selFile + File.separator + "sounds"); + swf.exportSounds(selFile + File.separator + "sounds", isMp3); swf.exportActionScript(selFile, isPcode); } } catch (Exception ignored) {