# Play video with sound

**URL:** <https://discourse.processing.org/t/play-video-with-sound/45924>\
**Category:** Libraries\
**Created:** [March 7, 2025, 6:11am UTC](https://discourse.processing.org/t/play-video-with-sound/45924 "2025-03-07T06:11:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![poppanona](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@poppanona](https://discourse.processing.org/u/poppanona)\
**Post date:** [March 7, 2025, 6:11am UTC](https://discourse.processing.org/t/play-video-with-sound/45924/1 "2025-03-07T06:11:55Z")

</div>

Is there a way to incorparate the sound in a movie in one’s sketch

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2025, 12:11pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/2 "2025-03-07T12:11:06Z")

</div>

please elaborate.

- Do you mean a simple animation in processing where you play a sound (and produce your own movie from the images)

- Do you want to load a movie and place a sound in it and then save the movie as a changed file on the hard drive?

---

<div class="post-metadata">

**Author:** ![poppanona](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@poppanona](https://discourse.processing.org/u/poppanona)\
**Post date:** [March 13, 2025, 6:01pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/4 "2025-03-13T18:01:30Z")

</div>

I want to load a mp4 movie with it’s sound into my sketch. I can then run the sketch and then save it as an mp4 movie. I know how to do the later with screen recording.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [March 13, 2025, 6:47pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/5 "2025-03-13T18:47:16Z")

</div>

If you’re willing to use JavaFX it has a MediaPlayer:

```auto
import java.io.File;
import javafx.stage.Stage;
import javafx.scene.layout.Pane;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;

void setup() {
  size(1, 1, FX2D);
  Stage stage = new Stage();
  // ****Replace this with your file path**** //
  String path = "/Users/xxxx/Movies/yyyyy.mp4";
  Media media = new Media(new File(path).toURI().toString());
  MediaPlayer mediaPlayer = new MediaPlayer(media);
  MediaView mediaView = new MediaView(mediaPlayer);
  mediaPlayer.setAutoPlay(true);
  mediaView.setLayoutX(10);
  mediaView.setLayoutY(10);
  Pane pane = new Pane();
  pane.getChildren().add(mediaView);
  Scene scene = new Scene(pane, 500, 500);
  stage.setScene(scene);
  stage.setTitle("Playing video");
  stage.show();
}

```

**Output:**

 ![mp](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/7/6774cef282fdc3e91312dbc00b8477a0e7e2c508.jpeg)

---

<div class="post-metadata">

**Author:** ![poppanona](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@poppanona](https://discourse.processing.org/u/poppanona)\
**Post date:** [March 13, 2025, 8:26pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/6 "2025-03-13T20:26:10Z")

</div>

Thanks for the replys. I forgot to mention that my current plans for a solution is to format my sketch so that it had a place to locate my video, and then run the sketch while doing a screen recording.

I later will take the screen recording and the video file and combine the two in my video editor, Premier Elements. I have done trial runs with two mp4 videos and it works fine. I haven’t done it with a video created in Processing yet.

Svan, Where does your code produce an output mp4 file with sound?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [March 13, 2025, 8:48pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/7 "2025-03-13T20:48:28Z")

</div>

`Where does your code produce an output mp4 file with sound?`  
It doesn’t produce anything; it just plays a pre-existing .mp4 video (with sound if it has it). You stated that you already knew how to do a screen recording.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [March 15, 2025, 2:31pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/8 "2025-03-15T14:31:12Z")

</div>

A screen recording willhave poor quality compared to a proper video export.

What hardware acceleration do you have.

There’s no way your CPU can handle playing sound, animating your sketch, and recording the screen simultaneously without really bad performance; that’s not what a CPU is designed to do, that’s why GPUs and dedicated audio cards/chips exist.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [March 15, 2025, 2:36pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/9 "2025-03-15T14:36:16Z")

</div>

Perhaps this may be useful.

> <https://stackoverflow.com/questions/56312019/is-there-a-way-to-only-play-audio-from-a-video>

Though playing and then re-recording the sound is inefficient and will degrade sound.

Perhaps it makes more sense to simply record your sketch only (no sound), then sperate the audio from the video, and finally combine the sound and sketch animation.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [March 15, 2025, 2:45pm UTC](https://discourse.processing.org/t/play-video-with-sound/45924/10 "2025-03-15T14:45:21Z")

</div>

Try these:

`ffmpeg -i input-video.mp4 -vn -acodec copy output-audio.aac`  
`ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4`

You may find this useful: [HWAccelIntro – FFmpeg](https://trac.ffmpeg.org/wiki/HWAccelIntro)
