Amnon82
2nd April 2004, 21:17
THX goes to Mozart who found this patch. Now it is the time to add it into a ffmpeg source. First here the mail form the creator of the patch:
The attached patch adds the following options to ffmpeg:
-padtop size add border above the frame
-padbottom size add border below the frame
-padleft size add border left of the frame
-padright size add border right of the frame
-padcolor hexcolor filled padded region with a color (ex: FFFFFF = black)
apply with:
cd ffmpeg; patch -p 0 -i pad.diff
patch modifies:
ffmpeg.c
libavcodec/avcodec.h
libavcodec/imgresample.c
doc/ffmpeg-doc.texi
Todd Kirby
<doubleshot@pa...>
--
"Running from your problems never solves them, but it's pretty good cardio."
Index: ffmpeg.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/ffmpeg.c,v
retrieving revision 1.194
diff -u -b -B -r1.194 ffmpeg.c
--- ffmpeg.c 18 Mar 2004 22:51:42 -0000 1.194
+++ ffmpeg.c 26 Mar 2004 06:58:32 -0000
@@ -71,6 +71,11 @@
static int frame_height = 128;
static float frame_aspect_ratio = 0;
static enum PixelFormat frame_pix_fmt = PIX_FMT_YUV420P;
+static int frame_padtop = 0;
+static int frame_padbottom = 0;
+static int frame_padleft = 0;
+static int frame_padright = 0;
+static float padcolor[3] = {16,128,128}; /* default to black */
static int frame_topBand = 0;
static int frame_bottomBand = 0;
static int frame_leftBand = 0;
@@ -219,6 +224,12 @@
int topBand; /* cropping area sizes */
int leftBand;
+ int video_pad; /* video_resample and video_pad are mutually exclusive */
+ int padtop; /* padding area sizes */
+ int padbottom;
+ int padleft;
+ int padright;
+
/* audio only */
int audio_resample;
ReSampleContext *resample; /* for audio resampling */
@@ -494,6 +505,40 @@
/* we begin to correct av delay at this threshold */
#define AV_DELAY_MAX 0.100
+
+/* Expects img to be yuv420 */
+static void fill_pad_region(AVPicture* img, int height, int width,
+ int padtop, int padbottom, int padleft, int padright, float *color) {
+
+ int i, y, shift;
+ uint8_t *optr;
+
+ for (i = 0; i < 3; i++) {
+ shift = (i == 0) ? 0 : 1;
+
+ if (padtop || padleft) {
+ memset(img->data[i], color[i], (((img->linesize[i] * padtop) +
+ padleft) >> shift));
+ }
+
+ if (padleft || padright) {
+ optr = img->data[i] + (img->linesize[i] * (padtop >> shift)) +
+ (img->linesize[i] - (padright >> shift));
+
+ for (y = 0; y < ((height - (padtop + padbottom)) >> shift); y++) {
+ memset(optr, color[i], (padleft + padright) >> shift);
+ optr += img->linesize[i];
+ }
+ }
+
+ if (padbottom) {
+ optr = img->data[i] + (img->linesize[i] * ((height - padbottom) >> shift));
+ memset(optr, color[i], ((img->linesize[i] * padbottom) >> shift));
+ }
+ }
+}
+
+
static void do_video_out(AVFormatContext *s,
AVOutputStream *ost,
AVInputStream *ist,
@@ -576,7 +621,8 @@
return;
/* convert pixel format if needed */
- target_pixfmt = ost->video_resample ? PIX_FMT_YUV420P : enc->pix_fmt;
+ target_pixfmt = ost->video_resample || ost->video_pad
+ ? PIX_FMT_YUV420P : enc->pix_fmt;
if (dec->pix_fmt != target_pixfmt) {
int size;
@@ -598,12 +644,19 @@
formatted_picture = (AVPicture *)in_picture;
}
- /* XXX: resampling could be done before raw format convertion in
+ /* XXX: resampling could be done before raw format conversion in
some cases to go faster */
/* XXX: only works for YUV420P */
if (ost->video_resample) {
final_picture = &ost->pict_tmp;
img_resample(ost->img_resample_ctx, final_picture, formatted_picture);
+
+ if (ost->padtop || ost->padbottom || ost->padleft || ost->padright) {
+ fill_pad_region(final_picture, enc->height, enc->width,
+ ost->padtop, ost->padbottom, ost->padleft, ost->padright,
+ padcolor);
+ }
+
if (enc->pix_fmt != PIX_FMT_YUV420P) {
int size;
@@ -639,6 +692,51 @@
picture_crop_temp.linesize[1] = formatted_picture->linesize[1];
picture_crop_temp.linesize[2] = formatted_picture->linesize[2];
final_picture = &picture_crop_temp;
+ } else if (ost->video_pad) {
+ final_picture = &ost->pict_tmp;
+
+ for (i = 0; i < 3; i++) {
+ uint8_t *optr, *iptr;
+ int shift = (i == 0) ? 0 : 1;
+ int y, yheight;
+
+ /* set offset to start writing image into */
+ optr = final_picture->data[i] + (((final_picture->linesize[i] *
+ ost->padtop) + ost->padleft) >> shift);
+ iptr = formatted_picture->data[i];
+
+ yheight = (enc->height - ost->padtop - ost->padbottom) >> shift;
+ for (y = 0; y < yheight; y++) {
+ /* copy unpadded image row into padded image row */
+ memcpy(optr, iptr, formatted_picture->linesize[i]);
+ optr += final_picture->linesize[i];
+ iptr += formatted_picture->linesize[i];
+ }
+ }
+
+ fill_pad_region(final_picture, enc->height, enc->width,
+ ost->padtop, ost->padbottom, ost->padleft, ost->padright,
+ padcolor);
+
+ if (enc->pix_fmt != PIX_FMT_YUV420P) {
+ int size;
+
+ av_free(buf);
+ /* create temporary picture */
+ size = avpicture_get_size(enc->pix_fmt, enc->width, enc->height);
+ buf = av_malloc(size);
+ if (!buf)
+ return;
+ final_picture = &picture_format_temp;
+ avpicture_fill(final_picture, buf, enc->pix_fmt, enc->width, enc->height);
+
+ if (img_convert(final_picture, enc->pix_fmt,
+ &ost->pict_tmp, PIX_FMT_YUV420P,
+ enc->width, enc->height) < 0) {
+ fprintf(stderr, "pixel format conversion not handled\n");
+ goto the_end;
+ }
+ }
} else {
final_picture = formatted_picture;
}
@@ -1263,10 +1362,15 @@
frame_topBand == 0 &&
frame_bottomBand == 0 &&
frame_leftBand == 0 &&
- frame_rightBand == 0)
+ frame_rightBand == 0 &&
+ frame_padtop == 0 &&
+ frame_padbottom == 0 &&
+ frame_padleft == 0 &&
+ frame_padright == 0)
{
ost->video_resample = 0;
ost->video_crop = 0;
+ ost->video_pad = 0;
} else if ((codec->width == icodec->width -
(frame_leftBand + frame_rightBand)) &&
(codec->height == icodec->height -
@@ -1276,6 +1380,20 @@
ost->video_crop = 1;
ost->topBand = frame_topBand;
ost->leftBand = frame_leftBand;
+ } else if ((codec->width == icodec->width +
+ (frame_padleft + frame_padright)) &&
+ (codec->height == icodec->height +
+ (frame_padtop + frame_padbottom))) {
+ ost->video_resample = 0;
+ ost->video_crop = 0;
+ ost->video_pad = 1;
+ ost->padtop = frame_padtop;
+ ost->padleft = frame_padleft;
+ ost->padbottom = frame_padbottom;
+ ost->padright = frame_padright;
+ if( avpicture_alloc( &ost->pict_tmp, PIX_FMT_YUV420P,
+ codec->width, codec->height ) )
+ goto fail;
} else {
ost->video_resample = 1;
ost->video_crop = 0; // cropping is handled as part of resample
@@ -1287,7 +1405,15 @@
ost->st->codec.width, ost->st->codec.height,
ist->st->codec.width, ist->st->codec.height,
frame_topBand, frame_bottomBand,
- frame_leftBand, frame_rightBand);
+ frame_leftBand, frame_rightBand,
+ frame_padtop, frame_padbottom,
+ frame_padleft, frame_padright);
+
+ ost->padtop = frame_padtop;
+ ost->padleft = frame_padleft;
+ ost->padbottom = frame_padbottom;
+ ost->padright = frame_padright;
+
}
ost->encoding_needed = 1;
ist->decoding_needed = 1;
@@ -1805,6 +1931,82 @@
}
}
+
+#define RGB_TO_YUV(rgb, yuv) { \
+ yuv[0] = ( 0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16; \
+ yuv[2] = ( 0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]) + 128; \
+ yuv[1] = (-0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]) + 128; \
+}
+
+static void opt_pad_color(const char *arg) {
+ /* Input is expected to be six hex digits similar to
+ how colors are expressed in html tags (but without the #) */
+ int rgb = strtol(arg, NULL, 16);
+ int rgb_color[3];
+
+ rgb_color[0] = (rgb >> 16);
+ rgb_color[1] = ((rgb >> 8) & 255);
+ rgb_color[2] = (rgb & 255);
+
+ RGB_TO_YUV(rgb_color, padcolor);
+}
+
+
+static void opt_frame_pad_top(const char *arg)
+{
+ frame_padtop = atoi(arg);
+ if (frame_padtop < 0) {
+ fprintf(stderr, "Incorrect top pad size\n");
+ exit(1);
+ }
+ if ((frame_padtop % 2) != 0) {
+ fprintf(stderr, "Top pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+static void opt_frame_pad_bottom(const char *arg)
+{
+ frame_padbottom = atoi(arg);
+ if (frame_padbottom < 0) {
+ fprintf(stderr, "Incorrect bottom pad size\n");
+ exit(1);
+ }
+ if ((frame_padbottom % 2) != 0) {
+ fprintf(stderr, "Bottom pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_left(const char *arg)
+{
+ frame_padleft = atoi(arg);
+ if (frame_padleft < 0) {
+ fprintf(stderr, "Incorrect left pad size\n");
+ exit(1);
+ }
+ if ((frame_padleft % 2) != 0) {
+ fprintf(stderr, "Left pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_right(const char *arg)
+{
+ frame_padright = atoi(arg);
+ if (frame_padright < 0) {
+ fprintf(stderr, "Incorrect right pad size\n");
+ exit(1);
+ }
+ if ((frame_padright % 2) != 0) {
+ fprintf(stderr, "Right pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
static void opt_frame_pix_fmt(const char *arg)
{
frame_pix_fmt = avcodec_get_pix_fmt(arg);
@@ -2228,8 +2430,8 @@
ap->channels = audio_channels;
ap->frame_rate = frame_rate;
ap->frame_rate_base = frame_rate_base;
- ap->width = frame_width;
- ap->height = frame_height;
+ ap->width = frame_width + frame_padleft + frame_padright;
+ ap->height = frame_height + frame_padtop + frame_padbottom;
ap->image_format = image_format;
ap->pix_fmt = frame_pix_fmt;
@@ -2443,8 +2645,8 @@
video_enc->frame_rate = frame_rate;
video_enc->frame_rate_base = frame_rate_base;
- video_enc->width = frame_width;
- video_enc->height = frame_height;
+ video_enc->width = frame_width + frame_padright + frame_padleft;
+ video_enc->height = frame_height + frame_padtop + frame_padbottom;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width,
255);
video_enc->pix_fmt = frame_pix_fmt;
@@ -3147,6 +3349,11 @@
{ "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop
band size (in pixels)", "size" },
{ "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_left}, "set left crop band
size (in pixels)", "size" },
{ "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_right}, "set right crop
band size (in pixels)", "size" },
+ { "padtop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_top}, "set top pad band size
(in pixels)", "size" },
+ { "padbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_bottom}, "set bottom pad
band size (in pixels)", "size" },
+ { "padleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_left}, "set left pad band size
(in pixels)", "size" },
+ { "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_right}, "set right pad band
size (in pixels)", "size" },
+ { "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad_color}, "set color of pad bands
(Hex 000000 thru FFFFFF)", "color" },
{ "g", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_gop_size}, "set the group of
picture size", "gop_size" },
{ "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra
frames"},
{ "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
@@ -3199,7 +3406,7 @@
{ "bug", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_workaround_bugs}, "workaround
not auto detected encoder bugs", "param" },
{ "ps", HAS_ARG | OPT_EXPERT, {(void*)opt_packet_size}, "set packet size in bits",
"size" },
{ "error", HAS_ARG | OPT_EXPERT, {(void*)opt_error_rate}, "error rate", "rate" },
- { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to
follow the standarts", "strictness" },
+ { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to
follow the standards", "strictne
I try now to add it into the source.
The attached patch adds the following options to ffmpeg:
-padtop size add border above the frame
-padbottom size add border below the frame
-padleft size add border left of the frame
-padright size add border right of the frame
-padcolor hexcolor filled padded region with a color (ex: FFFFFF = black)
apply with:
cd ffmpeg; patch -p 0 -i pad.diff
patch modifies:
ffmpeg.c
libavcodec/avcodec.h
libavcodec/imgresample.c
doc/ffmpeg-doc.texi
Todd Kirby
<doubleshot@pa...>
--
"Running from your problems never solves them, but it's pretty good cardio."
Index: ffmpeg.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/ffmpeg.c,v
retrieving revision 1.194
diff -u -b -B -r1.194 ffmpeg.c
--- ffmpeg.c 18 Mar 2004 22:51:42 -0000 1.194
+++ ffmpeg.c 26 Mar 2004 06:58:32 -0000
@@ -71,6 +71,11 @@
static int frame_height = 128;
static float frame_aspect_ratio = 0;
static enum PixelFormat frame_pix_fmt = PIX_FMT_YUV420P;
+static int frame_padtop = 0;
+static int frame_padbottom = 0;
+static int frame_padleft = 0;
+static int frame_padright = 0;
+static float padcolor[3] = {16,128,128}; /* default to black */
static int frame_topBand = 0;
static int frame_bottomBand = 0;
static int frame_leftBand = 0;
@@ -219,6 +224,12 @@
int topBand; /* cropping area sizes */
int leftBand;
+ int video_pad; /* video_resample and video_pad are mutually exclusive */
+ int padtop; /* padding area sizes */
+ int padbottom;
+ int padleft;
+ int padright;
+
/* audio only */
int audio_resample;
ReSampleContext *resample; /* for audio resampling */
@@ -494,6 +505,40 @@
/* we begin to correct av delay at this threshold */
#define AV_DELAY_MAX 0.100
+
+/* Expects img to be yuv420 */
+static void fill_pad_region(AVPicture* img, int height, int width,
+ int padtop, int padbottom, int padleft, int padright, float *color) {
+
+ int i, y, shift;
+ uint8_t *optr;
+
+ for (i = 0; i < 3; i++) {
+ shift = (i == 0) ? 0 : 1;
+
+ if (padtop || padleft) {
+ memset(img->data[i], color[i], (((img->linesize[i] * padtop) +
+ padleft) >> shift));
+ }
+
+ if (padleft || padright) {
+ optr = img->data[i] + (img->linesize[i] * (padtop >> shift)) +
+ (img->linesize[i] - (padright >> shift));
+
+ for (y = 0; y < ((height - (padtop + padbottom)) >> shift); y++) {
+ memset(optr, color[i], (padleft + padright) >> shift);
+ optr += img->linesize[i];
+ }
+ }
+
+ if (padbottom) {
+ optr = img->data[i] + (img->linesize[i] * ((height - padbottom) >> shift));
+ memset(optr, color[i], ((img->linesize[i] * padbottom) >> shift));
+ }
+ }
+}
+
+
static void do_video_out(AVFormatContext *s,
AVOutputStream *ost,
AVInputStream *ist,
@@ -576,7 +621,8 @@
return;
/* convert pixel format if needed */
- target_pixfmt = ost->video_resample ? PIX_FMT_YUV420P : enc->pix_fmt;
+ target_pixfmt = ost->video_resample || ost->video_pad
+ ? PIX_FMT_YUV420P : enc->pix_fmt;
if (dec->pix_fmt != target_pixfmt) {
int size;
@@ -598,12 +644,19 @@
formatted_picture = (AVPicture *)in_picture;
}
- /* XXX: resampling could be done before raw format convertion in
+ /* XXX: resampling could be done before raw format conversion in
some cases to go faster */
/* XXX: only works for YUV420P */
if (ost->video_resample) {
final_picture = &ost->pict_tmp;
img_resample(ost->img_resample_ctx, final_picture, formatted_picture);
+
+ if (ost->padtop || ost->padbottom || ost->padleft || ost->padright) {
+ fill_pad_region(final_picture, enc->height, enc->width,
+ ost->padtop, ost->padbottom, ost->padleft, ost->padright,
+ padcolor);
+ }
+
if (enc->pix_fmt != PIX_FMT_YUV420P) {
int size;
@@ -639,6 +692,51 @@
picture_crop_temp.linesize[1] = formatted_picture->linesize[1];
picture_crop_temp.linesize[2] = formatted_picture->linesize[2];
final_picture = &picture_crop_temp;
+ } else if (ost->video_pad) {
+ final_picture = &ost->pict_tmp;
+
+ for (i = 0; i < 3; i++) {
+ uint8_t *optr, *iptr;
+ int shift = (i == 0) ? 0 : 1;
+ int y, yheight;
+
+ /* set offset to start writing image into */
+ optr = final_picture->data[i] + (((final_picture->linesize[i] *
+ ost->padtop) + ost->padleft) >> shift);
+ iptr = formatted_picture->data[i];
+
+ yheight = (enc->height - ost->padtop - ost->padbottom) >> shift;
+ for (y = 0; y < yheight; y++) {
+ /* copy unpadded image row into padded image row */
+ memcpy(optr, iptr, formatted_picture->linesize[i]);
+ optr += final_picture->linesize[i];
+ iptr += formatted_picture->linesize[i];
+ }
+ }
+
+ fill_pad_region(final_picture, enc->height, enc->width,
+ ost->padtop, ost->padbottom, ost->padleft, ost->padright,
+ padcolor);
+
+ if (enc->pix_fmt != PIX_FMT_YUV420P) {
+ int size;
+
+ av_free(buf);
+ /* create temporary picture */
+ size = avpicture_get_size(enc->pix_fmt, enc->width, enc->height);
+ buf = av_malloc(size);
+ if (!buf)
+ return;
+ final_picture = &picture_format_temp;
+ avpicture_fill(final_picture, buf, enc->pix_fmt, enc->width, enc->height);
+
+ if (img_convert(final_picture, enc->pix_fmt,
+ &ost->pict_tmp, PIX_FMT_YUV420P,
+ enc->width, enc->height) < 0) {
+ fprintf(stderr, "pixel format conversion not handled\n");
+ goto the_end;
+ }
+ }
} else {
final_picture = formatted_picture;
}
@@ -1263,10 +1362,15 @@
frame_topBand == 0 &&
frame_bottomBand == 0 &&
frame_leftBand == 0 &&
- frame_rightBand == 0)
+ frame_rightBand == 0 &&
+ frame_padtop == 0 &&
+ frame_padbottom == 0 &&
+ frame_padleft == 0 &&
+ frame_padright == 0)
{
ost->video_resample = 0;
ost->video_crop = 0;
+ ost->video_pad = 0;
} else if ((codec->width == icodec->width -
(frame_leftBand + frame_rightBand)) &&
(codec->height == icodec->height -
@@ -1276,6 +1380,20 @@
ost->video_crop = 1;
ost->topBand = frame_topBand;
ost->leftBand = frame_leftBand;
+ } else if ((codec->width == icodec->width +
+ (frame_padleft + frame_padright)) &&
+ (codec->height == icodec->height +
+ (frame_padtop + frame_padbottom))) {
+ ost->video_resample = 0;
+ ost->video_crop = 0;
+ ost->video_pad = 1;
+ ost->padtop = frame_padtop;
+ ost->padleft = frame_padleft;
+ ost->padbottom = frame_padbottom;
+ ost->padright = frame_padright;
+ if( avpicture_alloc( &ost->pict_tmp, PIX_FMT_YUV420P,
+ codec->width, codec->height ) )
+ goto fail;
} else {
ost->video_resample = 1;
ost->video_crop = 0; // cropping is handled as part of resample
@@ -1287,7 +1405,15 @@
ost->st->codec.width, ost->st->codec.height,
ist->st->codec.width, ist->st->codec.height,
frame_topBand, frame_bottomBand,
- frame_leftBand, frame_rightBand);
+ frame_leftBand, frame_rightBand,
+ frame_padtop, frame_padbottom,
+ frame_padleft, frame_padright);
+
+ ost->padtop = frame_padtop;
+ ost->padleft = frame_padleft;
+ ost->padbottom = frame_padbottom;
+ ost->padright = frame_padright;
+
}
ost->encoding_needed = 1;
ist->decoding_needed = 1;
@@ -1805,6 +1931,82 @@
}
}
+
+#define RGB_TO_YUV(rgb, yuv) { \
+ yuv[0] = ( 0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16; \
+ yuv[2] = ( 0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]) + 128; \
+ yuv[1] = (-0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]) + 128; \
+}
+
+static void opt_pad_color(const char *arg) {
+ /* Input is expected to be six hex digits similar to
+ how colors are expressed in html tags (but without the #) */
+ int rgb = strtol(arg, NULL, 16);
+ int rgb_color[3];
+
+ rgb_color[0] = (rgb >> 16);
+ rgb_color[1] = ((rgb >> 8) & 255);
+ rgb_color[2] = (rgb & 255);
+
+ RGB_TO_YUV(rgb_color, padcolor);
+}
+
+
+static void opt_frame_pad_top(const char *arg)
+{
+ frame_padtop = atoi(arg);
+ if (frame_padtop < 0) {
+ fprintf(stderr, "Incorrect top pad size\n");
+ exit(1);
+ }
+ if ((frame_padtop % 2) != 0) {
+ fprintf(stderr, "Top pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+static void opt_frame_pad_bottom(const char *arg)
+{
+ frame_padbottom = atoi(arg);
+ if (frame_padbottom < 0) {
+ fprintf(stderr, "Incorrect bottom pad size\n");
+ exit(1);
+ }
+ if ((frame_padbottom % 2) != 0) {
+ fprintf(stderr, "Bottom pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_left(const char *arg)
+{
+ frame_padleft = atoi(arg);
+ if (frame_padleft < 0) {
+ fprintf(stderr, "Incorrect left pad size\n");
+ exit(1);
+ }
+ if ((frame_padleft % 2) != 0) {
+ fprintf(stderr, "Left pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
+static void opt_frame_pad_right(const char *arg)
+{
+ frame_padright = atoi(arg);
+ if (frame_padright < 0) {
+ fprintf(stderr, "Incorrect right pad size\n");
+ exit(1);
+ }
+ if ((frame_padright % 2) != 0) {
+ fprintf(stderr, "Right pad size must be a multiple of 2\n");
+ exit(1);
+ }
+}
+
+
static void opt_frame_pix_fmt(const char *arg)
{
frame_pix_fmt = avcodec_get_pix_fmt(arg);
@@ -2228,8 +2430,8 @@
ap->channels = audio_channels;
ap->frame_rate = frame_rate;
ap->frame_rate_base = frame_rate_base;
- ap->width = frame_width;
- ap->height = frame_height;
+ ap->width = frame_width + frame_padleft + frame_padright;
+ ap->height = frame_height + frame_padtop + frame_padbottom;
ap->image_format = image_format;
ap->pix_fmt = frame_pix_fmt;
@@ -2443,8 +2645,8 @@
video_enc->frame_rate = frame_rate;
video_enc->frame_rate_base = frame_rate_base;
- video_enc->width = frame_width;
- video_enc->height = frame_height;
+ video_enc->width = frame_width + frame_padright + frame_padleft;
+ video_enc->height = frame_height + frame_padtop + frame_padbottom;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width,
255);
video_enc->pix_fmt = frame_pix_fmt;
@@ -3147,6 +3349,11 @@
{ "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop
band size (in pixels)", "size" },
{ "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_left}, "set left crop band
size (in pixels)", "size" },
{ "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_right}, "set right crop
band size (in pixels)", "size" },
+ { "padtop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_top}, "set top pad band size
(in pixels)", "size" },
+ { "padbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_bottom}, "set bottom pad
band size (in pixels)", "size" },
+ { "padleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_left}, "set left pad band size
(in pixels)", "size" },
+ { "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_pad_right}, "set right pad band
size (in pixels)", "size" },
+ { "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad_color}, "set color of pad bands
(Hex 000000 thru FFFFFF)", "color" },
{ "g", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_gop_size}, "set the group of
picture size", "gop_size" },
{ "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra
frames"},
{ "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
@@ -3199,7 +3406,7 @@
{ "bug", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_workaround_bugs}, "workaround
not auto detected encoder bugs", "param" },
{ "ps", HAS_ARG | OPT_EXPERT, {(void*)opt_packet_size}, "set packet size in bits",
"size" },
{ "error", HAS_ARG | OPT_EXPERT, {(void*)opt_error_rate}, "error rate", "rate" },
- { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to
follow the standarts", "strictness" },
+ { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to
follow the standards", "strictne
I try now to add it into the source.