2012-10-04 3 views
4

출력 된 스트림에 인코딩 된 버퍼링 된 이미지를 쓰려고하는데 스트림에 오는 모든 데이터를 가져올 수 없습니다 ... 누군가가 내가 뭘 잘못하고 왜 내가 할 수 없는지 말할 수 있습니까? 출력을 볼 수 있습니까?xuggler를 사용하여 outputStream에 쓰는 방법은 무엇입니까?

필자는 write.encodeVideo 메서드를 호출하여 비디오를 ByteArrayOutputStream으로 인코딩한다고 가정 할 것입니다.

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 

// video parameters 
final int videoStreamIndex = 0; 
final int videoStreamId = 0; 
final long frameRate = DEFAULT_TIME_UNIT.convert(15, MILLISECONDS); 
final int width = 512; 
final int height = 254; 
long nextFrameTime = 0; 

// create a media writer and specify the output file 
final IMediaWriter writer = ToolFactory.makeWriter("aaa.ogg"); 

IContainer ic = writer.getContainer(); 
ic.open(outputStream, writer.getContainer().getContainerFormat(), true, false); 

ICodec codec = ICodec.guessEncodingCodec(null, null,"aaa.ogg", null, ICodec.Type.CODEC_TYPE_VIDEO); 

// add the video stream 
writer.addVideoStream(videoStreamIndex, videoStreamId, codec, width, height); 

BufferedImage img = null; 
try 
{ 
    img = ImageIO.read(new File("/home/jbkreme/aaa.png")); 
} 
catch (final IOException e) 
{ 
    e.printStackTrace(); 
} 

for(int yy =0; yy < 2048-height; yy=yy+8) 
{ 
    nextFrameTime++; 
    BufferedImage frame = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); 
    frame = img.getSubimage(0, yy, width, height); 
    BufferedImage frame2 = convertToType(frame, BufferedImage.TYPE_3BYTE_BGR); 

    //encode the video 
    writer.encodeVideo(videoStreamIndex, frame2, nextFrameTime, DEFAULT_TIME_UNIT); 

    nextFrameTime += frameRate; 
} 

writer.close(); 
outputStream.flush(); 
outputStream.close(); 
+0

대답을 알아 냈습니까? –

+0

내가 그랬다고 생각하지 않습니까? 죄송합니다 – Grammin

+0

@PhaniRahul 당신은 여전히 ​​OutputStream 인코딩하려는 경우 대답을 제출했습니다. – 11101101b

답변

1

나는 IMediaWriter을 만드는 방법이 잘못되었다고 생각합니다. 작가의 용기를 직접 열지 않으려는 것입니다. 당신이 파일 대신 OutputStream을 사용하는 경우이 같은 com.xuggle.xuggler.io.XugglerIO 매퍼 사용하여 작업을 수행 할 수 있습니다

// create a media writer and specify the output stream 
final IMediaWriter writer = ToolFactory.makeWriter(XugglerIO.map(outputStream)); 

// manually set the container format (because it can't detect it by filename anymore) 
IContainerFormat containerFormat = IContainerFormat.make(); 
containerFormat.setOutputFormat("ogg", null, "application/ogg"); 
mWriter.getContainer().setFormat(containerFormat); 

// add the video stream 
writer.addVideoStream(videoStreamIndex, videoStreamId, ICodec.ID.CODEC_ID_THEORA, width, height); 

염두에 두어야을 당신은 "추구"할 수있는 형식을 만들려고하는 경우 생성 과정 (예 : .mov)의 일부로 출력 바이트 내에서, 내가 나타낸 것처럼 간단히 OutputStream과 작동하지 않습니다. OutputStream 대신 파일에 써야합니다.

관련 문제