*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define HAVE_AV_CONFIG_H
#include <limits.h>
static int video_codec_tag = 0;
static int same_quality = 0;
static int b_frames = 0;
-static int b_strategy = 0;
static int pre_me = 0;
static int do_deinterlace = 0;
static int workaround_bugs = FF_BUG_AUTODETECT;
extern int loop_input; /* currently a hack */
static int loop_output = AVFMT_NOOUTPUTLOOP;
static int genpts = 0;
+static int qp_hist = 0;
static int gop_size = 12;
static int intra_only = 0;
#ifdef CONFIG_BKTR
static char *video_grab_format = "bktr";
#else
+#ifdef CONFIG_VIDEO4LINUX2
+static char *video_grab_format = "video4linux2";
+#else
static char *video_grab_format = "video4linux";
#endif
+#endif
static char *video_device = NULL;
static char *grab_device = NULL;
static int video_channel = 0;
break;
}
ret = avcodec_encode_audio(enc, audio_out, size_out,
- (short *)buftmp);
+ (short *)buftmp);
audio_size += ret;
pkt.stream_index= ost->index;
pkt.data= audio_out;
padcolor);
}
- if (enc->pix_fmt != PIX_FMT_YUV420P) {
+ if (enc->pix_fmt != PIX_FMT_YUV420P) {
int size;
- av_free(buf);
+ av_free(buf);
/* create temporary picture */
size = avpicture_get_size(enc->pix_fmt, enc->width, enc->height);
buf = av_malloc(size);
goto the_end;
}
- }
+ }
} else if (ost->video_crop) {
picture_crop_temp.data[0] = formatted_picture->data[0] +
(ost->topBand * formatted_picture->linesize[0]) + ost->leftBand;
avoid any copies. We support temorarily the older
method. */
AVFrame* old_frame = enc->coded_frame;
- enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack
+ enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack
pkt.data= (uint8_t *)final_picture;
pkt.size= sizeof(AVPicture);
if(dec->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
pkt.flags |= PKT_FLAG_KEY;
av_interleaved_write_frame(s, &pkt);
- enc->coded_frame = old_frame;
+ enc->coded_frame = old_frame;
} else {
AVFrame big_picture;
}
static void print_report(AVFormatContext **output_files,
- AVOutputStream **ost_table, int nb_ostreams,
- int is_last_report)
+ AVOutputStream **ost_table, int nb_ostreams,
+ int is_last_report)
{
char buf[1024];
AVOutputStream *ost;
int frame_number, vid, i;
double bitrate, ti1, pts;
static int64_t last_time = -1;
+ static int qp_histogram[52];
if (!is_last_report) {
int64_t cur_time;
}
if (!vid && enc->codec_type == CODEC_TYPE_VIDEO) {
frame_number = ost->frame_number;
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d q=%2.1f ",
- frame_number, enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : 0);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d q=%3.1f ",
+ frame_number, enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
if(is_last_report)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
+ if(qp_hist && enc->coded_frame){
+ int j;
+ int qp= lrintf(enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ if(qp>=0 && qp<sizeof(qp_histogram)/sizeof(int))
+ qp_histogram[qp]++;
+ for(j=0; j<32; j++)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j]+1)/log(2)));
+ }
if (enc->flags&CODEC_FLAG_PSNR){
int j;
double error, error_sum=0;
"size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
(double)total_size / 1024, ti1, bitrate);
- if (verbose > 1)
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
- nb_frames_dup, nb_frames_drop);
+ if (verbose > 1)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
+ nb_frames_dup, nb_frames_drop);
if (verbose >= 0)
fprintf(stderr, "%s \r", buf);
int data_size, got_picture;
AVFrame picture;
void *buffer_to_free;
- static int samples_size= 0;
+ static unsigned int samples_size= 0;
static short *samples= NULL;
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
}
#endif
/* if output time reached then transcode raw format,
- encode packets and output them */
+ encode packets and output them */
if (start_time == 0 || ist->pts >= start_time)
for(i=0;i<nb_ostreams;i++) {
int frame_size;
codec->block_align= icodec->block_align;
break;
case CODEC_TYPE_VIDEO:
+ codec->pix_fmt = icodec->pix_fmt;
codec->width = icodec->width;
codec->height = icodec->height;
codec->has_b_frames = icodec->has_b_frames;
/* init pts */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
- is = input_files[ist->file_index];
+ is = input_files[ist->file_index];
ist->pts = 0;
ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q);
if(ist->st->start_time == AV_NOPTS_VALUE)
{
if (parse_frame_rate(&frame_rate, &frame_rate_base, arg) < 0) {
fprintf(stderr, "Incorrect frame rate\n");
- exit(1);
+ exit(1);
}
}
exit(1);
}
if ((frame_topBand) >= frame_height){
- fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
exit(1);
}
frame_height -= frame_topBand;
exit(1);
}
if ((frame_bottomBand) >= frame_height){
- fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
exit(1);
}
frame_height -= frame_bottomBand;
exit(1);
}
if ((frame_leftBand) >= frame_width){
- fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
exit(1);
}
frame_width -= frame_leftBand;
exit(1);
}
if ((frame_rightBand) >= frame_width){
- fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
+ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
exit(1);
}
frame_width -= frame_rightBand;
#define SCALEBITS 10
#define ONE_HALF (1 << (SCALEBITS - 1))
-#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
+#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
#define RGB_TO_Y(r, g, b) \
((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
p = strchr(arg, ':');
if (p) {
x = strtol(arg, (char **)&arg, 10);
- if (arg == p)
- y = strtol(arg+1, (char **)&arg, 10);
- if (x > 0 && y > 0)
- ar = (double)x / (double)y;
+ if (arg == p)
+ y = strtol(arg+1, (char **)&arg, 10);
+ if (x > 0 && y > 0)
+ ar = (double)x / (double)y;
} else
ar = strtod(arg, (char **)&arg);
if (!ar) {
fprintf(stderr, "Incorrect aspect ratio specification.\n");
- exit(1);
+ exit(1);
}
frame_aspect_ratio = ar;
}
{
video_qmin = atoi(arg);
if (video_qmin < 1 ||
- video_qmin > 31) {
- fprintf(stderr, "qmin must be >= 1 and <= 31\n");
+ video_qmin > 51) {
+ fprintf(stderr, "qmin must be >= 1 and <= 51\n");
exit(1);
}
}
{
video_qmax = atoi(arg);
if (video_qmax < 1 ||
- video_qmax > 31) {
- fprintf(stderr, "qmax must be >= 1 and <= 31\n");
+ video_qmax > 51) {
+ fprintf(stderr, "qmax must be >= 1 and <= 51\n");
exit(1);
}
}
"phods",
"epzs",
"x1",
+ "hex",
+ "umh",
+ "iter",
NULL,
};
}
frame_height = enc->height;
frame_width = enc->width;
- frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
- frame_pix_fmt = enc->pix_fmt;
+ frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
+ frame_pix_fmt = enc->pix_fmt;
rfps = ic->streams[i]->r_frame_rate.num;
rfps_base = ic->streams[i]->r_frame_rate.den;
enc->workaround_bugs = workaround_bugs;
if (b_frames) {
video_enc->max_b_frames = b_frames;
- video_enc->b_frame_strategy = b_strategy;
video_enc->b_quant_factor = 2.0;
}
video_enc->qmin = video_qmin;
oc->timestamp = rec_timestamp;
- if (str_title)
+ if (str_title)
pstrcpy(oc->title, sizeof(oc->title), str_title);
if (str_author)
pstrcpy(oc->author, sizeof(oc->author), str_author);
fprintf(stderr, "Not overwriting - exiting\n");
exit(1);
}
- }
- else {
+ }
+ else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
exit(1);
- }
+ }
}
}
fmt1 = av_find_input_format(video_grab_format);
vp->device = video_device;
vp->channel = video_channel;
- vp->standard = video_standard;
+ vp->standard = video_standard;
+ vp->pix_fmt = frame_pix_fmt;
if (av_open_input_file(&ic, "", fmt1, 0, vp) < 0) {
fprintf(stderr, "Could not find video grab device\n");
exit(1);
}
/* If not enough info to get the stream parameters, we decode the
first frames to get it. */
- if ((ic->ctx_flags & AVFMTCTX_NOHEADER) && av_find_stream_info(ic) < 0) {
+ if ((ic->ctx_flags & AVFMTCTX_NOHEADER) && av_find_stream_info(ic) < 0) {
fprintf(stderr, "Could not find video grab parameters\n");
exit(1);
}
exit(1);
}
-void parse_matrix_coeffs(uint16_t *dest, const char *str)
+static void parse_matrix_coeffs(uint16_t *dest, const char *str)
{
int i;
const char *p = str;
}
}
-void opt_inter_matrix(const char *arg)
+static void opt_inter_matrix(const char *arg)
{
inter_matrix = av_mallocz(sizeof(uint16_t) * 64);
parse_matrix_coeffs(inter_matrix, arg);
}
-void opt_intra_matrix(const char *arg)
+static void opt_intra_matrix(const char *arg)
{
intra_matrix = av_mallocz(sizeof(uint16_t) * 64);
parse_matrix_coeffs(intra_matrix, arg);
static void show_version(void)
{
+ /* TODO: add function interface to avutil and avformat */
fprintf(stderr, "ffmpeg " FFMPEG_VERSION "\n"
+ "libavutil %d\n"
"libavcodec %d\n"
"libavformat %d\n",
- avcodec_build(), LIBAVFORMAT_BUILD);
+ LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD);
exit(1);
}
{ "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
"when dumping packets, also dump the payload" },
{ "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
- { "loop", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
+ { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
{ "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
{ "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" },
{ "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
{ "i_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qoffset}, "qp offset between p and i frames", "offset" },
{ "ibias", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_ibias}, "intra quant bias", "bias" },
{ "pbias", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_pbias}, "inter quant bias", "bias" },
- { "b_strategy", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&b_strategy}, "dynamic b frame selection strategy", "strategy" },
{ "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
{ "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
{ "bt", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate_tolerance}, "set video bitrate tolerance (in kbit/s)", "tolerance" },
{ "skip_exp", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&frame_skip_exp}, "frame skip exponent", "exponent" },
{ "newvideo", OPT_VIDEO, {(void*)opt_new_video_stream}, "add a new video stream to the current output stream" },
{ "genpts", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&genpts }, "generate pts" },
+ { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
/* audio options */
{ "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },
static void show_banner(void)
{
- fprintf(stderr, "ffmpeg version " FFMPEG_VERSION ", build %d, Copyright (c) 2000-2004 Fabrice Bellard\n",
- LIBAVCODEC_BUILD);
- fprintf(stderr, " configuration: %s\n", FFMPEG_CONFIGURATION);
+ fprintf(stderr, "FFmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2004 Fabrice Bellard\n");
+ fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
+ fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
+ fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");
+ fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n");
fprintf(stderr, " built on " __DATE__ " " __TIME__);
#ifdef __GNUC__
- fprintf(stderr, ", gcc: %s\n", __VERSION__);
+ fprintf(stderr, ", gcc: " __VERSION__ "\n");
#else
fprintf(stderr, ", using a non-gcc compiler\n");
#endif
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
- "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
+ "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
);
#else
printf(
"\n"
"You should have received a copy of the GNU Lesser General Public\n"
"License along with this library; if not, write to the Free Software\n"
- "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
);
#endif
exit(1);
for(i=0;i<nb_output_files;i++) {
/* maybe av_close_output_file ??? */
AVFormatContext *s = output_files[i];
- int j;
+ int j;
if (!(s->oformat->flags & AVFMT_NOFILE))
- url_fclose(&s->pb);
- for(j=0;j<s->nb_streams;j++)
- av_free(s->streams[j]);
+ url_fclose(&s->pb);
+ for(j=0;j<s->nb_streams;j++)
+ av_free(s->streams[j]);
av_free(s);
}
for(i=0;i<nb_input_files;i++)