ardera / flutter_packages

My collected packages for pub.dev
MIT License
28 stars 7 forks source link

RTSP error #31

Open AndroidDesigner opened 2 weeks ago

AndroidDesigner commented 2 weeks ago

Hello @ardera I want to stream an IP camera using rtsp in a Raspberrypi 4 (bullseye). So, I used your sample code and wrote the below code in my flutter-pi project:

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutterpi_gstreamer_video_player/flutterpi_gstreamer_video_player.dart';
import 'package:video_player/video_player.dart';

class CameraPage extends StatefulWidget {
  const CameraPage({super.key});

  @override
  State<CameraPage> createState() => _CameraPageState();
}

class _CameraPageState extends State<CameraPage> {

  late VideoPlayerController _controller;
  late ChewieController _chewieController;

  @override
  void initState() {
    super.initState();
    _controller = FlutterpiVideoPlayerController.withGstreamerPipeline(
      'rtspsrc location="rtsp://192.168.31.170:554" ! queue max-size-buffers=2 ! rtph264depay ! h264parse ! decodebin ! autovideosink sync=false appsink name="sink"'
    );
    _chewieController = ChewieController(
      videoPlayerController: _controller,
      autoInitialize: true,
      autoPlay: true,
      looping: true,
      isLive: true,
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
    _chewieController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Chewie(controller: _chewieController);
  }

}

but it results in a blank screen (live video does not show) and shows the the below error:

plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.

Also, if I press refresh button of Chewie widget, it shows me the below error:

plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: gstreamer error: code: 9, domain: gst-resource-error-quark, msg: Unhandled error (debug info: ../gst/rtsp/gstrtspsrc.c(6696): gst_rtspsrc_send (): /GstPipeline:pipeline4/GstRTSPSrc:rtspsrc4:
Session Not Found (454))
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: gstreamer error: code: 9, domain: gst-resource-error-quark, msg: Unhandled error (debug info: ../gst/rtsp/gstrtspsrc.c(6696): gst_rtspsrc_send (): /GstPipeline:pipeline5/GstRTSPSrc:rtspsrc5:
Session Not Found (454))
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: gstreamer error: code: 9, domain: gst-resource-error-quark, msg: Unhandled error (debug info: ../gst/rtsp/gstrtspsrc.c(6696): gst_rtspsrc_send (): /GstPipeline:pipeline6/GstRTSPSrc:rtspsrc6:
Session Not Found (454))
plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.
plugins/gstreamer_video_player/player.c: gstreamer error: code: 9, domain: gst-resource-error-quark, msg: Unhandled error (debug info: ../gst/rtsp/gstrtspsrc.c(6696): gst_rtspsrc_send (): /GstPipeline:pipeline7/GstRTSPSrc:rtspsrc7:
Session Not Found (454))

what is problem?

ardera commented 2 weeks ago
    _controller = FlutterpiVideoPlayerController.withGstreamerPipeline(
      'rtspsrc location="rtsp://192.168.31.170:554" ! queue max-size-buffers=2 ! rtph264depay ! h264parse ! decodebin ! autovideosink sync=false appsink name="sink"'
    );

First, you need to remove the autovideosink. You don't want gstreamer to automatically select where to display the video, it will try to display it in a Desktop Window or something. You want flutter-pi to handle the video output. Try this pipeline:

rtspsrc location="rtsp://192.168.31.170:554" ! queue max-size-buffers=2 ! rtph264depay ! h264parse ! decodebin !  appsink name="sink"

You can also try removing the rtph264depay and h264parse, IIRC decodebin will automatically decode those.

This here:

plugins/gstreamer_video_player/player.c: Couldn't find "src" element to configure additional HTTP headers.

is not an error message, it's just a warning. But I should probably make that more silent, seems to be confusing.

This here is the real error:

plugins/gstreamer_video_player/player.c: gstreamer error: code: 9, domain: gst-resource-error-quark, msg: Unhandled error (debug info: ../gst/rtsp/gstrtspsrc.c(6696): gst_rtspsrc_send (): /GstPipeline:pipeline7/GstRTSPSrc:rtspsrc7:
Session Not Found (454))

I have no idea about RTSP, so I don't really know what's going on here. Some gstreamer forum / IRC is probably the better place to ask. But with googling it seems like this can be caused by client/server state inconsistency, for example it could be server closed the connection or crashed, and client didn't notice.