Change Framerate of recorded stream

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Change Framerate of recorded stream

Wes Miller
Administrator
Hi All,

I have an mjpeg stream saved into a matroska container file that I want to play (to a videosink or a filesink) with a reduced framerate.  The original stream is 25 fps.  I want to change it to, say, 5 fps.  Essentially,

     filesrc ! matroskademux ! image/jpeg,framerate=(fraction)5/1 ! jpegdec ! ...

This pipeline doesn't  start, reports general stream error...not linked.

What is the correct form to do this?  I can do it with a have-data callback that discards 80% of the frames, but there has to be a smarter way.


Is it also possible to fix the timestamps so that I can get either original speed video (at 5 fps) or fast playback, i.e. after converting to 5 fps, set the timestamps to play at 25 fps?

Many thanks,


Wes


Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Sandeep Prakash
Wes Miller wrote
I have an mjpeg stream saved into a matroska container file that I want to play (to a videosink or a filesink) with a reduced framerate.  The original stream is 25 fps.  I want to change it to, say, 5 fps.  Essentially,

     filesrc ! matroskademux ! image/jpeg,framerate=(fraction)5/1 ! jpegdec ! ...

This pipeline doesn't  start, reports general stream error...not linked.

What is the correct form to do this?  I can do it with a have-data callback that discards 80% of the frames, but there has to be a smarter way.
You can use "videorate" plugin to change the framerate. Directly changing the caps
on the stream will not work.

Wes Miller wrote
Is it also possible to fix the timestamps so that I can get either original speed video (at 5 fps) or fast playback, i.e. after converting to 5 fps, set the timestamps to play at 25 fps?
Not sure how to achieve this because you (or videorate) would have discarded the frames already .
I guess we have to change the buffer duration for this.

Regards,
Sandeep Prakash
http://sandeepprakash.homeip.net
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
Well,  guess you're going to have to tell me what parameter to use.  Almost all of them I see when I do a gst-inspect are readonly and the few that are writeabe don't sound like they have anything to do with adjusting the framerate.

     name    
     silent              
     new-pref        
     skip-to-first

Wes
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Kocsis Tibor
Use capsfilter after videorate to chose the framerate you want.

... ! videorate ! capsfilter caps="video/x-raw-yuv,framerate=1/1 ! ...



On Wed, Aug 25, 2010 at 12:34 PM, Wes Miller <[hidden email]> wrote:

>
> Well,  guess you're going to have to tell me what parameter to use.  Almost
> all of them I see when I do a gst-inspect are readonly and the few that are
> writeabe don't sound like they have anything to do with adjusting the
> framerate.
>
>     name
>     silent
>     new-pref
>     skip-to-first
>
> Wes
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Change-Framerate-of-recorded-stream-tp2336869p2337980.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
In reply to this post by Sandeep Prakash
Sandeep,

Thanks very much for your help.  I need to learn more about capsfilter, I guess.

For whoever might read this later, the working pipeline I have is:

   - The original file caps are: image/jpeg,width=640,height=480,framerate=25/1

   - I guess this effectively shows every "25th" frame

      gst-launch-0.10 -e -v    filesrc location="2.mkv" ! matroskademux ! jpegdec  \
                                      !  videorate ! capsfilter caps="video/x-raw-yuv,framerate=1/1" \
                                      !  ffmpegcolorspace !  autovideosink

   - And this reduces the size and framerate:

      gst-launch-0.10 -e -v    filesrc location="2.mkv" ! matroskademux ! jpegdec \
                                      ! videorate  !  capsfilter caps="video/x-raw-yuv,framerate=1/1"  \
                                      !  videoscale ! capsfilter caps="video/x-raw-yuv,width=320,height=240"  \
                                      !  ffmpegcolorspace !  autovideosink

Neither, however, give me fast playback.

Wes
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
In reply to this post by Sandeep Prakash
Sandeep,

You wrote:

     You can use "videorate" plugin to change the framerate. Directly changing the caps
     on the stream will not work.

         Wes Miller wrote:
        Is it also possible to fix the timestamps so that I can get either original speed video (at 5 fps)
        or fast playback, i.e. after converting to 5 fps, set the timestamps to play at 25 fps?

     Not sure how to achieve this because you (or videorate) would have discarded the frames already .
     I guess we have to change the buffer duration for this.


Would it be correct to create a pipeline program where some pad calls a have-data callback that:
1)  Keeps only every 5th or 7th or whatever frame *returns true) and tosses the rest (returns false) and
2)  Modifies the frame metadata to fix the timestamps to appear "faster" and modifies the caps to say framerate=5/1 or whatever.  I think, in my case, the jpegs have zero duration, but that might also need to be altered for non-jpeg frames.

