Title: GStreamer: cannot put pipeline to play
Tags: opencv;video;gstreamer
Question: this is a command what I run in the terminal,```rosrun ros_exploration ros_exploration```after that, I got an unexpected error as below.it should be mentioning that the note,```GStreamer: cannot put pipeline to play```probably is the key point of this problem. unfortunately, I don't know how do I fix it.

```0:00:04.442429649  3130      0x2071c90 ERROR                    omx gstomx.c:3249:plugin_init: Failed to load configuration file: Valid key file could not be found in search dirs (searched in: /home/htf/.config:/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg:/usr/local/etc/xdg as per GST_OMX_CONFIG_DIR environment variable, the xdg user config directory (or XDG_CONFIG_HOME) and the system config directory (or XDG_CONFIG_DIRS)
0:00:04.990602557  3078 0x7fd5a8002e70 ERROR           GST_PIPELINE grammar.y:816:priv_gst_parse_yyparse: no element "Video"

(ros_exploration:3078): GStreamer-CRITICAL **: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
0:00:04.990762618  3078 0x7fd5a8002e70 ERROR           GST_PIPELINE grammar.y:971:priv_gst_parse_yyparse: no source element for URI "/18_09_11-11:44:53-PCL.avi"
GStreamer Plugin: Embedded video playback halted; module filesink0 reported: Could not open file "Video/18_09_11-11:44:53-PCL.avi" for writing.
GStreamer Plugin: Embedded video playback halted; module filesink0 reported: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
OpenCV Error: Unspecified error (GStreamer: cannot put pipeline to play
) in CvVideoWriter_GStreamer181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16open, file /home/htf/Downloads/opencv-667.385.0637/modules/highgui/src/cap_gstreamer.cpp, line 1528
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16notify() and catch all exceptions there.

terminate called after throwing an instance of 'cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16xception'
  what():  /home/htf/Downloads/opencv-667.385.0637/modules/highgui/src/cap_gstreamer.cpp:1528: error: (-2) GStreamer: cannot put pipeline to play
 in function CvVideoWriter_GStreamer181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16open

Aborted (core dumped)
```

If you have ever used GStreamer or met the relevant problems and solutions, little clues would be appreciated.



here is a part of relevant codes,

PCL_VideoWriter.open(FileName.toAscii().data(),CV_FOURCC('M','P','2','V'),FPS,cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16Size(640,480));
        //        MainTimer->start(viewer_thr->loop_time);

```    if(SLAM_IMG_Capture_flag == 1)
    {
        FileName.clear();
        FileName =  "Video/"+CurrDateText+"-"+CurrTimeText+"-SLAM"+".avi";
```



I tried to recompile OpenCV-2.4.13. here are my commands,```cmake cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-2.4.13  -D WITH_FFMPEG=ON ..```&amp; ```make```&amp; 

````sudo make install`
```

. Then I got this, 

```     Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.1)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 58.18.100)
--       avformat:                  YES (ver 58.12.100)
--       avutil:                    YES (ver 56.14.100)
--       swscale:                   YES (ver 5.1.100)
--       avresample:                YES (ver 1.0.1)
--     GStreamer:                   
--       base:                      YES (ver 667.385.0637)
--       video:                     YES (ver 667.385.0637)
--       app:                       YES (ver 667.385.0637)
--       riff:                      YES (ver 667.385.0637)
--       pbutils:                   YES (ver 667.385.0637)
```

however, the error is that  ```error: ‘CV_CAP_FFMPEG’ was not declared in this scope``` or  ```error: ‘CAP_FFMPEG’ is not a member of ‘cv’``` still exists.


Here is the accepted answer: From what i see you are trying to open a video file not a gstreamer pipe. For this case using FFMPEG interface of opencv might be more useful. ```VideoWriter``` class has an overload function for it:

```bool cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16VideoWriter181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16open  (   const String &amp;      filename,
    int     apiPreference,
    int     fourcc,
    double      fps,
    Size    frameSize,
    bool    isColor = true 
)   
```

You may use it like:

