Data loss during conversion of video from images in Java
<p>My video bailey.mpg from which i created .png images using xuggler method, then i  read each image in byte array and append hash as delimiter and text data in this byte array and recreate image using this byte array.</p>

<p>Now i am reconstructing video in .avi format from this (text appended images)set of images. By getting the sets of .png images from new avi video using xuggler .I am  reading each image in byte array, and i am searching  delimiter in byte array of image's set, but I am unable to find hash delimiter.I think this means text data loss during creation of video.
what should i do?</p>

<p>Code for create images from video 
package DifferentPackage;</p>

<pre><code>import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
import com.xuggle.xuggler.Global;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pratibha
 */
public class VideoIntoFrames {
    public static final double SECONDS_BETWEEN_FRAMES =1;
    String inputFilename;
    private static final String outputFilePrefix = "C:\\photo\\image_";
    // The video stream index, used to ensure we display frames from one and
    //only one video stream from the media container.
    private static int mVideoStreamIndex = -1;
    // Time of last frame write
    private static long mLastPtsWrite = Global.NO_PTS;
    public static final long MICRO_SECONDS_BETWEEN_FRAMES =(long)(100 * SECONDS_BETWEEN_FRAMES);
    int FrameNo=0;
    public VideoIntoFrames(String filepath){
        inputFilename=filepath;
        IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
        // stipulate that we want BufferedImages created in BGR 24bit color space

        mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
        mediaReader.addListener(new ImageSnapListener());
        // read out the contents of the media file and
        // dispatch events to the attached listener

        while (mediaReader.readPacket() == null) ;
    }
       private  class ImageSnapListener extends MediaListenerAdapter {



        public void onVideoPicture(IVideoPictureEvent event) {



            if (event.getStreamIndex() != mVideoStreamIndex) {

                // if the selected video stream id is not yet set, go ahead an

                // select this lucky video stream

                if (mVideoStreamIndex == -1)

                    mVideoStreamIndex = event.getStreamIndex();

                // no need to show frames from this video stream

               else

                    return;

            }



            // if uninitialized, back date mLastPtsWrite to get the very first frame

           if (mLastPtsWrite == Global.NO_PTS)

                mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;



            // if it's time to write the next frame

            if (event.getTimeStamp() - mLastPtsWrite &gt;=

                    MICRO_SECONDS_BETWEEN_FRAMES) {


                ++FrameNo;

                String outputFilename = dumpImageToFile(event.getImage());


                // indicate file written

                double seconds = ((double) event.getTimeStamp()) /

                    Global.DEFAULT_PTS_PER_SECOND;

                System.out.printf(

                        "at elapsed time of %6.3f seconds wrote: %s\n",

                        seconds, outputFilename);



                // update last write time

                mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;

            }



        }



        private String dumpImageToFile(BufferedImage image) {

           try {

                String outputFilename = outputFilePrefix +FrameNo+ ".gif";

                ImageIO.write(image, "jpg", new File(outputFilename));

                return outputFilename;

            }

            catch (Exception e) {

                e.printStackTrace();

                return null;

            }

        }



    }

    public static void main(String args[]){
        String path="D:/bailey.mpg";
       VideoIntoFrames v=new VideoIntoFrames(path);
    }
}
</code></pre>

<p>All images are save at c:/photo .Code for Insert Text Data in image_1.gif is</p>

<pre><code> try{
            String data="My Name is ";
            int[] charValue=new int[data.length()];
            for(int rowIndex=0;rowIndex&lt;charValue.length;rowIndex++){
                charValue[rowIndex]=data.charAt(rowIndex);
            }
            File videoFile = new File("C:/photo/image_1.gif");
            FileInputStream videoInput = new FileInputStream(videoFile);
            int VideoByte = -1;
            List&lt;Byte&gt; bytes = new ArrayList&lt;Byte&gt;();
            while ((VideoByte = videoInput.read()) != -1) {
                bytes.add((byte) VideoByte);
            }

            byte[] ByteOfVideo = new byte[bytes.size()];
            for (int count = 0; count &lt; ByteOfVideo.length; count++) {
                ByteOfVideo[count] = bytes.get(count);
                //    System.out.println(count+" of ByteOfImage "+ByteOfVideo[count]);
            }


            ////////////////////////////////////#////////////////////////

            /////now insert actual image fRames,Row and Columns

            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

            for (int i = 0; i &lt; ByteOfVideo.length; i++) {

                byteOut.write(ByteOfVideo[i]);
            }
            byte[] HashArray = "#".getBytes();
            byteOut.write(HashArray);
            byteOut.write(HashArray);
            byteOut.write(HashArray);
            byteOut.write(HashArray);
            byteOut.write(HashArray);


           /// String retrievedString = new String(FrameByteArray, "UTF-8");
          for (int i = 0; i &lt; charValue.length; i++) {
               System.out.println(" NameArray in Bytes" + charValue[i]);
                byteOut.write(charValue[i]);
            }
            ////insert #



          //////write this Video File 

           String FinalModifiedVideo="C:\\photo\\image_1.gif";
           File ModifiedFile=new File(FinalModifiedVideo);
           DataOutputStream out=new DataOutputStream(new FileOutputStream(ModifiedFile));
           byteOut.writeTo(out);
           out.close();

           System.out.println("Process End");

        }
        catch(Exception e){
            e.printStackTrace();
        }
</code></pre>

<p>Code for create video from image set(images in c:/photo) folder.this create image.avi video</p>

<pre><code>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Frame;

import test.*;
import ch.randelshofer.media.avi.AVIOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Inbo
 */
public class MyVideoWriter {

    static ArrayList&lt;String&gt; img = new ArrayList();

    public static void readFiles() {

        String path = "C:\\photo\\";

        String files;
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();

        int c = 0;
        for (int i = 0; i &lt;799; i++) {
            img.add(path + "\\image_" + (i + 1) + ".gif");
        }
        // System.out.println(img);
    }

    public MyVideoWriter(String path) {
        readFiles();
        try {
            AVIOutputStream AVIout = new AVIOutputStream(new File(path + ".avi"), AVIOutputStream.VideoFormat.JPG);
            AVIout.setVideoCompressionQuality(1);
            //AVIout.setFrameRate(10);
            AVIout.setVideoDimension(352, 240);

            for (int i = 0; i &lt; img.size(); i++) {
                AVIout.writeFrame(new File(img.get(i)));
            }

            AVIout.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static void main(String args[]) {
        String path="C:\\image";
        MyVideoWriter mv = new MyVideoWriter(path);

    }
}
</code></pre>