If this would work (I have gotten the keep/discard and timestamp fixes to work), How would one fix the caps?  I know I need them writable and they fail is_mutabl e assertions if I just try to modify them directly.

The help for modifying caps is a little unclear.  Does making a copy of the caps and derefing the old caps cause the new caps to be added/replaced into the buffer?  Do I need to copy the new caps at the location of the old ones?  Can I just set the old one mutable and "know" that I am modifying the original caps and not a copy?

Thanks and for your previous help, too, more thanks,,

Wes
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Sandeep Prakash
Hi Wes,


Try the trick mode. I guess the framework already supports what you are trying to achieve.
For more info check this:
http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-trickmodes.txt

Not sure all the demuxers support this feature and not sure it will work for mjpeg streams.

Regards,
Sandeep Prakash
http://sandeepprakash.homeip.net
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Robert Powell-2
In reply to this post by Wes Miller

Hi Wes,

On Wed, Aug 25, 2010 at 5:23 AM, Wes Miller <[hidden email]> wrote:
Neither, however, give me fast playback.

If you want fast playback, the easiest pipeline might be
gst-launch gnlfilesource duration=10000000000 media-duration=100000000000 location=2.mkv ! autovideosink

Adjust the durations to get the rate you want, of course.

Hope that helps,

Rob

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
Rob,

Well, it looks like a good start, but it doesn't quite work.  Any suggestions based on the following?

Wes


As written (with filename fixes):
     gst-launch-0.10      gnlfilesource duration=10000000000000   \
                                  media-duration=100000000000  \
                                  location="file:///c:/gstreamer/bin/2.mkv" \
                               ! autovideosink

I get:

     Setting pipeline to PAUSED ...
     Pipeline is PREROLLING ...
     ERROR: from element /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0: Could not perform
      seek on resource.
     Additional debug info:
     ..\..\..\Source\gnonlin\gnl\gnlsource.c(332): ghost_seek_pad (): /GstPipeline:pipeline0/Gn
     lFileSource:gnlfilesource0:
     Sending initial seek to upstream element failed
     ERROR: pipeline doesn't want to preroll.
     Setting pipeline to NULL ...
     Freeing pipeline ...


If I replace autovideosink with fakesink -v I get:

     Setting pipeline to PAUSED ...
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin:
      source = (GstFileSrc) source
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstTypeFindElement:typefind.GstPad:src: caps = video/x-matroska
     Pipeline is PREROLLING ...
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMatroskaDemux:matroskademux0.GstPad:sink: caps = video/x-matr
     oska
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0.GstPad:sink0: caps = image/jpeg, width
     =(int)640, height=(int)480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0: max-size-buffers = 5
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0: max-size-bytes = 2097152
     ERROR: from element /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0: Could not perform
      seek on resource.
     Additional debug info:
     ..\..\..\Source\gnonlin\gnl\gnlsource.c(332): ghost_seek_pad (): /GstPipeline:pipeline0/Gn
     lFileSource:gnlfilesource0:
     Sending initial seek to upstream element failed
     ERROR: pipeline doesn't want to preroll.
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0.GstPad:src0: caps = image/jpeg, width=
     (int)640, height=(int)480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstJpegDec:jpegdec0.GstPad:sink: caps = image/jpeg, width=(int)6
     40, height=(int)480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0.GstGhostPad:src0: caps = video/x-raw-y
     uv, format=(fourcc)I420, width=(int)704, height=(int)480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin.
     GstGhostPad:src0: caps = video/x-raw-yuv, format=(fourcc)I420, width=(int)704, height=(int
     )480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20.GstDecodePad:src0: caps = video/x-raw-yuv, format=(fourcc)I420,
     width=(int)704, height=(int)480, framerate=(fraction)25/1
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstJpegDec:jpegdec0.GstPad:src: caps = video/x-raw-yuv, format=(
     fourcc)I420, width=(int)704, height=(int)480, framerate=(fraction)25/1
     Setting pipeline to NULL ...
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0.GstGhostPad:src0: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin.
     GstGhostPad:src0: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20.GstDecodePad:src0: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstJpegDec:jpegdec0.GstPad:src: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstJpegDec:jpegdec0.GstPad:sink: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0.GstPad:sink0: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMultiQueue:multiqueue0.GstPad:src0: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMatroskaDemux:matroskademux0.GstPad:video_00: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstMatroskaDemux:matroskademux0.GstPad:sink: caps = NULL
     /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/
     GstDecodeBin2:decodebin20/GstTypeFindElement:typefind.GstPad:src: caps = NULL
     Freeing pipeline ...
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Robert Powell-2


