Java: How to read available audio tracks in a video file? - java

Some video files contain multiple audio tracks. Multiple languages for example. Is there a library which gets information about these audio tracks? Names of the audio tracks would be sufficient.
It should support common formats (mkv, avi,...)

I believe the best monolithic media file library available is that for VLC player. I seem to remember there was a Java wrapper, but it's probably not maintained (like all Java wrappers more than a few weeks old heheh).

I have found a solution to my problem. From Java I call the following command:
ffmpeg -i myvideo.mkv
Then I read the commands output and filter the lines which start with Stream #.
This works on all my files with multiple audio tracks.

Related

How to split a live audio stream into separate channels and save to files?

I am trying to take an online MP3 (icecast) stream which plays one thing on the left, and another thing on the right and split that into 2 separate files. I transferred the stream to a wav file that keeps growing. Now I want to save 2 additional files for the two separate channels. I found some other solutions around the web but they only seem to work for full wav files, but because it is a live stream and the file keeps growing they didn't work for this.
I am trying to do this in Java.
Just shell out to FFmpeg. This is trivial to do there.
ffmpeg -i <your stream> -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
See also: https://trac.ffmpeg.org/wiki/AudioChannelManipulation

Java web app. Merge audio and video

I have two files - audio(mp3 or wav) and video(mp4 or avi) with the same duration. I want to merge them and send to the front.
Which java library will help me to implement that?
If you mean you want to merge the audio and the video on the server side, so that the merged video can then be streamed to the client, then using ffmpeg via a wrapper may be the easiest approach.
The ffmpeg command line is well used and it is quite easy to ask and receive answers to any particular syntax. Using a Java wrapper approach allows you leverage this syntax and give you the flexablity to use other ffmpeg functionality in the future if you need it.
A popular up to date Java Wrapper is available here:
https://github.com/bramp/ffmpeg-cli-wrapper
If you actually want to stream the audio and the video to the browser separately and do the merging there, then, if you are not worried about an exact match (e.g. needing to synch audio to speech to keep it in lip synch), you can actually just start the audio player and video player simultaneously and the browser will play both together. This worked on all major browsers I tested it on for a project several years ago and I am not aware of anything changing to stop this working.

Streaming video files users have uploaded

We have a java web application where users can upload all kinds of files including any kind of video files. Now we want to allow them to stream these video files they own. So I need to make sure that they are the owner and then stream video. Also possibly stream a preview.
Do I need to convert these video files before streaming and where should I look to get started?
The best video playback/encoding library I have ever seen is ffmpeg. It plays everything you throw at it. (It is used by MPlayer.) It is written in C but I found some Java wrappers.
FFMPEG-Java: A Java wrapper around ffmpeg using JNA.
jffmpeg: This one integrates to JMF.

How to distinguish between audio file and video file?

I am using Java to write a media application.
Given a file, how can I know is it a audio file or video file?
By the way, I use vlcj library.
In Java 7 you will be able to use java.nio.file.probeContentType to do this.
In the meantime, there are a number of other options for doing this kind of thing.

media conversion library/plugin preferably php

I am looking for an media conversion library that can convert and compress various media i.e both audio and video files to various formats.
FFMPEG-PHP is a popular choice for extracting information. It doesn't re-encode files, though. http://ffmpeg-php.sourceforge.net/
But if you have an instance of FFMPEG installed on the machine, you can call FFMPEG via the exec function in php.
Eg: exec(’ffmpeg -i ‘.$SourcePath.’ ‘.$Destination);
I think your best bet is ffmpeg-php (can be used for both audio and video conversions). Imagemagick has a few basic video conversion options as well.
A second option would be to use mencoder from the MPlayer project (again, you'll have to call this as a command line tool). The main difference between ffmpeg and MPlayer is that the former comes with open source codecs while the latter comes with a host of codecs from all kinds of sources plus it uses ffmpeg.
So ffmpeg is a little more simple to use, MPlayer can convert between many more formats but the command line gets pretty complex.

Categories