[Libav-user] Video encoding at fractional fps

cyril apan cyrilapan at yahoo.fr
Tue Jun 11 15:25:21 CEST 2013


Never tested it, but you should try with those values:
    c->time_base.den = 2997;
    c->time_base.num = 100;

Regards,

Cyril APAN.



________________________________
 De : Taha Ansari <mtaha.ansari at gmail.com>
À : "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <libav-user at ffmpeg.org> 
Envoyé le : Mardi 11 juin 2013 15h18
Objet : [Libav-user] Video encoding at fractional fps
 


Hi all!

I am trying to encode at fractional fps. Currently, I can encode video at 29 fps, or 30 fps, but cannot encode at fractional, like 29.97.


I have a video mp4 file with me, probing it gives me the following:

----------------------
ffprobe version N-47062-g26c531c Copyright (c) 2007-2012 the FFmpeg developers
  built on Nov 25 2012 12:23:20 with gcc 4.7.2 (GCC)
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3
 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib
--enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-
amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut -
-enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger -
-enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab
le-libxavs --enable-libxvid --enable-zlib
  libavutil      52.  9.100 / 52.  9.100
  libavcodec     54. 77.100 / 54. 77.100
  libavformat    54. 37.100 / 54. 37.100
  libavdevice    54.  3.100 / 54.  3.100
  libavfilter     3. 23.102 /  3. 23.102
  libswscale      2.  1.102 /  2.  1.102
  libswresample   0. 17.101 /  0. 17.101
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf53.27.0
  Duration: 00:00:21.19, start: 0.000000, bitrate: 812 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480 [
SAR 1:1 DAR 4:3], 700 kb/s, 30.06 fps, 29.92 tbr, 748 tbn, 59.84 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 103
 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
----------------------

Above video was probably encoded at 30.06 fps. I want to achieve something similar, but my 'open codec' related code is something like:

---------------------------
/* Add a video output stream. */
static AVStream *add_video_stream(AVFormatContext *oc, AVCodec **codec,
                                  enum AVCodecID codec_id)
{
    AVCodecContext *c;
    AVStream *st;

    /* find the video encoder */
    *codec = avcodec_find_encoder(codec_id);
    if (!(*codec)) {
        fprintf(stderr, "codec not found\n");
        exit(1);
    }

    st = avformat_new_stream(oc, *codec);
    if (!st) {
        fprintf(stderr, "Could not alloc stream\n");
        exit(1);
    }

    c = st->codec;

    avcodec_get_context_defaults3(c, *codec);

    c->codec_id = codec_id;

    /* Put sample parameters. */
    c->bit_rate = 400000;
    /* Resolution must be a multiple of two. */
    c->width    = 352;
    c->height   = 288;
    /* timebase: This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
     * timebase should be 1/framerate and timestamp increments should be
     * identical to 1. */
    c->time_base.den = 30;
    c->time_base.num = 1;
    c->gop_size      = 12; /* emit one intra frame every twelve frames at most */
    c->pix_fmt       = STREAM_PIX_FMT;
    if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
        /* just for testing, we also add B frames */
        c->max_b_frames = 2;
    }
    if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
        /* Needed to avoid using macroblocks in which some coeffs overflow.
         * This does not happen with normal video, it just happens here as
         * the motion of the chroma plane does not match the luma plane. */
        c->mb_decision = 2;
    }
    /* Some formats want stream headers to be separate. */
    if (oc->oformat->flags & AVFMT_GLOBALHEADER)
        c->flags |= CODEC_FLAG_GLOBAL_HEADER;

    return st;
}
---------------------------

(above, from muxing example)

Here, noteworthy is:
    c->time_base.den = 30;
    c->time_base.num = 1;

Which basically tells to encode at 30 fps. Both den, and num are integer values, so I cannot stuff something like 30.06 as den value.

So the question is, how can I achieve same fractional fps while encoding a video?

Can anyone kindly provide guidance for above?

Thanks for your time...

_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130611/1715b670/attachment.html>


More information about the Libav-user mailing list