public boolean generateVideoBySequenceImages4Jcoder
		(String videoFilename, List<String> filelist,  int FPS) throws Exception {
		boolean result = false;
		SeekableByteChannel out = null;
		
		try {
			out = NIOUtils.writableFileChannel(videoFilename);
		      // for Android use: AndroidSequenceEncoder
            AWTSequenceEncoder encoder = new AWTSequenceEncoder(out, Rational.R(FPS, 1));
            for (String fnpath : filelist) {
            	LOGGER.info(fnpath);
            	
            	File img = new File(fnpath);
            	BufferedImage image = ImageIO.read(img);
            	encoder.encodeImage(image);
            }
            // Finalize the encoding, i.e. clear the buffers, write the header, etc.
            encoder.finish();
            result = true;
			
		} catch (Exception e) {
//			LOGGER.info("generateVideoBySequenceImages Exception: " + e);
			e.printStackTrace();
			
		} finally {
            NIOUtils.closeQuietly(out);
        }
		return result;
	}
    
    ----
    
    ...사용시
    
         String filefullNm = tempPath + fileName + format1.format(time)+ "_jcodec.avi";
        	if ( generateVideoBySequenceImages4Jcoder(filefullNm, filelist, Integer.valueOf(videofps)) ){
        		LOGGER.info("동영상저장 끝:" + filefullNm);
        		result = "true";
        		mv.addObject("filePath", filefullNm);
        	}

참조 : https://stackoverflow.com/questions/55232723/generate-mp4-video-file-by-sequence-png-images-in-java-8

 

Generate MP4 video file by sequence PNG images in Java 8

After testing several tools for Windows 10 found on the network, I had great difficulty in finding one that could carry around 5,000 PNG images in sequence and convert it into a video that was

stackoverflow.com

jcodec 사용하여 순서 이미지들로 동영상 파일 제작 

(sequence images to video)

 

그런데 문제가 발생한다.

계속 발생하는게 아니라 특정 조건에 아래와 같이 발생한다.

Component 1 width should be a multiple of 2 for colorspace: YUV420J

 

찾아 보면 이미지의 넓이와 크기가 짝수여야 한다는 것이다.

 

그래서 원천 이미지를 만들어 내는 곳에 소스를 변경해야 만 처리가 편한다.

사용은 아래와 같이

	
...
  BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(imageBytes));

  int width          = bufImg.getWidth() ;
  int height         = bufImg.getHeight();
  if ( (width %2) != 0 ) width++;
  if ( (height %2) != 0 ) height++;
  BufferedImage resizedImage = resizeImg(bufImg, width, height);

  ImageIO.write(resizedImage, "png", new File(filefullNm)); 
...
   
   
   	// 크기 재생산
    public BufferedImage resizeImg(BufferedImage inputImage, int width, int height)
            throws IOException {
    	//https://icarus8050.tistory.com/32

        BufferedImage outputImage =
                new BufferedImage(width, height, inputImage.getType());

        Graphics2D graphics2D = outputImage.createGraphics();
        graphics2D.drawImage(inputImage, 0, 0, width, height, null);
        graphics2D.dispose();

        return outputImage;
    }

이와 같이 하면 문제가 없어 질 것이다. 두둥탁~

참 

pom

 

<!--        jcodec   #######################################################################################-->
<dependency>
    <groupId>org.jcodec</groupId>
    <artifactId>jcodec</artifactId>
    <version>0.2.5</version>
</dependency>

<dependency>
    <groupId>org.jcodec</groupId>
    <artifactId>jcodec-javase</artifactId>
    <version>0.2.5</version>
</dependency>

 

메이븐도 필수~

 

 

 

 

1. 개요 

 - 수작업 많음

 - 조립쉬움

 - 카페 활용 (프린터보드 등)

 - 출력시 내용확인

 

2. 환경

 - 노즐 관리

 - 프린팅 마다 초기 필라멘트 제거 - 출력물 베이스 없을때

 - 배드 온도 수작업 설정

 - 심플리파이 3D, 슬라이싱

 

   start G-code

----

G28 ; home all axes

배드온도 올리는 스크립트 생각중.

 

   end G-code

----

G91

G1 Z+0.5 E-1 F9000

G90

G1 X-10 Y200 F3600

M104 S0 ; turn off extruder

M140 S0 ; turn off bed

M107 ; fan stop

M84 ; disable motors

 

-> 출력이 끝나면 배드를 앞으로 전진 시키고 시작점으로 노즐을 이동

 

노즐온도

플라멘트에 따라 변경 195~210 

배드온도

50~60

 

지속적 업데이트 예정

+ Recent posts