<div dir="ltr"><div><div><div><div><div><div><div>Hi all!<br><br></div>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.<br><br></div>
I have a video mp4 file with me, probing it gives me the following:<br><br>----------------------<br>ffprobe version N-47062-g26c531c Copyright (c) 2007-2012 the FFmpeg developers<br> built on Nov 25 2012 12:23:20 with gcc 4.7.2 (GCC)<br>
configuration: --disable-static --enable-shared --enable-gpl --enable-version3<br> --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib<br>--enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-<br>
amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut -<br>-enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger -<br>-enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --<br>
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab<br>le-libxavs --enable-libxvid --enable-zlib<br> libavutil 52. 9.100 / 52. 9.100<br> libavcodec 54. 77.100 / 54. 77.100<br> libavformat 54. 37.100 / 54. 37.100<br>
libavdevice 54. 3.100 / 54. 3.100<br> libavfilter 3. 23.102 / 3. 23.102<br> libswscale 2. 1.102 / 2. 1.102<br> libswresample 0. 17.101 / 0. 17.101<br> libpostproc 52. 2.100 / 52. 2.100<br>Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_0.mp4':<br>
Metadata:<br> major_brand : isom<br> minor_version : 512<br> compatible_brands: isomiso2avc1mp41<br> creation_time : 1970-01-01 00:00:00<br> encoder : Lavf53.27.0<br> Duration: 00:00:21.19, start: 0.000000, bitrate: 812 kb/s<br>
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480 [<br>SAR 1:1 DAR 4:3], 700 kb/s, 30.06 fps, 29.92 tbr, 748 tbn, 59.84 tbc<br> Metadata:<br> creation_time : 1970-01-01 00:00:00<br> handler_name : VideoHandler<br>
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 103<br> kb/s<br> Metadata:<br> creation_time : 1970-01-01 00:00:00<br> handler_name : SoundHandler<br>----------------------<br>
<br></div>Above video was probably encoded at 30.06 fps. I want to achieve something similar, but my 'open codec' related code is something like:<br><br>---------------------------<br>/* Add a video output stream. */<br>
static AVStream *add_video_stream(AVFormatContext *oc, AVCodec **codec,<br> enum AVCodecID codec_id)<br>{<br> AVCodecContext *c;<br> AVStream *st;<br><br> /* find the video encoder */<br>
*codec = avcodec_find_encoder(codec_id);<br> if (!(*codec)) {<br> fprintf(stderr, "codec not found\n");<br> exit(1);<br> }<br><br> st = avformat_new_stream(oc, *codec);<br> if (!st) {<br>
fprintf(stderr, "Could not alloc stream\n");<br> exit(1);<br> }<br><br> c = st->codec;<br><br> avcodec_get_context_defaults3(c, *codec);<br><br> c->codec_id = codec_id;<br><br> /* Put sample parameters. */<br>
c->bit_rate = 400000;<br> /* Resolution must be a multiple of two. */<br> c->width = 352;<br> c->height = 288;<br> /* timebase: This is the fundamental unit of time (in seconds) in terms<br> * of which frame timestamps are represented. For fixed-fps content,<br>
* timebase should be 1/framerate and timestamp increments should be<br> * identical to 1. */<br> c->time_base.den = 30;<br> c->time_base.num = 1;<br> c->gop_size = 12; /* emit one intra frame every twelve frames at most */<br>
c->pix_fmt = STREAM_PIX_FMT;<br> if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {<br> /* just for testing, we also add B frames */<br> c->max_b_frames = 2;<br> }<br> if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {<br>
/* Needed to avoid using macroblocks in which some coeffs overflow.<br> * This does not happen with normal video, it just happens here as<br> * the motion of the chroma plane does not match the luma plane. */<br>
c->mb_decision = 2;<br> }<br> /* Some formats want stream headers to be separate. */<br> if (oc->oformat->flags & AVFMT_GLOBALHEADER)<br> c->flags |= CODEC_FLAG_GLOBAL_HEADER;<br><br>
return st;<br>}<br>---------------------------<br></div><div>(above, from muxing example)<br></div><div><br></div>Here, noteworthy is:<br> c->time_base.den = 30;<br> c->time_base.num = 1;<br><br></div>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.<br>
<br></div>So the question is, how can I achieve same fractional fps while encoding a video?<br><br></div>Can anyone kindly provide guidance for above?<br><br>Thanks for your time...<br></div>