0

I created an FFMPEG pipeline so that I can stream video frames to an RTSP server. I created a synthetic video for testing where each frame is a green number on a black background. The video plays on my screen but it does not stream to the server because I get the error "Unable to find a suitable output format for 'rtsp://10.0.0.6:8554/mystream" My code is below. The source code is taken from the answer: How to stream frames from OpenCV C++ code to Video4Linux or ffmpeg?

int main() {
    int width = 720;
    int height = 1280;
    int fps = 30;

    FILE* pipeout = _popen("ffmpeg -f rawvideo -r 30 -video_size 720x1280 -pixel_format bgr24 -i pipe: -vcodec libx264 -crf 24 -pix_fmt yuv420p rtsp://10.0.0.6:8554/mystream", "w");



    for (int i = 0; i < 100; i++)
    {
        Mat frame = Mat(height, width, CV_8UC3);
        frame = Scalar(60, 60, 60); //Fill background with dark gray 
        putText(frame, to_string(i + 1), Point(width / 2 - 50 * (int)(to_string(i + 1).length()), height / 2 + 50), FONT_HERSHEY_DUPLEX, 5, Scalar(30, 255, 30), 10);  // Draw a green number

        imshow("frame", frame);
waitKey(1); 

        fwrite(frame.data, 1, width * height * 3, pipeout);
    }
    // Flush and close input and output pipes
    fflush(pipeout);

    _pclose(pipeout);   //Windows
    return 0;
}

When I change -f rawvideo to -f rtsp in the FFMPEG command, I no longer get the error but the program just displays the first frame on the screen and seems to get stuck. Is there a wrong parameter in the pipeline. When I change the RTSP url to a file name such as output.mkv, it works perfectly and saves the video to the file.

  • Try adding `-f rtsp`: `_popen("ffmpeg -f rawvideo -r 30 -video_size 720x1280 -pixel_format bgr24 -i pipe: -vcodec libx264 -crf 24 -pix_fmt yuv420p -f rtsp rtsp://10.0.0.6:8554/mystream", "w");` – Rotem Dec 07 '22 at 21:03
  • Thank you very much for the response. Adding -f rtsp definitely solved the problem. I am now getting a picture when I open up the RTSP url on a media player like VLC. The one issue that I'm still facing is that when I read in my own video from a file and stream the output using ffmpeg, the stream is just a series of green lines without any clear picture. Could it be that the RTSP server is expecting a specific type of codec? Are there any parameters that I could alter in the pipeline to make the picture clear and not just green lines? – user20623229 Dec 08 '22 at 09:11
  • I don't have enough information for answering that. I recommend you to test it from command line first (from console, not from C). – Rotem Dec 08 '22 at 09:40

0 Answers0