0

I am trying to make an AirPlay server in java with this library. I am able to start the server and connect to it and I am getting video input, however the input is in h264 format and I tried decoding it with JCodec but it always says I need an sps/pps and I don't know how to create/find this with just a byte[]. This is the onVideo method which is pretty much just copy-pasted from some websites:

@Override
public void onVideo(byte[] video) {
    try {
        videoFileChannel.write(ByteBuffer.wrap(video));
        
        ByteBuffer bb = ByteBuffer.wrap(video);
        H264Decoder decoder = new H264Decoder();
        decoder.addSps(List.of(ByteBuffer.wrap(video)));
        Picture out = Picture.create(1920, 1088, ColorSpace.YUV420);
        var real = decoder.decodeFrame(bb, out.getData());
        // decoder.decodeFrame prints "[WARN]   . (:0): Skipping frame as no SPS/PPS have been seen so far..." in console and returns null => NullPointer in next line
 
        var img = AWTUtil.toBufferedImage(real.createCompatible());
        
        // ...
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Edit: I've uploaded a ("working") version to github, but the decoded image is discolored and doesn't update all pixels so when something is on the screen and the frame changes, that something can still be on the image.

LetsDuck
  • 41
  • 4
  • Exciting that you are trying a pure Java implementation. Please provide a complete and self contained example that any developer can compile and debug. You will have a much better chance getting an answer. – Markus Schumann Aug 01 '22 at 21:05
  • I've now pushed it to github and it does kinda work now, but the images are pixelated and colored weirdly. I don't really know why it's happening but I think it might be because of a wrong sps, which I just copied from [here](https://openairplay.github.io/airplay-spec/screen_mirroring/stream_packets.html?search=dfdssdfdadsffsdfdf). [github link](https://github.com/LetsDuck2210/AirplayServer) – LetsDuck Aug 03 '22 at 18:46

0 Answers0