[FFmpeg-user] Capturing raw video and honoring timestamps

Joseph Rosensweig jrosensw at gmail.com
Sat Dec 8 21:25:50 CET 2012


On Sat, Dec 8, 2012 at 10:05 AM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:

> Joseph Rosensweig <jrosensw <at> gmail.com> writes:
>
> > I've been playing around with streaming a bit. I'm
> > essentially taking a stream of raw YUV data and feeding
> > it into ffmpeg to create h264 recordings of the data
> > packed in an mp4.  This has worked really well for me,
> > but I was wondering if there was any way to provide
> > timestamps to ffmpeg so that when it received the video
> > data it would honor the timestamps when creating the
> > recording.
>
> > Is there a way to encode the timestamp into the raw stream
> > frames such that ffmpeg will recognize and honor it?
>
> Command line and complete, uncut console output missing.
> (Normally, I write this although I already could guess -
> not always correct of course - what the issue is, in your
> case I have absolutely no idea because "timestamps in raw
> YUV data" is just not precise enough to understand, at
> least for me.)
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>

Ok I can be more precise.  Right now I am piping raw yuv frames to a pipe
like this:

$ ffmpeg -f rawvideo -pix_fmt yuv420p -s 1280x720 -y -an -r 30 -i pipe:0
-vcodec libx264 -vpre libx264-lossless_fast-r 30 -g 30
/tmp/AV_REC_TEST_Cb3f5d6cc1.mp4
FFmpeg version git-2d162e3, Copyright (c) 2000-2011 the FFmpeg developers


  built on Apr  4 2012 11:34:44 with gcc 4.4.3


  configuration: --enable-gpl --enable-libx264
--extra-ldflags=-L/source/VideoGatewayAlpha/externals/SDK/lib
--extra-cflags=-I/source/VideoGatewayAlpha/externals/SDK/include
--enable-shared --enable-pic
  libavutil    50. 36. 0 / 50. 36. 0


  libavcore     0. 16. 1 /  0. 16. 1


  libavcodec   52.108. 0 / 52.108. 0


  libavformat  52. 94. 0 / 52. 94. 0


  libavdevice  52.  2. 3 / 52.  2. 3


  libavfilter   1. 74. 0 /  1. 74. 0


  libswscale    0. 12. 0 /  0. 12. 0


[rawvideo @ 0xc1c510] Estimating duration from bitrate, this may be
inaccurate

Input #0, rawvideo, from 'pipe:0':


  Duration: N/A, start: 0.000000, bitrate: N/A


    Stream #0.0: Video: rawvideo, yuv420p, 1280x720, 33 tbr, 33 tbn, 33 tbc


[buffer @ 0xc26200] w:1280 h:720 pixfmt:yuv420p


[libx264 @ 0xc25ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3
FastShuffle SSE4.2

[libx264 @ 0xc25ac0] profile High, level 3.2


[libx264 @ 0xc25ac0] 264 - core 102 r1665 293b47b - H.264/MPEG-4 AVC codec
- Copyleft 2003-2010 - http://www.videolan.org/x264.html - options: cabac=1
ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00
mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1
interlaced=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=2 b_bias=0
direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25
scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200
ratetol=1.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00



Output #0, mp4, to '/tmp/VIDEO_REC_TEST_Ce24f656d1.mp4':


  Metadata:


    encoder         : Lavf52.94.0


    Stream #0.0: Video: libx264, yuv420p, 1280x720, q=10-51, 200 kb/s, 33
tbn, 33 tbc

Stream mapping:


  Stream #0.0 -> #0.0


frame=   19 fps=  0 q=-1.0 size=       0kB time=10000000000.00 bitrate=
0.0kbits/s    ^Mframe=   37 fps= 35 q=-1.0 size=       0kB
time=10000000000.00 bitrate=   0.0kbits/s    ^Mframe=   53 fps= 34 q=47.0
size=       7kB time=0.33 bitrate= 165.5kbits/s    ^Mframe=   71 fps= 34
q=41.0 size=      16kB time=0.88 bitrate= 153.4kbits/s    ^Mframe=   88
fps= 34 q=39.0 size=      26kB time=1.39 bitrate= 151.3kbits/s    ^Mframe=
 105 fps= 33 q=37.0 size=      32kB time=1.91 bitrate= 136.9kbits/s
 ^Mframe=  123 fps= 34 q=39.0 size=      55kB time=2.45 bitrate=
184.3kbits/s    ^Mframe=  141 fps= 33 q=41.0 size=      76kB time=3.00
bitrate= 206.6kbits/s    ^Mframe=  159 fps= 34 q=42.0 size=      93kB
time=3.55 bitrate= 215.9kbits/s    ^Mframe=  177 fps= 34 q=41.0 size=
103kB time=4.09 bitrate= 205.6kbits/s    ^Mframe=  194 fps= 34 q=40.0 size=
    110kB time=4.61 bitrate= 195.8kbits/s    ^Mframe=  211 fps= 34 q=39.0
size=     117kB time=5.12 bitrate= 187.4kbits/s    ^Mframe=  225 fps= 32
q=-1.0 Lsize=     132kB time=6.79 bitrate= 159.2kbits/s    ^M



video:129kB audio:0kB global headers:0kB muxing overhead 2.481489%


frame I:1     Avg QP:24.00  size:   263


[libx264 @ 0xc25ac0] frame P:179   Avg QP:36.03  size:   668


[libx264 @ 0xc25ac0] frame B:45    Avg QP:39.53  size:   249


[libx264 @ 0xc25ac0] consecutive B-frames: 67.0% 12.5% 18.8%  1.8%


[libx264 @ 0xc25ac0] mb I  I16..4:  0.0% 100.0%  0.0%


[libx264 @ 0xc25ac0] mb P  I16..4:  1.5%  1.1%  0.1%  P16..4:  3.5%  0.6%
 0.3%  0.0%  0.0%    skip:92.9%

[libx264 @ 0xc25ac0] mb B  I16..4:  0.4%  0.8%  0.0%  B16..8:  1.1%  0.1%
 0.0%  direct: 0.2%  skip:97.3%  L0:56.4% L1:41.3% BI: 2.3%

[libx264 @ 0xc25ac0] final ratefactor: 32.76


[libx264 @ 0xc25ac0] 8x8 transform intra:52.5% inter:58.5%


[libx264 @ 0xc25ac0] direct mvs  spatial:95.6% temporal:4.4%

    The above works fine.  But it assumes that the frames coming in are
33ms apart.  So if I have a set of frames with timestamps like this:

Frame 1 -- 0ms
Frame 2 -- 33 ms
Frame 3 -- 99 ms
Frame 4 -- 132 ms
Frame 5 -- 330 ms

   It will just put these 33ms apart.  I was just wondering if there was a
way of passing this time data in with each frame I pass to ffmpeg so that
it honors the incoming.  For example it could duplicate frame 4 a few times
until the time reaches 330ms for frame 5.

   Does this make things clearer?  I was planning on making my application
do this task, but I figured I would check if ffmpeg had any capabilities
built in to it.

Thanks,

JD


More information about the ffmpeg-user mailing list