Ejemplo n.º 1
0
 /** Sets initial paths and conditions for an opened file */
 public void initializeSubEditor(String option) {
   String path = tools.getFileChooser("SRT files only", option + " subtitle file", "srt");
   // Enable edit options for a valid srt file
   if (path != null) {
     openSubtitle.setText(path.substring(path.lastIndexOf("/") + 1, path.length()));
     editSubtitle.setEnabled(true);
     subEditor.panel.setInputFile(path);
     SubtitleEditor.model.fireTableDataChanged();
     subEditor.setVisible(true);
   }
 }
Ejemplo n.º 2
0
  /**
   * Constructor sets up layout of buttons and calls methods to set up functionality. Adds subtitle
   * editing and video filter options to the frame.
   *
   * @param controls
   */
  public VideoSettings(final VidivoxGUI controls) {
    /* Set up layout and access to controls */
    this.controls = controls;
    setLayout(new GridBagLayout());
    tools.getTitle("Video Settings", this);

    /*Initialise and add implementations for buttons */
    setUpButtons();
    addSubtitleListeners();
    addVideoFilterListeners();

    /* Add subtitle and video filter panels */
    subEditor = new SubtitleFrame();
    vidFilter = new VideoFilter();
    GridBagConstraints gbc = tools.addConstraints(vidFilter, 0, 2, 8, 8, false);
    add(vidFilter, gbc);

    /* Select buttons to be enabled/disabled for user limitation */
    Common.activeBtns.add(apply);
    Common.activeBtns.add(preview);
  }
Ejemplo n.º 3
0
  /** Setup button positioning on panel */
  private void setUpButtons() {
    /* Initialize buttons */
    apply = new JButton("Apply changes");
    apply.setIcon(applyIcon);
    apply.setHorizontalAlignment(SwingConstants.RIGHT);
    preview = new JButton("Preview");
    openSubtitle = new JButton("Load subtitle file (.srt)");
    createSub = new JButton("Create subtitle file (.srt)");
    editSubtitle = new JButton("Edit Subtitles");
    editSubtitle.setEnabled(false);

    /* Add buttons to locations in the panel */
    GridBagConstraints gbc = tools.addConstraints(openSubtitle, 0, 12, 4, 1, true);
    add(openSubtitle, gbc);
    gbc = tools.addConstraints(createSub, 4, 12, 4, 1, true);
    add(createSub, gbc);
    gbc = tools.addConstraints(editSubtitle, 0, 13, 8, 1, true);
    add(editSubtitle, gbc);
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(preview);
    buttonPanel.add(apply);
    gbc = tools.addConstraints(buttonPanel, 0, 11, 8, 1, true);
    add(buttonPanel, gbc);
  }
 private NodeList getAssetFiles(String resource) {
   return Common.stopRecordingParseCharlesSession(resource);
 }
Ejemplo n.º 5
0
/**
 * Used to apply video edits to the video. Is the main class for video settings, using other classes
 * including SubtitleEditor and VideoFilter to bring together and implement video settings. Control
 * center for editing subtitles or applying video filters
 *
 * @author pban945
 */
@SuppressWarnings("serial")
public class VideoSettings extends JPanel {
  // For access to tools and controls
  private Common tools = new Common();
  private VidivoxGUI controls;
  // Video editing functionality
  public static VideoFilter vidFilter;
  private SubtitleFrame subEditor;
  private double audRate, vidRate;
  private String extraAudio;
  // Buttons and icon
  private JButton openSubtitle, createSub, editSubtitle, preview, apply;
  private ImageIcon applyIcon =
      new ImageIcon(tools.createIcon(getClass().getResource("/icons/apply.png"), 18, 18));

  /**
   * Constructor sets up layout of buttons and calls methods to set up functionality. Adds subtitle
   * editing and video filter options to the frame.
   *
   * @param controls
   */
  public VideoSettings(final VidivoxGUI controls) {
    /* Set up layout and access to controls */
    this.controls = controls;
    setLayout(new GridBagLayout());
    tools.getTitle("Video Settings", this);

    /*Initialise and add implementations for buttons */
    setUpButtons();
    addSubtitleListeners();
    addVideoFilterListeners();

    /* Add subtitle and video filter panels */
    subEditor = new SubtitleFrame();
    vidFilter = new VideoFilter();
    GridBagConstraints gbc = tools.addConstraints(vidFilter, 0, 2, 8, 8, false);
    add(vidFilter, gbc);

    /* Select buttons to be enabled/disabled for user limitation */
    Common.activeBtns.add(apply);
    Common.activeBtns.add(preview);
  }

