Javacv: error while decoding bytestream

Created on 6 Jun 2019  路  19Comments  路  Source: bytedeco/javacv

I geht errors like this while access to stream:

...
[h264 @ 0000000033a298c0] left block unavailable for requested intra4x4 mode -1
[h264 @ 0000000033a298c0] error while decoding MB 0 13, bytestream 234391
[h264 @ 0000000033a2e0c0] left block unavailable for requested intra4x4 mode -1
[h264 @ 0000000033a2e0c0] error while decoding MB 0 32, bytestream 12860
[h264 @ 0000000033a29480] left block unavailable for requested intra4x4 mode -1
[h264 @ 0000000033a29480] error while decoding MB 0 13, bytestream 352876
[h264 @ 0000000033a2e0c0] cabac decode of qscale diff failed at 67 54
[h264 @ 0000000033a2e0c0] error while decoding MB 67 54, bytestream 36823
[h264 @ 0000000033a29480] error while decoding MB 53 32, bytestream -5
[h264 @ 0000000029b3d740] error while decoding MB 57 35, bytestream -5
[h264 @ 0000000033a2e540] error while decoding MB 42 37, bytestream -15
[h264 @ 0000000033c400c0] error while decoding MB 59 34, bytestream -5
...

The image looks not clear. I work with JavaFx8 an Javacv 1.5.0.
Capturing with FrameRate: 25.0, Width: 1920, Height: 1080, Codec; H.264
When I move the ptz-head, the image get worse.

When I open the stream in VLC player or web interface, the image looks perfect.

Result:
nok1

Desired image:
ok1

BTW: Those this library use GPU for rendering?

question

Most helpful comment

Yesss, that's the trick. Thank you

All 19 comments

If you only need to display why not just use JavaFX?

Because its not only to display. I also have to record the stream in specific recording last 10 seconds from a trigger.

I see, so you're probably just not encoding fast enough and losing packets. You'll need to find a way to encode faster on your machine.

When I bypass the stream to FFmpegFrameRecorder directly without showing to display, I also have this effect. Remember, in VLC-Player or by Webview I dont have this problem.

How do you know this is happening if you're not displaying or recording anything?

You still get the error messages you mean? Well, you're obviously losing packets, so this is either something related to your network, or you're not decoding fast enough. Make sure this isn't happening.

You still get the error messages you mean? No, when I am just recording without to display, there is noe error message (because I don't use converter). But I see in created file the garbage.
so this is either something related to your network No, a am sure that network is ok, because its an test installation only for this. 100MB, short wire etc. VLC and Webview works without that effect.
you're not decoding fast enough I work on a multimedia pc, its not on Limit. I don't decoding self, it's javacv. See my simple code:

captureService = new Thread(() -> {
          grabber.start();
          live = true;

          // While we are capturing...
          Frame capturedFrame = null;
          while (live && (capturedFrame = grabber.grabImage()) != null) {

              Image image = jconverter.convert(capturedFrame);
              Platform.runLater(() -> {
                  imageView.setImage(image);
              });
          }
          stopRecord();
          grabber.stop();
 }

Please try without the call to Platform.runLater(() -> { imageView.setImage(image); }). If you do not get any errors that way, then it is unrelated to JavaCV!

Yes, I also get those errors. It must be in the calling (from JavaFXFrameConverter)
Image image = jconverter.convert(capturedFrame);
Without this I don't get errors.

Edit:
Nob, this error occurs also without jconverter.convert(capturedFrame);...

@johanvos Would you know anything about what could cause this sort of delay in JavaFXFrameConverter? Is it thread safe?

I have updated my message several hours before because I tried without to call converter but I saw that log until after thread stop.

What does your code looks like now?

There is my code:

public final void init() {
grabber = new FFmpegFrameGrabber(RTSP_URL);
grabber.setOption(
TimeoutOption.STIMEOUT.getKey(),
String.valueOf(TIMEOUT * 1000000) // In microseconds, from examples of deadlock. TIMEOUT = 10
);
av_log_set_level(AV_LOG_ERROR); // hides "deprecated pixel format used" - Warnings from some cameras
}

public final void startCamera() {

   captureService = new Thread(() -> {
       try {
           grabber.start();

           live = true;

           JavaFXFrameConverter jconverter = new JavaFXFrameConverter();

           if (grabber == null) {
               return;
           }
           // While we are capturing...
           setState(PlayerState.PLAY);
           while (live && (capturedFrame = grabber.grabImage()) != null) {
               // normaly show frames
           }

           stopRecord();
           grabber.stop();
           setState(PlayerState.STOP);
       } catch (FrameGrabber.Exception | Exception ex) {
           stopRecord();
           setState(PlayerState.CONERROR);
           ex.printStackTrace();
       }
   });

   captureService.start();

}

For information: I have tested it with use opencv 4.0.1 (its also included in your jar as far I see). There is a clean image and no errors.

It's possible some other threads in your application are using all processing power. Please try it outside your application.

Yes I have already tried it with same result.
I attached a zip file with demo:
JavaFxSimplePlayVideo.zip

Thanks, but I won't be able to test that here...

Setting the "rtsp_transport" option to "tcp" helps with that apparently:
https://stackoverflow.com/questions/50063707/ffmpeg-rtsp-error-while-decoding-mb

Yesss, that's the trick. Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bahramudin picture Bahramudin  路  3Comments

eldhosengeorge picture eldhosengeorge  路  3Comments

y4nnick picture y4nnick  路  3Comments

Maleandr picture Maleandr  路  3Comments

UpAndDownAgain picture UpAndDownAgain  路  3Comments