سؤال

I'm using the a bunch of png files to create a video.My problem is that while the png files are of an OK quality the video frames won't render in a good enough quality.Do you know how i can fix such a thing? Here is the code i've written concerning the matter:

    private void createVideo() throws IOException{


    IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
    Dimension screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

    writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,screenBounds.width/2, screenBounds.height/2);

    long startTime = System.nanoTime();

    File directory = new File(sourceFolder);
    ArrayList<File> filenames = new ArrayList<File> ();

    File[] list= directory.listFiles();
    for(int i=0;i<list.length;i++){
        filenames.add(list[i]);
    }

    for (int index = 0; index < filenames.size(); index++) {
        if(filenames.get(index).toString().contains("png")){

            BufferedImage screen = ImageIO.read(filenames.get(index));

            // convert to the right image type
            BufferedImage bgrScreen = convertToType(screen,BufferedImage.TYPE_3BYTE_BGR);


            int i=0;
            while(i<FRAME_RATE){
                writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, 
                   TimeUnit.NANOSECONDS);
                ++i;
            }

            // sleep for frame rate milliseconds
            try {
                Thread.sleep((long) (1000 / FRAME_RATE));
            } 
            catch (InterruptedException e) {
            }
        }

    }

    writer.close();     

}

Solution: the problem was this line

writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4,screenBounds.width/2, screenBounds.height/2);

I shouldn't have divided the width and height with 2 after i removed it the quality was just as the png it self.

هل كانت مفيدة؟

المحلول

I do not know what you mean by in a good quality but assuming that you mean it looks blurred out, it could be that

PNG image is smaller in size compared to the size in which you want it encoded.

This will mean less pixels to encode into the video stream. This will result in pixels being spread out and hence looking of poor quality.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top