  /** Setup button positioning on panel */
  private void setUpButtons() {
    /* Initialize buttons */
    apply = new JButton("Apply changes");
    apply.setIcon(applyIcon);
    apply.setHorizontalAlignment(SwingConstants.RIGHT);
    preview = new JButton("Preview");
    openSubtitle = new JButton("Load subtitle file (.srt)");
    createSub = new JButton("Create subtitle file (.srt)");
    editSubtitle = new JButton("Edit Subtitles");
    editSubtitle.setEnabled(false);

    /* Add buttons to locations in the panel */
    GridBagConstraints gbc = tools.addConstraints(openSubtitle, 0, 12, 4, 1, true);
    add(openSubtitle, gbc);
    gbc = tools.addConstraints(createSub, 4, 12, 4, 1, true);
    add(createSub, gbc);
    gbc = tools.addConstraints(editSubtitle, 0, 13, 8, 1, true);
    add(editSubtitle, gbc);
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(preview);
    buttonPanel.add(apply);
    gbc = tools.addConstraints(buttonPanel, 0, 11, 8, 1, true);
    add(buttonPanel, gbc);
  }

  /** Implement subtitle functionality */
  private void addSubtitleListeners() {
    /* Load a subtitle file */
    openSubtitle.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            initializeSubEditor("Open");
          }
        });
    /* Create new subtitle file */
    createSub.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            initializeSubEditor("Save");
          }
        });
    /* Edit the loaded subtitle file */
    editSubtitle.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Show and update subtitle editor
            subEditor.setVisible(true);
            SubtitleEditor.model.fireTableDataChanged();
            // Pause the video components in the editor to show frames only
            SubtitleEditor.player1.play();
            SubtitleEditor.player2.play();
            try {
              Thread.sleep(200);
            } catch (InterruptedException e1) {
            }
            SubtitleEditor.player1.getOurMediaPlayer().pause();
            SubtitleEditor.player2.getOurMediaPlayer().pause();
          }
        });
  }

  /** Sets the appropriate output of the video based on preview or apply modes */
  public void addVideoFilterListeners() {
    /*Set up preview using ffplay for previewing */
    preview.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setRates();
            String path = Main.player.getVideoFile();
            String cmd =
                "ffplay -i \""
                    + path
                    + "\" -vf \""
                    + vidFilter.getValues()
                    + "setpts="
                    + vidRate
                    + "*PTS\" -af \"atempo="
                    + audRate
                    + extraAudio
                    + "\"";
            SettingsFrame.progress.setIndeterminate(true);
            new RateWorker("preview", cmd, 1 / vidRate, null).execute();
          }
        });
    /* Set up apply using ffmpeg for writing changes */
    apply.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setRates();
            String path = Main.player.getVideoFile();
            SettingsFrame.progress.setIndeterminate(false);
            // Increment number of changes to get unique filename
            controls.numberOfChanges++;
            String output = Common.appDir + controls.numberOfChanges + controls.edittedFile;
            String cmd =
                "ffmpeg -y -i \""
                    + path
                    + "\" -vf \""
                    + vidFilter.getValues()
                    + "setpts="
                    + vidRate
                    + "*PTS\" -af \"atempo="
                    + audRate
                    + extraAudio
                    + "\" -strict -2 \""
                    + output
                    + "\"";
            controls.originalFile = output;
            new RateWorker("save", cmd, 1 / vidRate, controls).execute();
            Common.activateBtns(false);
          }
        });
  }

  /** Set the selected rates to be passed onto the ffmpeg command */
  public void setRates() {
    // Compute rates to be passed to command
    double selectedRate = (Double) vidFilter.rateBox.getSelectedItem();
    vidRate = 1 / selectedRate;
    audRate = selectedRate;
    extraAudio = "";
    // Multiple audio rate commands required for rate>2
    if (audRate > 2.0) {
      double extra = 0;
      extra = audRate / 2;
      audRate = 2;
      extraAudio = ",atempo=" + extra;
    }
  }

  /** Sets initial paths and conditions for an opened file */
  public void initializeSubEditor(String option) {
    String path = tools.getFileChooser("SRT files only", option + " subtitle file", "srt");
    // Enable edit options for a valid srt file
    if (path != null) {
      openSubtitle.setText(path.substring(path.lastIndexOf("/") + 1, path.length()));
      editSubtitle.setEnabled(true);
      subEditor.panel.setInputFile(path);
      SubtitleEditor.model.fireTableDataChanged();
      subEditor.setVisible(true);
    }
  }

  /** Opens subtitle editor in new window */
  class SubtitleFrame extends JFrame {
    // Initialize editor component
    SubtitleEditor panel = new SubtitleEditor(controls);

    public SubtitleFrame() {
      super("Subtitle Editor");
      /* Set the dimensions and layout */
      setBounds(600, 200, 800, 420);
      setResizable(false);
      JPanel contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.add(panel);
    }
  }
}