Merge Audio And Video [Help]

Dear, Guys ...
I need some help..... my problems, when i m trying merge the video and audio, just the audio can show out......
this is the code :
private boolean mergeAudioVideo() {
     try {
String tempTotal = myGrabber.tempFile + myGrabber.cntMovies + myGrabber.extension;
String audioFile = "";
System.out.println(myGrabber.movPath + tempTotal);
audioFile = mySampler.audioFile.toURL().toString();
String mergeArguments[] = {"-o", myGrabber.movFile,     myGrabber.movPath + tempTotal, audioFile};
if (!myProgressBar.cancelled) {
new Merge(mergeArguments, myProgressBar);
return true;
} else {
return false;
     } catch (Exception e) {
outWindow.out("Gagal menggabungkan file - file");
outWindow.out("" + e);
} catch (OutOfMemoryError o) {
outWindow.out("Gagal menggabungkan file - file");
outWindow.out("" + o);
return true;
merge.java
package camcap.Recording;
* @author Shinlei
import java.io.File;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.datasink.*;
import java.util.Vector;
* Menggabungkan jalur - jalur dari input yang berbeda dan menghasilkan sebuah file QuickTime
* dengan jalur - jalur yang sudah digabung
public class Merge implements ControllerListener, DataSinkListener {
Vector sourcesURLs = new Vector(1);
Processor [] processors = null;
String outputFile = null;
String videoEncoding = "JPEG";
String audioEncoding = "LINEAR";
String outputType = FileTypeDescriptor.QUICKTIME;
DataSource [] dataOutputs = null;
DataSource merger = null;
DataSource outputDataSource;
Processor outputProcessor;
ProcessorModel outputPM;
DataSink outputDataSink;
MediaLocator outputLocator;
boolean done = false;
VideoFormat videoFormat = null;
AudioFormat audioFormat = null;
public camcap.UserInterface.EncodingProgressBar myProgressBar;
public Merge(String [] args) {
     parseArgs(args);
     if (sourcesURLs.size() < 2) {
     System.err.println("Need at least two source URLs");
     showUsage();
     } else {
     doMerge();
public Merge(String [] args, camcap.UserInterface.EncodingProgressBar p) {
myProgressBar = p;
     parseArgs(args);
     if (sourcesURLs.size() < 2) {
     System.err.println("Need at least two source URLs");
     showUsage();
     } else {
     doMerge();
private void doMerge() {
     int i = 0;
     processors = new Processor[sourcesURLs.size()];
     dataOutputs = new DataSource[sourcesURLs.size()];
     for (i = 0; i < sourcesURLs.size(); i++) {
     String source = (String) sourcesURLs.elementAt(i);
     MediaLocator ml = new MediaLocator(source);
     ProcessorModel pm = new MyPM(ml);
     try {
          processors[i] = Manager.createRealizedProcessor(pm);
          dataOutputs[i] = processors.getDataOutput();
          processors[i].start();
     } catch (Exception e) {
          System.err.println("Failed to create a processor: " + e);
          System.exit(-1);
     try {
     merger = Manager.createMergingDataSource(dataOutputs);
     merger.connect();
     merger.start();
     } catch (Exception ex) {
     System.err.println("Failed to merge data sources: " + ex);
     System.exit(-1);
     if (merger == null) {
     System.err.println("Failed to merge data sources");
     System.exit(-1);
     try {
     Player p = Manager.createPlayer(merger);
     new com.sun.media.ui.PlayerWindow(p);
     } catch (Exception e) {
     System.err.println("Failed to create player " + e);
     // Membuat output dari processor
     ProcessorModel outputPM = new MyPMOut(merger);
     try {
     outputProcessor = Manager.createRealizedProcessor(outputPM);
     outputDataSource = outputProcessor.getDataOutput();
     } catch (Exception exc) {
     System.err.println("Failed to create output processor: " + exc);
     System.exit(-1);
     try {
     outputLocator = new MediaLocator(outputFile);
     outputDataSink = Manager.createDataSink(outputDataSource, outputLocator);
     outputDataSink.open();
     } catch (Exception exce) {
     System.err.println("Failed to create output DataSink: " + exce);
     System.exit(-1);
     outputProcessor.addControllerListener(this);
     outputDataSink.addDataSinkListener(this);
     System.err.println("Merging...");
     try {
     outputDataSink.start();
     outputProcessor.start();
     } catch (Exception excep) {
     System.err.println("Failed to start file writing: " + excep);
     System.exit(-1);
     int count = 0;
     while (!done) {
     try {
          Thread.currentThread().sleep(100);
     } catch (InterruptedException ie) {
try {
if (myProgressBar.cancelled) {
try {
outputDataSink.stop();
outputProcessor.stop();
done = true;
System.out.println("Stopped merge datasink");
} catch (Exception e) {
System.out.println("Couldn't stop merge datasink");
System.out.println(e);
} catch (Exception e) {}
     if (outputProcessor != null &&
          (int)(outputProcessor.getMediaTime().getSeconds()) > count) {
          System.err.print(".");
          count = (int)(outputProcessor.getMediaTime().getSeconds());
     if (outputDataSink != null) {
     outputDataSink.close();
     synchronized (this) {
     if (outputProcessor != null) {
          outputProcessor.close();
     System.err.println("Done!");
public void controllerUpdate(ControllerEvent ce) {
     if (ce instanceof EndOfMediaEvent) {
     synchronized (this) {
          outputProcessor.close();
          outputProcessor = null;
public void dataSinkUpdate(DataSinkEvent dse) {
     if (dse instanceof EndOfStreamEvent) {
     done = true;
     } else if (dse instanceof DataSinkErrorEvent) {
     done = true;
class MyPM extends ProcessorModel {
     MediaLocator inputLocator;
     public MyPM(MediaLocator inputLocator) {
     this.inputLocator = inputLocator;
     public ContentDescriptor getContentDescriptor() {
     return new ContentDescriptor(ContentDescriptor.RAW);
     public DataSource getInputDataSource() {
     return null;
     public MediaLocator getInputLocator() {
     return inputLocator;
     public Format getOutputTrackFormat(int index) {
     return null;
     public int getTrackCount(int n) {
     return n;
     public boolean isFormatAcceptable(int index, Format format) {
     if (videoFormat == null) {
          videoFormat = new VideoFormat(videoEncoding);
     if (audioFormat == null) {
          audioFormat = new AudioFormat(audioEncoding);
     if (format.matches(videoFormat) || format.matches(audioFormat))
          return true;
     else
          return false;
class MyPMOut extends ProcessorModel {
     DataSource inputDataSource;
     public MyPMOut(DataSource inputDataSource) {
     this.inputDataSource = inputDataSource;
     public ContentDescriptor getContentDescriptor() {
     return new FileTypeDescriptor(outputType);
     public DataSource getInputDataSource() {
     return inputDataSource;
     public MediaLocator getInputLocator() {
     return null;
     public Format getOutputTrackFormat(int index) {
     return null;
     public int getTrackCount(int n) {
     return n;
     public boolean isFormatAcceptable(int index, Format format) {
     if (videoFormat == null) {
          videoFormat = new VideoFormat(videoEncoding);
     if (audioFormat == null) {
          audioFormat = new AudioFormat(audioEncoding);
     if (format.matches(videoFormat) || format.matches(audioFormat))
          return true;
     else
          return false;
private void showUsage() {
     System.err.println("Usage: Merge <url1> <url2> [<url3> ... ] [-o <out URL>] [-v <video_encoding>] [-a <audio_encoding>] [-t <content_type>]");
private void parseArgs(String [] args) {
     int i = 0;
     while (i < args.length) {
     if (args[i].equals("-h")) {
          showUsage();
     } else if (args[i].equals("-o")) {
          i++;
          outputFile = args[i];
     } else if (args[i].equals("-t")) {
          i++;
          outputType = args[i];
     } else if (args[i].equals("-v")) {
          i++;
          videoEncoding = args[i];
     } else if (args[i].equals("-a")) {
          i++;
          audioEncoding = args[i];
     } else {
          sourcesURLs.addElement(args[i]);
     i++;
     if (outputFile == null) {
     outputFile = "file:" + System.getProperty("user.dir") + File.separator + "merged.avi";
public static void main(String [] args) {
     new Merge(args);
     System.exit(0);
ii can't find the problems, can anyone help me?
Thanks,
Shin

Even manually I configured & realized the processors for input files.
My application is getting blocked in following mentioned snippet of code.
while (!done)
         if (outputProcessor != null
              && (int) (outputProcessor.getMediaTime().getSeconds()) > count)
          count = (int) (outputProcessor.getMediaTime().getSeconds());
          logger.debug("Merging is in progress...");
     }This is happening when I try merge large video , audio files only. Is this limitation of JMF or any mistake in app.
Please suggest any idea or link by which I get some solution.

Similar Messages

  • How to demultiplex the merged audio and video streams

    Hi. I'm currently working on a video conferencing program. I successfully implemented the program using threads to run the audio and the video clients and servers. The problem with this is that the delay for the transmission of both media is a little too great. So now, I'm trying to merge both media into on DataSource, so then I don't have to worry about sending audio and video into 2 different ports and RTP sessions. I know how to merge the audio and video streams, but I was wondering how to extract each media back after receiving the merged audio and video streams. Any ideas? I used the createMergingDataSource(the_DataSource_array) method to merge both streams. Thanks.
    J.L.

    I am working on the same problem. Is there any solution yet?
    Regards
    C.Eckert

  • Trouble merging audio and video

    Hi everybody. I'm using 'merge clips' to combine audio recorded separately from video. We also had a mic on the camera, so we can hear how it syncs up. The clip is an hour long. The audio starts out in sync, but gradually and steadily lags behind the video. The audio ends up being 1-2 frames behind every 30 seconds or so. Very annoying. Any idea why this would happen and how to fix?

    wing hunter wrote: unknown audio recording device. I got them as wav files.
    I would be hunting down the guy who recorded them, finding out what the unknown device is, and what its settings are/were at the time, as well as what they did before delivering the files. Were they imported from the device into some sort of software? File conversions? I know ProTools projects have selectable frame rates, and that needs to match your footage frame rate or you will have sync issues.
    Lots of variables that need to be determined before we can help.

  • FCP7; "unmerge" merged audio and video clips in the timeline?

    Our TC was way off in some areas due to a bad timecode lemo on set. My editor synched by slate then merged the video with an audio mixdown track using the in points. Now when I export an EDL the original TC from the audio clip is gone, so he has no reference for matching up the audio. Does anybody know of a way to un-merge these clips and restore the original filename (audio takes the name of merged video but reveals correctly in finder) and timecode? Thanks.

    what happens if you match frame the audio?  I would think it would match back to the source audio clip which you could then use to replace the audio in the timeline.

  • Merge audio to video clips, end of clip loses audio

    This is driving me nuts. After merging audio and video clips, sync to slate using the in points, everything is in sync.
    The audio is longer than the video itself. But WAY before the scene ends, the audio mutes. The waveforms are visable but no audio plays. It drop out. It happens to every merged clip I create. I don't use the out points either.
    Anyone else have this issue??
    If I take an alternate method to sync them in the timeline and create a clip from there, it makes a new sequence clip losing the scene and take metadata. That's not good. Is there a workaround?

    It happens on every project and different formats. I do use FCP Rescue and that doesn't solve it. I did figure out a work around which involves a few more steps and is more time consuming. Maybe this can help find the problem. Here is the ridiculous workaround steps. We should send this to Apple.
    The "--" are the extra steps.
    To get a good merged subclip.
    Open the audio file and add the 'in point' to the slate.
    --Drag audio clip to the timeline.
    --Drag the audio clip from the timeline to the browser window.
    Merge with video.
    Viola. Audio won't drop out. But the waveforms are completely off with the sound.
    Next step is to open the merged clips and Make Subclip so you don't have that extra media in the beginning and end. And the waveform seem normal.

  • Can i take both Receveing of audio and video on the same window.

    hi,
    i m using AVTransmit2 and AVReceive2 for Transmission and Receiving all is doing well but problem is that AVReceive2 show Transmission of audio and video in both different windows and it use different players for audio and video. Can u tell me can i merge both audio and video at the receiving end. i m already mergeing audio and video at transmission end ???. any one tell me how can i solve this problem ???
    thx in advance.

    Hi,
    I have the same situation - to use one window to show both rtp audio and video stream, but use the ControlPanelComponent of audio player to control both players.
    I want to use the audio player as the master player so that the video player could be synchronized with it. So: audioPlayer.addController(videoPlayer).
    In the only window frame for both players, I want to show the VisualComponent(VC) of video and the ControlPanelComponent(CC) of audio. So I add both components respectly to the window frame, after I got them from each player. Because the streams are coming from the network over RTP, and they do not become realized at the same time, I add the VC and CC of first realized player(no matter it is audio or video) to window frame at first, and then change them to the desired video VC and audio audio CC.
    Though I check both player are realized and not started before I call the addController() method, the application stucked in this method. Of course I call it in a try block but no exception was thrown out.
    when I use TimeBase to synchronize them, i.e., videoPlayer.setTimeBase(audioPlayer.getTimeBase()), everything goes fine. But, I can not control both players from one ControlPanelComponent in this way.
    Anybody having any idea to solve this problem please reply.
    By the way, in the example code such as AVReceiver, where audo and video streams are shown on two window seperately, user can use the ControlPanelComponent of audio to control both player, though it seems no relevant code to support that function. The ControlPanelComponent of video can not control the audio player anyway. Anyone having any explanation to this?

  • Problem with merging incmoing audio and video source

    I am trying to record incoming audio and video data but i ran into a weird problem. The datasources merged fine but during playback of the recorded file the video sometimes turns white while audio still goes. For example, if the audio duration is 10 mins , the file length will be 10 mins but the video shows only like 2 mins and then the rest of file is white with sound in background. i am not sure why its happening... i also tried merging the files after recording audio and video individually but still no\ luck. does anyone know why this is happening? thanks

    I am working on Audio/video conferancing . Before sending Audio/Video data from my side
    to other side I am setting SendStream's setSourceDescription with my own name for CNAME . On reciving side some time i am getting correct CNAME which i set to SourceDescription ,but some time it gives default CNAME which is username@computername in steed of giving CNAME set to my name .
    Can you help me to solve this problem
    Thanks & Regards
    Amol Chandurkar

  • Audio and Video out of sync during editing. PLEASE HELP

    I am using a MacBook Pro. Specs are:
    - OS X version 10.9.2
    - 2.5GHz Intel Core i5 Processor
    - 4GB 1600MHz DDR3 RAM
    When I import a video into AfterEffects CC, the audio and video are out of sync. The audio and video files are the right size, length etc. but are way out of sync. By the end of a 2 minute video, it can be out by up to 5-6 seconds. This applies to videos imported from any device. iPhone, USB and even videos I've recorded directly from my computer. Most files I try and import are MP4 files, but I've found the same issues with all other video files. I've even tried importing them separetely as an audio file and then as a video file. Nothing seems to work. I am also experienceing the same issue with Premiere CC.
    Please help. I am needing these programs to work for assessment items.
    - Andrew

    Without knowing the specs of your videos it is hard to say. I'm also running a Mac and am having no such issues.
    My first thought is that you have something from a 3rd party installed that is causing conflicts. If all else fails try transcoding your mp4 files to a frame based codec using the Adobe Media Encoder. Pick one of the Apple production codecs or Jpeg compressed QuickTime.
    Are you running a ram preview? Did you render your Premiere timeline? Are you new to AE?

  • While playing videos on itunes, audio and video will stop and start. It just started doing this recently and it does it with all my itunes videos..help!!

    While playing videos on itunes, the audio and video will stop and start several times during playback. This just started recently and it does it on all my videos. Help!!

    Try to download the application VLC.
    It is a media player that should be able to play any audio or video file you may have. If your videos play flawlessly using that application, then the issue is with iTunes and Quicktime, as they are both essentially similar software types when it comes to playing media.
    In that case you may need to install a plug-in file called Perian, in order for the videos to play correctly within iTunes or at least Quicktime...

  • Operating Windows 7 Home Premium, 2 user accounts. Running Firefox one user can stream audio and video, the other cannot. Can anyone help?

    Two accounts set up. One can stream audio and video using Firefox, the other account cannot. The account with cannot stream a/v is able to steam a/v using (gasp) MS Internet Explorer. Is there some setting I have screwed up?

    There are some compatibility issues between the latest Flash player and some Firefox add-ons or settings. Could you see whether anything in this article helps: [[Flash 11.3 doesn't load video in Firefox]].

  • FCP 7.0.2 - audio and video out of sync after QT export! HELP!

    I loaded a self-contained movie of my project and exported it through Compressor. However, half way through the video, the audio and video went out of sync.
    This has never happened before — only since I upgraded to 10.6.3 and FCP 7.0.2/Compressor 3.5.2
    HELP!

    (P.S. I did change the Settings of the FCP from 720p60 to 720p30 about half way through the project, but that shouldn't affect the export.)
    About the time you changed FCP Easy Setup from 720p60 to 720p30 DURING Export?
    As you stated on this post:
    http://discussions.apple.com/thread.jspa?threadID=2384569&tstart=0
    I wouldn't think that's the best time to make a major change.

  • Please help with audio and video not syncing.

    I'm using Encore 3, and have already authored a DVD a month ago without a glitch. The following are the same steps I used, but this time around, the video and audio in Encore are not syncing.
    Here's what I've done.
    1) I export my Final Cut projects to .mov using the following settings (Share > Master File).
    Format: Video and Audio
    Video codec: H.264
    Resolution: 1920x1080
    Audio file format: Quicktime Movie (AAC)
    Include chapter markers: Unchecked
    Roles as: Quicktime Movie
    2) I run the .mov file in Compressor using the "Disc Burning" preset.
    3) I then import the .ac3 and .m2v files that Compressor created into Encore.
    4) In Encore, I select both files and go to New > Timeline.
    In the Timeline window, the durations on both are the same. But I don't understand why the audio and video are not synced when I preview or when I burn a test DVD. The audio comes in just a tad late.
    Video Clip:
    Source In: 00;00;00;00
    Duration: 00;02;33;29
    In-Point: 00;00;00;00
    Out-Point: 00;02;33;29
    Audio Clip:
    Source In: 00;00;00;00
    Duration: 00;02;34;00
    In-Point: 00;00;00;00
    Out-Point: 00;02;34;00
    What's puzzling is that two of the 10 videos I've import to Encore are synced perfectly -- same export settings from FCP, same settings Compressor.
    Please help.
    Thanks!
    Mark

    Hi Mark.
    Do you have any situations where there is more than one video file in a timeline?
    Secondly - why are you using H264 HD files for a DVD? This is using lossy compression to make the H264, which is in turn then scaled & even further bitrate reduced for M2V.
    I would give it a try rendering an SD video file for use in Encore - not the H264 - and starting out with Dolby Digital or LPCM audio, not AAC.
    As with all DVD authoring programs, Encore works best with DVD compliant assets - which you are most definitely using - but I still think you are over-complicating things by using H264/AAC at all.
    Eliminating this may help.

  • After Effects CS6 renders audio and video separately. Please help!

    Trying to render a finished video so that I can upload it to Youtube, but having extreme rendering difficulties. The only way my audio and video are combined in one file is when I export the project as a lossless AVI. Best quality for sure, but the size is MUCH too massive. Any other format I try always separates the audio and video. I have no idea why. Any help or suggestions are greatly appreciated. Thanks!

    Sure thing, here you go. If there is anything anyone else needs to see please let me know.

  • MERGING AND SYNCING more then one audio and video clip?

    Is there are way to select a bin of video clips and a bin of audio clips (DSLR with separate audio) and have Premiere analyze and sync them in batches like Avid. I have a mountain of audio and video clips, but with no rhyme or reason to the file name, no timecode, no slates, just waveforms. But without knowing which audio files go with which video files, it’s impossible (or least time-consuming).
    Or do I have to use plural eyes or other synchronising program for doing that?
    THanks.

    Do the video clips have audio. That is, are you seeking to match A/V clips with audio-only clips? If so, then Premiere can do that. Select all the clips in both bins, right-click & select Create Multicam Source Sequence, and select Sync by Audio.
    Whenever Premiere finds that two or more clips match each other but no others in the batch, it creates a multicam source sequence of just those clips.

  • How to combine discrete audio and video files?

    I am working on a project which requires me to merge a video file with a PCM audio file from another source.
    I just bought Compressor 4.1.1, expecting to be able to do exactly this.
    The only "multiple input - single output" option I can see is creating a surround sound group, adding my audio as left and right channels, and then attaching the video.
    This does not work. Pressing "add" at the end of the process does not result in a new job.
    Help please!
    G.

    QT7 Pro is able to do this. Cost is $30.
    In QT7 Pro, open up the audio and video files to be matched.
    Select all the audio and then select copy
    In the video window, put the playback head where you want the audio to start then select add to movie.
    Verify the playback is as desired, then save the movie. Done.
    Takes longer to describe the process than to do it.
    x
    Of course, life is good when the in point is exactly the same for both audio and video ...

Maybe you are looking for

  • My only local print shop can't open a .pages document

    Help! I have to have the brochure I've worked on for a week printed this afternoon, and the printer is pc only, can't open my file. When I save it as a word document, it is not possible to read the document, and much of the content is missing...it ge

  • Query regarding inner join

    Hi Can anyone explain me the error in this select query and give me the correct answer. select 1begda 1endda 2kostl 2persg 2anvsh 3pernr into corresponding fields of table i_emp from ( ( pa0000 as 1 innerjoin pa0001 as 2 on 1pernr = 2pernr ) join pa0

  • Editing mp3s and WAVs

    Maybe the wrong forum but I thought you guys might know. I'm looking for a simple program that will let me do some simple editing on music mp3s and perhaps on WAV files as well. Mostly, I want to be able to cut and add material in a song (silence, co

  • How to get Itunes media on iPhone back to PC or ITunes?

    Hi all, I have an IPHONE 4S, and (I wont bore you with the details) I have all of my purchased music on it (downloaded from ITUNES) and all of my CD installed music on my laptop. This was due to a catastrophic loss of media folder, and me attempting

  • Generation Error in MSA 4.0 SP12

    Hello all, Could you please help me on this? I needed to add a button in the Marketing Attributes list tile. So I have created another tile of extended list type (Z_classlist2), using the context menu of the attributes list tile (classslist2) for Mar