Skip to content

Commit

Permalink
Implement MP4Writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandelshofer committed Oct 3, 2024
1 parent 399689b commit 1070c8f
Show file tree
Hide file tree
Showing 109 changed files with 6,697 additions and 2,716 deletions.
3 changes: 1 addition & 2 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import javax.sound.sampled.TargetDataLine;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand Down Expand Up @@ -115,8 +116,9 @@ record AudioTargetInfo(Mixer mixer, Line.Info info, AudioFormat format) {
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, LineUnavailableException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 'at' HH.mm.ss");
File file = new File(System.getProperty("user.home"), "Movies/AudioRecording " + dateFormat.format(new Date()) + ".avi");
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd 'at' HH.mm.ss").withZone(ZoneId.systemDefault());
;
File file = new File(System.getProperty("user.home"), "Movies/AudioRecording " + dateFormat.format(Instant.now()) + ".avi");
if (!file.getParentFile().isDirectory()) {
file.getParentFile().mkdirs();
}
Expand All @@ -128,7 +130,8 @@ public static void main(String[] args) throws IOException, LineUnavailableExcept
Mixer mixer = AudioSystem.getMixer(info);
for (Line.Info info1 : mixer.getTargetLineInfo()) {
System.out.println(" " + info1);
if (info1 instanceof DataLine.Info dlInfo) {
if (info1 instanceof DataLine.Info) {
DataLine.Info dlInfo = (DataLine.Info) info1;
for (AudioFormat format : dlInfo.getFormats()) {
if (format.getEncoding() == AudioFormat.Encoding.PCM_SIGNED && format.getSampleRate() != AudioSystem.NOT_SPECIFIED) {
System.out.println((targetLines.size() + 1) + ". " + format);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void main(String[] args) throws IOException {
public void run() {
JFrame fr = new JFrame(f.getName());
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel(new ImageIcon(frames.getFirst()));
final JLabel label = new JLabel(new ImageIcon(frames.get(0)));
final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, frames.size() - 1, 0);

slider.addChangeListener(new ChangeListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ private static void info(MovieWriter w) throws IOException {
*/
private static void info(MovieReader in) throws IOException {
System.out.println(" Format: " + FormatFormatter.toString(in.getFileFormat()));
System.out.println(" Duration: " + in.getDuration().toDescriptiveString() + " seconds");
System.out.println(" Duration: " + in.getMovieDuration().toDescriptiveString() + " seconds");
for (int t = 0; t < in.getTrackCount(); t++) {
System.out.println(" Track " + t);
System.out.println(" Format: " + FormatFormatter.toString(in.getFormat(t)));
System.out.println(" Duration: " + in.getDuration(t).toDescriptiveString() + " seconds");
System.out.println(" Duration: " + in.getTrackDuration(t).toDescriptiveString() + " seconds");
System.out.println(" Chunk Count: " + in.getChunkCount(t));
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ private static Rational parseTime(String str, ArrayList<File> infiles, MovieRead
return Rational.valueOf(str);
} catch (NumberFormatException e) {
if (r[0] == null && !infiles.isEmpty()) {
r[0] = Registry.getInstance().getReader(infiles.getFirst());
r[0] = Registry.getInstance().getReader(infiles.get(0));
}
if (r[0] != null) {
int t = r[0].findTrack(0, new Format(MediaTypeKey, MediaType.VIDEO));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ private void dragExited(DragEvent event) {
private void dragDropped(DragEvent event) {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles() && db.getFiles() instanceof List<File> fileList && !fileList.isEmpty()) {
fileDroppedConsumer.accept(fileList.getFirst());
if (db.hasFiles()) {
List<File> files = db.getFiles();
if (files != null && !files.isEmpty()) {
fileDroppedConsumer.accept(files.get(0));
success = true;
}
}
event.setDropCompleted(success);
event.consume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void zoomToActualSize(ActionEvent event) {
}

void zoomTo(double power) {
MediaInterface media = getPlayer() instanceof MediaPlayerInterface p ? p.getMedia() : null;
MediaInterface media = getPlayer() instanceof MediaPlayerInterface ? getPlayer().getMedia() : null;
if (media == null) {
return;
}
Expand All @@ -135,7 +135,7 @@ private MediaPlayerInterface getPlayer() {
}

private double getZoomPower() {
MediaInterface media = getPlayer() instanceof MediaPlayerInterface p ? p.getMedia() : null;
MediaInterface media = getPlayer() instanceof MediaPlayerInterface ? getPlayer().getMedia() : null;
if (media == null) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ private void mouseDragged(MouseEvent event) {
double parentHeight = rootPane.getHeight();

int minimumAmountVisible = 10;
double newX = Math.clamp(controllerPane.getLayoutX() + dx, 0 - width + minimumAmountVisible, parentWidth - minimumAmountVisible);
double newY = Math.clamp(controllerPane.getLayoutY() + dy, 0 - height + minimumAmountVisible, parentHeight - minimumAmountVisible);
double newX = MathUtil.clamp(controllerPane.getLayoutX() + dx, 0 - width + minimumAmountVisible, parentWidth - minimumAmountVisible);
double newY = MathUtil.clamp(controllerPane.getLayoutY() + dy, 0 - height + minimumAmountVisible, parentHeight - minimumAmountVisible);

AnchorPane.setLeftAnchor(controllerPane, null);
AnchorPane.setRightAnchor(controllerPane, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.monte.demo.javafx.movieplayer.model.MediaInterface;
import org.monte.demo.javafx.movieplayer.model.TrackInterface;

import java.util.Objects;

/**
* Adapter for JavaFX {@link Media}.
*/
Expand All @@ -32,11 +34,17 @@ public class FXMedia implements MediaInterface {
public FXMedia(Media media) {
this.media = media;
for (Track track : media.getTracks()) {
switch (track) {
case VideoTrack t -> tracks.add(new FXVideoTrack(t));
case AudioTrack t -> tracks.add(new FXAudioTrack(t));
case SubtitleTrack t -> tracks.add(new FXSubtitleTrack(t));
default -> tracks.add(new FXTrack(track));
if (Objects.requireNonNull(track) instanceof VideoTrack) {
VideoTrack t = (VideoTrack) Objects.requireNonNull(track);
tracks.add(new FXVideoTrack(t));
} else if (track instanceof AudioTrack) {
AudioTrack t = (AudioTrack) track;
tracks.add(new FXAudioTrack(t));
} else if (track instanceof SubtitleTrack) {
SubtitleTrack t = (SubtitleTrack) track;
tracks.add(new FXSubtitleTrack(t));
} else {
tracks.add(new FXTrack(track));
}
}

Expand All @@ -51,11 +59,17 @@ public void onChanged(Change<? extends Track> c) {
if (c.wasAdded()) {
int i = c.getFrom();
for (Track track : c.getAddedSubList()) {
switch (track) {
case VideoTrack t -> tracks.add(i, new FXVideoTrack(t));
case AudioTrack t -> tracks.add(i, new FXAudioTrack(t));
case SubtitleTrack t -> tracks.add(i, new FXSubtitleTrack(t));
default -> tracks.add(i, new FXTrack(track));
if (Objects.requireNonNull(track) instanceof VideoTrack) {
VideoTrack t = (VideoTrack) Objects.requireNonNull(track);
tracks.add(i, new FXVideoTrack(t));
} else if (track instanceof AudioTrack) {
AudioTrack t = (AudioTrack) track;
tracks.add(i, new FXAudioTrack(t));
} else if (track instanceof SubtitleTrack) {
SubtitleTrack t = (SubtitleTrack) track;
tracks.add(i, new FXSubtitleTrack(t));
} else {
tracks.add(i, new FXTrack(track));
}
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public MonteMedia(File source) {

public void dispose() {
for (var tr : tracks) {
if (tr instanceof MonteTrackInterface mtr) {
if (tr instanceof MonteTrackInterface) {
MonteTrackInterface mtr = (MonteTrackInterface) tr;
mtr.dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void initialize() {
}

private void addTrack(TrackInterface tr) {
if (tr instanceof MonteVideoTrack vt) {
if (tr instanceof MonteVideoTrack) {
MonteVideoTrack vt = (MonteVideoTrack) tr;
ImageView imageView = new ImageView();
imageView.imageProperty().bind(vt.videoImageProperty());
Format format = vt.getFormat();
Expand Down Expand Up @@ -116,7 +117,8 @@ public void onChanged(Change<? extends TrackInterface> c) {
private void removeTrack(TrackInterface remitem) {
Node remove = trackMap.remove(remitem);
group.getChildren().remove(remove);
if (remove instanceof ImageView imageView) {
if (remove instanceof ImageView) {
ImageView imageView = (ImageView) remove;
imageView.imageProperty().unbind();
}
}
Expand Down
Loading

0 comments on commit 1070c8f

Please sign in to comment.