I am tyring to merge an .mov file with a .wav file using java media framework, thus I need to know their duration. How can I do this? Any ideas would be appreciated..
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- Can we recover audio from MFCC coefficients?
- StackExchange API - Deserialize Date in JSON Respo
you can learn the duration of sound files using this way(that is VitalyVal's second way):
I tried the accepted answer, but after getting exceptions with it, I decided to just do it the simple way.
If you have a few basic pieces of information, you can figure audio data length. The main pieces are:
If you have these, you can find out duration. Java is nice because it provides libraries to easily retrieve all of this information with minimal effort. Equation is below:
sample-rate * sample-size * duration * channel-count = file-size
See the code below that does this calculation in java:
Hope this helps someone out there! I've only tested it with WAV files, though.
I am not familiar with java media framework, but probably the following will help:
1) Theoretically you can get duration of a wav file from the "fact" chunk. But I doubt, JMF give direct access to the chunk. Moreover the chunk can contain an incorrect value.
2) You can calculate duration, knowing audio data size (in bytes) and sample rate (or bitrate).