I have wrote C++ application which saves RTSP stream to separate files using gst_parse_launch() and pipeline like following for command line:
gst-launch-1.0 -e rtspsrc location=rtsp://path/to/src ! rtpjitterbuffer ! rtpmp4vdepay ! mpeg4videoparse ! splitmuxsink location=video%d.avi max-size-time=10000000000 max-size-bytes=1000000 When connection fails I get error via: gst_bus_pop_filtered(bus, GST_MESSAGE_ERROR); then send EOS to pipeline via: gst_element_send_event(pipeline, gst_event_new_eos()); set pipeline to NULL state: gst_element_set_state(pipeline, GST_STATE_NULL); and go to the next iteration where I try to connect with: gst_element_set_state(pipeline, GST_STATE_GST_STATE_PLAYING); In each iteration I destroy old pipeline and create new one. Most times everything work perfect, but occasionally I get broken files (ffmpeg detects it with message: "[mov,mp4,m4a,3gp,3g2,mj2 @ 00967fe0] moov atom not found") which can't be played. My question is: what I need to do in my code to guarantee that file closed correctly after connection was broken? In another words: how to do what is option "-e" does for gst-launch util? |
On Mon, 2016-10-31 at 01:30 -0700, alexolut wrote:
Hi, > gst-launch-1.0 -e rtspsrc location=rtsp://path/to/src ! > rtpjitterbuffer ! > rtpmp4vdepay ! mpeg4videoparse ! splitmuxsink location=video%d.avi > max-size-time=10000000000 max-size-bytes=1000000 Just on a side note, you are not creating AVI files here (since you don't use avimux as muxer, the default muxer of splitmuxsink is mp4mux). > When connection fails I get error via: (..) > Most times everything work perfect, but occasionally I get broken > files (ffmpeg detects it with message: "[mov,mp4,m4a,3gp,3g2,mj2 @ > 00967fe0] moov atom not found") which can't be played. > > My question is: what I need to do in my code to guarantee that file > closed correctly after connection was broken? In another words: how > to do what is option "-e" does for gst-launch util? The easiest option might be to use a container format where the content survives even if it's not finalised properly, for example Matroska or MPEG-TS. For MP4, you use mp4mux's "reserved-*" properties to make sure the file always stays valid, and set it as muxer on splitmuxsink. This means some data might be lost at the end though, depending on the update period. Cheers -Tim -- Tim Müller, Centricular Ltd - http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Thanks for your reply.
What I need to do for this? Try to change "muxer" property of "splitmuxsink" element or anything else? After reading documentation for mp4mux I didn't clearly understand which values I need to set to prevent broken files at all (losing of some data at the end is not important, if video file can be played in VLC or WMP). Is enough to set reserved-moov-update-period to some 'N' (is value in nanosec?) to prevent creation of fully unplayable files if source is live more than early specified period 'N'? |
In reply to this post by Tim Müller
I tried to use "muxer=matroskamux" for "splitmuxsink" but in result I also got damaged .mkv file after interrupt my application on some condition and switching pipeline to NULL state via: gst_element_set_state(pipeline, GST_STATE_NULL); before return from main(). Maybe I did it not right? Do you know how to close RTSP-connection correctly (on some user-defined condition) and avoid damaged files in result? |
Hello, alexolut
Your mkv container is not finished. It is the reason it is damaged.
-You need to send EOS event before stoping pipeline gst_element_send_event(_pipeline, gst_event_new_eos());
-After this, wait for GST_MESSAGE_EOS on a bus
-Only then you can close pipeline
Mikl From: gstreamer-devel <[hidden email]> on behalf of alexolut <[hidden email]>
Sent: Tuesday, November 1, 2016 9:32:50 AM To: [hidden email] Subject: Re: Saving stream to file on unstable communication line Tim Müller wrote
> The easiest option might be to use a container format where the content > survives even if it's not finalised properly, for example Matroska or > MPEG-TS. I tried to use "muxer=matroskamux" for "splitmuxsink" but in result I also got damaged .mkv file after interrupt my application on some condition and switching pipeline to NULL state via: gst_element_set_state(pipeline, GST_STATE_NULL); before return from main(). Maybe I did it not right? Do you know how to close RTSP-connection correctly (on some user-defined condition) and avoid damaged files in result? -- View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Saving-stream-to-file-on-unstable-communication-line-tp4680334p4680361.html Sent from the GStreamer-devel mailing list archive at Nabble.com. _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hello, Mikl.
Even if I send EOS to the pipeline it couldn't be received because pipeline is not in a PLAYING state (connection is broken now). I will wait for EOS forever, that is not acceptably. So I need a strategy to prevent locking of application (on wait for EOS) and creation of unfinished files at the same time. |
Hi,
try to set streamable = true on matroskamux, this way the produced files have no indexes (standard seek will not work) but are always playable, Nicola Il 04/11/2016 14:07, alexolut ha scritto: > Hello, Mikl. > > > Mikl wrote >> Your mkv container is not finished. It is the reason it is damaged. >> >> -You need to send EOS event before stoping pipeline >> >> gst_element_send_event(_pipeline, gst_event_new_eos()); >> >> -After this, wait for GST_MESSAGE_EOS on a bus >> >> -Only then you can close pipeline > Even if I send EOS to the pipeline it couldn't be received because pipeline > is not in a PLAYING state (connection is broken now). I will wait for EOS > forever, that is not acceptably. > > So I need a strategy to prevent locking of application (on wait for EOS) and > creation of unfinished files at the same time. > > > > -- > View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Saving-stream-to-file-on-unstable-communication-line-tp4680334p4680450.html > Sent from the GStreamer-devel mailing list archive at Nabble.com. > _______________________________________________ > gstreamer-devel mailing list > [hidden email] > https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Le 4 nov. 2016 9:42 AM, "Mailing List SVR" <[hidden email]> a écrit : And additionally, send Eos from a separate thread, and use g_timeout to cancel it (state null) if it took longer then expected. > Nicola _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |