Home Java: playing audio from a youtube video
Reply: 1

Java: playing audio from a youtube video

Victor Florintsev
1#
Victor Florintsev Published in 2017-12-05 22:53:31Z

I'm thinking about coding a Java applet that would take in the top 100 or so songs, find their samples (music that appears within the songs) off WhoSampled.com and then playing those samples off of YouTube.

My problem is the playing part, let's say I have the URL. What's the best way to deal with that in Java, do you think ripping the audio off and playing the audio from there would be best, or should I try to control a sentient YouTube player.

I'm leaning towards extracting the audio, and this: thread mentions a way to extract that audio, however the code:

  wget http://www.youtube.com/get_video.php?video_id=... 
  ffmpeg -i - audio.mp3

Is not written in Java. How do I, if possible convert this to run in a Java program? Or does anyone know a good way in Java

Thank you for your suggestions.

Charlystar
2#
Charlystar Reply to 2017-12-06 00:47:43Z

You can use an FFMPEG Java wrapper like this one https://github.com/bramp/ffmpeg-cli-wrapper/

An example can be found in Readme. Converting MP4 to mp3 should be like this:

FFmpeg ffmpeg = new FFmpeg("/path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");

FFmpegBuilder builder = new FFmpegBuilder()

  .setInput("input.mp4")     // Filename, or a FFmpegProbeResult
  .overrideOutputFiles(true) // Override the output if it exists

  .addOutput("output.mp3")   // Filename for the destination
    .setFormat("mp3")        // Format is inferred from filename, or can be set
    .setAudioCodec("aac")        // using the aac codec
    .setAudioSampleRate(48_000)  // at 48KHz
    .setAudioBitRate(32768)      // at 32 kbit/s

    .done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

// Run a one-pass encode
executor.createJob(builder).run();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30807 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO