On Sun, 2010-09-19 at 01:47 +0400, Kulti wrote: > On Sat, Sep 18, 2010 at 6:10 PM, Tomas Härdin <[email protected]>wrote: > > > On Fri, 2010-09-17 at 14:13 +0400, Kulti wrote: > > > On Fri, Sep 17, 2010 at 10:36 AM, Tomas Härdin <[email protected] > > >wrote: > > > > > > > On Thu, 2010-09-16 at 20:11 +0400, Kulti wrote: > > > > > On Thu, Sep 16, 2010 at 5:34 PM, Tomas Härdin < > > [email protected] > > > > >wrote: > > > > > > > > > > > Please don't top post on this list. It makes it harder for people > > to > > > > > > read it. > > > > > > > > > > > > On Thu, 2010-09-16 at 17:02 +0400, Kulti wrote: > > > > > > > Hm... Thanks, I'm use flv-container, but how to set VFR? It's > > mean, > > > > that > > > > > > I > > > > > > > need to modify AVCodecContext.time_base before encoding every > > frames? > > > > > > > > > > > > > > On Thu, Sep 16, 2010 at 4:43 PM, Tomas Härdin < > > > > [email protected] > > > > > > >wrote: > > > > > > > > > > > > > > > On Thu, 2010-09-16 at 13:36 +0400, Kulti wrote: > > > > > > > > > Hi, all. > > > > > > > > > > > > > > > > > > I have a webcam and need to transcode mjpeg to any formats, > > but > > > > > > sometime > > > > > > > > > webcam lagged and fps fall down. Can ffmpeg atuo fill dropped > > > > frames > > > > > > to > > > > > > > > > constantly fps? > > > > > > > > > > > > > > > > Why do you want constant fps? Just use a container that handles > > VFR > > > > > > > > (avi, flv, mov etc.). > > > > > > > > > > > > > > > > Anyway, assuming the frames are timestamped correctly ffmpeg > > should > > > > > > > > behave correctly. If not, try forcing constant framerate with > > -r. > > > > > > > > > > > > > > > > /Tomas > > > > > > > > > > > > > > > > > > > > FLV has a fixed time base of 1 kHz, so it's always VFR. In other > > cases, > > > > > > like AVI, you can set time_base to be less than or equal to the > > inverse > > > > > > of the maximum fps. > > > > > > > > > > > > In other words, if you know your camera can't deliver more than 50 > > fps > > > > > > you can set time_base to 1/50, 1/123, 1/10000 or whatever. In the > > > > > > specific case of AVI you shouldn't set it too low though, since it > > pads > > > > > > with empty packets for the "missing" time stamps (IIRC something > > like > > > > > > 39*16 = 624 B overhead if you mux 25 fps with a time base of 1 > > kHz). > > > > FLV > > > > > > does not have this problem though. > > > > > > > > > > > > Hope that helps :) > > > > > > > > > > > > /Tomas > > > > > > > > > > > > _______________________________________________ > > > > > > libav-user mailing list > > > > > > [email protected] > > > > > > https://lists.mplayerhq.hu/mailman/listinfo/libav-user > > > > > > > > > > > > > > > > > Sorry for top-post... and thanks for your help. > > > > > > > > > > So, I set time_base to fixed value 1/25 (that I get from > > AVCodecContext > > > > for > > > > > mjpeg-decoder). Then I added timer and frame-counter before > > > > > av_write_frame(). I see, that fps is 19-21. But I need > > live-streaming. > > > > So, I > > > > > hardcoded time_base to 1/20, and all works fine before webcam is not > > lag, > > > > > but after fall down fps to 15 transcoding process broken. > > > > > > > > > > Yes, I understand, that must be working for transcoding into file, > > but I > > > > > need real-time transoding for live streaming. I can't see any way > > instead > > > > > inserting frames, when some drops... > > > > > > > > What you do is convert the current time to the stream's time base, and > > > > stick that value in as the packet's DTS. Sort of like this: > > > > > > > > //remember what the time was when the program started > > > > int64_t t0 = get_microseconds_time(); //replace with whatever function > > > > is suitable > > > > > > > > ... > > > > //for each AVPacket > > > > int64_t t = get_microseconds_time(); > > > > pkt->dts = av_rescale_q(t - t0, AV_TIME_BASE_Q, st->time_base); > > > > av_write_frame(...); > > > > > > > > That seconds line converts your zero-centered times from microseconds > > to > > > > the stream's time base. This means if the camera suddenly slows down a > > > > bit, the DTS value will have gaps. This is fine as long as the muxer > > can > > > > handle VFR (such as AVI and FLV). > > > > > > > > /Tomas > > > > > > > > _______________________________________________ > > > > libav-user mailing list > > > > [email protected] > > > > https://lists.mplayerhq.hu/mailman/listinfo/libav-user > > > > > > > > > > > Thanks! > > > > > > I'm not familiar with pts, dts etc. May be you can advise me any docs? > > > > > > In my application I already have rescale for pts: > > > avPacket->pts = av_rescale_q(codedFrame->pts, pCodecCtx->time_base, > > > pVideoStream->time_base); > > > > > > and I've added rescale for dts too: > > > avPacket->dts = av_rescale_q(getTimeMicroSeconds() - > > > startEncodingTimeMicroSeconds, AV_TIME_BASE_Q, pVideoStream->time_base); > > > > > > but after any seconds I've received error message: > > > st:0 error, pts < dts > > > > > > So, I added following code: > > > if( avPacket->pts < avPacket->dts ) > > > avPacket->pts = avPacket->dts; > > > > > > Is it right way? Now it works about 50 minutes and other error displayed: > > > st:0 error, non monotone timestamps 2885736 >= -1385734 > > > > > > As I understand from ffmpeg sources, it's meaning, that stream's dts >= > > > packet's dts, but I have not any idea to fix them. > > > > What I do is that I only set pts. libavformat will generate the dts > > values by sorting the pts:es and some other magic. So try setting only > > pts, and set it to the rescaled real time (microseconds etc.). > > > > /Tomas > > > > > Well, now it's looks like work. Just replase setting avPacket->pts by > rescale realtime difference instead codedFrame->pts. Thanks. > > PS. And I still cannot understand this magic with pts and dts. Why It's > works, when I rescale pts(base on codedFrame->pts) and dts(base on realtime > diff)? And why it's work with rescale only pts(base on realtime diff)? It's > a rhetorical question...
Since dts always has to be less than or equal to pts lavf will sort and adjust the pts values so this relation holds. For instance: pts: 0, 3, 1, 2, 4 gets transformed to something like dts: -1, 0, 1, 2, 3 For VFR video I believe it's a bit more complicated. The following are values that I get from an FLV sample I have: pts: 0, 666, 333, 1000, 1033 I'm not sure what lavf does, but sorting and subtracting 333 works: dts: -333, 0, 333, 667, 700 I suggest you look at compute_pkt_fields() and compute_pkt_fields2() in libavformat/utils.c. /Tomas
signature.asc
Description: This is a digitally signed message part
_______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