On Wed, Aug 25, 2010 at 9:38 AM, Wes Miller <[hidden email]> wrote:

Rob,

Well, it looks like a good start, but it doesn't quite work.  Any
suggestions based on the following?


Nope, no idea.  This pipeline works fine for me with the following differences: I'm using an H264 video and sending it out to xvimagesink. Looks like gnlfilesource isn't able to seek on your video.

Sorry

Rob

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Sandeep Prakash
In reply to this post by Wes Miller
Hi Wes,

Wes Miller wrote
Well, it looks like a good start, but it doesn't quite work.  Any suggestions based on the following?
It works for me as well. I tried an mkv file with jpeg. Even the playback rate I am able to control.
I am running GNonLin Version: 0.10.15
What version have you installed? There were some fixes on gnlfilesource. But not sure on the specifics.

Regards,
Sandeep
http://sandeepprakash.homeip.net

Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
I must have something really wrong, guys.

I downloaded and installed all new gstreamer and plugins-good and gnonlin.  Still no joy.

I recorded an mjpeg stream to a matroska file using a simnple pipe:

gst-launch -e -v souphttpsrc location="http://10.253.5.90/axis-cgi/mjpg/video.cgi?camera=1" do-timestamp=true is_live=true \
! multipartdemux ! image/jpeg,width=640,height=480  ! queue2 \
! matroskamux ! filesink location="test.mkv"

Used ctrl-c to end recording.

Then I tried to play test.mkv through your pipeline and I still get no video.  I do get errors from matroskademux:  

ERROR: from element /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/GstDecodeBin2:decodebin20/GstMatroskaDemux:matroskademux0: GStreamer encountered a general stream error.
Additional debug info:
matroska-demux.c(5640): gst_matroska_demux_loop (): /GstPipeline:pipeline0/GnlFileSource:gnlfilesource0/GstURIDecodeBin:internal-uridecodebin/GstDecodeBin2:decodebin20/GstMatroskaDemux:matroskademux0:
stream stopped, reason not-negotiated
ERROR: pipeline doesn't want to preroll.

Looks like I am stuck finding another way to do this.  I can playback test.mkv and my other files using a straight pipeline    filesrc ! mat4roskademux ! jpegdec ! ffmpegcolorspace ! autovideosink
but gnl just hates me.  

So, If I want to edit my frames by hand, how do I edit the caps in the individual buffrs?  

Wes

Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Wes Miller
Administrator
Hey, I finally got this to work!

It did require one change to the original pipeline.  I added the ffmpegcolorspace element and voila it worked.

Actually, I did have one other change.  My original mkv file was corrupt.  I played it through a jpegdec ! jpecenc and re-stored it to a new mkv file and that file what worked for me.

     gst-launch-0.10      gnlfilesource duration=10000000000000  media-duration=10000000000000   \
                             location="file:///home/wmiller/2redo.mkv" ! ffmpegcolorspace ! autovideosink


I do still have one problem.  How do I change the playback rate?  I tried adding rate=0.02 and a rate=75, neither changed the playback rate.

(The original goal here is to take a mjpeg video of, say, 1000 frames, taken at framerate = 25/1 and throw away 4 out of every 5 frames then to fix the timestamp info in the saved frames so the video plays back at 5x speed, i.e. the duration is divided by 5.  Result is highspeed, small filesize, "thumbnail" video)

Thanks,

Wes


Reply | Threaded
Open this post in threaded view
|

Re: Change Framerate of recorded stream

Sandeep Prakash
Hi Wes,

Wes Miller wrote
I do still have one problem.  How do I change the playback rate?  I tried adding rate=0.02 and a rate=75, neither changed the playback rate.
The "rate" property of gnlfilesource is READONLY. I am assuming you are talking about the gnlfilesource element. You should be getting a "GLib-GObject-WARNING" for this.

To actually change the rate you have to fiddle with the "duration" and "media-duration" properties. So for a faster playback media-duration should be greater than the duration and vice-versa for slow playback.

Also you have to use identity element to adjust the timestamps. E.G.:
Below pipeline is for faster playback:
gst-launch gnlfilesource duration=10000000000000  media-duration=100000000000000 location=file:///home/user/test.mp4 ! identity single-segment=true ! ffmpegcolorspace ! queue ! autovideosink


Regards,
Sandeep Prakash
http://sandeepprakash.homeip.net