```PCL_VideoWriter.open(FileName.toAscii().data(),CAP_FFMPEG,CV_FOURCC('M','P','2','V'),FPS,cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16Size(640,480));
    //        MainTimer-&gt;start(viewer_thr-&gt;loop_time);
```

Also, is the video in correct path i.e "Video/18_09_11-11:44:53-PCL.avi"? 

Comment for this answer: Sorry, I confused VideoCapture and VideoWriter. Now I updated the answer. Could you try the overloaded `open` function with `CAP_FFMPEG` parameter instead of the original.
Comment for this answer: `CAP_FFMPEG` _is_ the parameter. you can use it directly, or with namespace `cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16P_FFMPEG`. Hopefully, you have FFMPEG installed in your system and OpenCV is compiled with FFMPEG flags turned on.
Comment for this answer: I guess it's the same in 2.4. One possibility is that you are missing FFMPEG in your OpenCv build. You might need to re-build OpenCv with FFMPEG flags enabled.
Comment for this answer: @HanJingyu could you try again after enabling avresample? You need to install `libavresample-dev` package (`sudo apt-get install libavresample-dev`)
Comment for this answer: I said that because FFMPEG requires all sub-requirements to work properly. Is your initial code (without CAP_FFMPEG ) also not working?
Comment for this answer: @HanJingyu sorry, I forgot this thread. From what I read recompiling OpenCv doesn't affect your results, hopefully you recompiled your application after recompiling OpenCv. I don't think other commands are necessary, we want to disable gstreamer and use FFMPEG instead.
Comment for this answer: I also posted the relevant codes. I have never used the GStreamer, so the question is what should I type in the terminal after installed successfully if launching GStreamer.@Alper Kucukkomurler
Comment for this answer: to be honest, codes related to video capturing was written by one of a classmate, So I  also not sure whether the generated video on the correct path.  I was guessing the video should be saved in home/Videos(ubuntu).@Alper Kucukkomurler
Comment for this answer: if possible, could you tell me what the CAP_FFMPEG parameter should be? sorry, I got confused with all of this project.@Alper Kucukkomurler
Comment for this answer: However, I am using OpenCV-2.4.13. so cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16P_FFMPEG is not a member of "cv" namespace.@ Alper Kucukkomurler
Comment for this answer: because I am using OpenCV-2.4.13, I tried to rewrite a suitable format of cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16P_FFMPEG. but ‘CV_CAP_FFMPEG’ was not declared in this scope. so if possible, could you tell me what is the proper format of cv181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16 FFMPEG under 2.4.13? Besides, I also tried to use OpenCV-3.4.0. unfortunately, most part of this project is based on OpenCV-2.4.13. so it's very difficult for me to update a new version.
Comment for this answer: I have already followed your clues and updated the descriptions of my problem as you can see above.@Alper Kucukkomurler. thank you for your patience.
Comment for this answer: I did followed what you said, but it doesn't make sense.@ Alper Kucukkomurler
Comment for this answer: NO, without these words,  the code could be compiled smoothly. However, when typing some commands to launch the file, I will get an unexpected error as above.@Alper Kucukkomurler
Comment for this answer: here is the corresponding project posted on GitHub 
 https://github.com/TengFeiHan0/AFOA-SLAM/blob/master/ros_exploration/src/captureviewer.cpp
Comment for this answer: have you found a solution to this problem? if you have more ideas, please feel free to contact me. thanks a lot.@Alper Kucukkomurler
Comment for this answer: before typing rosrun ros_exploration ros_exploration, do I need to enter some other commands related to GStreamer?just as this document said,https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html 
 @Alper Kucukkomurler


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:09/11/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<opencv><video><gstreamer>', 'Title': 'GStreamer: cannot put pipeline to play', 'ViewCount': 951, 'id': 52268179, 'user_AboutMe': None, 'user_AccountId': 13592076.0, 'user_DisplayName': 'TENG FEI HAN', 'user_Reputation': 92.0, 'user_Views': 30.0, 'user_id': 9805133.0}}