diff --git a/oggenc/encode.c b/oggenc/encode.c
index 86f1596..0e95baf 100644
--- a/oggenc/encode.c
+++ b/oggenc/encode.c
@@ -458,6 +458,53 @@ int oe_encode(oe_enc_opt *opt)
 #endif
         }
 
+        /* Add comment padding, if necessary */
+        if (opt->comment_padding)
+        {
+            int padblock = opt->comment_padding;
+            const long bitrate = vi.bitrate_nominal;
+            const long size = header_comments.bytes;
+
+            if (padblock == 1 || padblock < 0)
+            {
+                /* no padding size given; try to pick a reasonable default */
+
+                const long seconds = opt->total_samples_per_channel / opt->rate;
+                if (padblock != 1 && seconds < 30)
+                {
+                    /* unless padding was requested (padblock==1), disable it
+                     * for files of short or unknown (seconds==0) length */
+                    padblock = 0;
+                }
+                else if (seconds < 30 || (bitrate > 0 && bitrate < 96000))
+                    padblock = 512;
+                else
+                    padblock = 4096;
+            }
+
+            /* pad to a multiple of padblock bytes,
+             * leaving at least padblock/2 bytes free */
+            if (padblock)
+            {
+                char *new_packet;
+                long padding;
+                const int min_padding = padblock / 2;
+
+                padding = size + (padblock - 1) + min_padding;
+                padding -= (padding % padblock) + size;
+
+                new_packet = malloc(size + padding);
+                if (new_packet)
+                {
+                    memcpy(new_packet, header_comments.packet, size);
+                    memset(new_packet + size, 0, padding);
+
+                    header_comments.bytes = size + padding;
+                    header_comments.packet = new_packet;
+                }
+            }
+        }
+
         /* write the next Vorbis headers */
         ogg_stream_packetin(&os,&header_comments);
         ogg_stream_packetin(&os,&header_codebooks);
diff --git a/oggenc/encode.h b/oggenc/encode.h
index e3dd33b..9d16d41 100644
--- a/oggenc/encode.h
+++ b/oggenc/encode.h
@@ -62,6 +62,7 @@ typedef struct
     int advopt_count;
 
     int copy_comments;
+    int comment_padding;
     int with_skeleton;
     int quiet;
     int rawmode;
@@ -122,6 +123,7 @@ typedef struct
     int endianness;
     int resamplefreq;
     int copy_comments;
+    int comment_padding;
     int with_skeleton;
 
     /* Various bitrate/quality options */
diff --git a/oggenc/oggenc.c b/oggenc/oggenc.c
index 345b92c..8f3e332 100644
--- a/oggenc/oggenc.c
+++ b/oggenc/oggenc.c
@@ -39,6 +39,7 @@ struct option long_options[] = {
     {"quiet",0,0,'Q'},
     {"help",0,0,'h'},
     {"skeleton",no_argument,NULL, 'k'},
+    {"comment-padding",2,0,0},
     {"comment",1,0,'c'},
     {"artist",1,0,'a'},
     {"album",1,0,'l'},
@@ -87,15 +88,25 @@ int main(int argc, char **argv)
 {
     /* Default values */
     oe_options opt = {
+              /* title, artist, album, comments, tracknum */
               NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0,
+              /* dates, genre, lyrics, lyrics_language, advopt */
               NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0,
-              1, 0, 0, 0,
+              /* copy_comments, comment_padding, with_skeleton, quiet, rawmode */
+              1, -1, 0, 0, 0,
+              /* raw_{samplesize, samplerate, channels, endianness} */
               16,44100,2, 0,
+              /* namefmt{, _remove, _replace} */
               NULL, DEFAULT_NAMEFMT_REMOVE, DEFAULT_NAMEFMT_REPLACE,
+              /* outfile */
               NULL,
+              /* managed, min_bitrate, nominal_bitrate, max_bitrate */
               0, -1,-1,-1,
+              /* quality, quality_set */
               .3,-1,
+              /* resamplefreq, downmix, scale */
               0,0,0.f,
+              /* serial, skeleton_serial, kate_serial, fixedserial, ignorelength */
               0, 0, 0, 0, 0};
 
     int i;
@@ -178,6 +189,7 @@ int main(int argc, char **argv)
         enc_opts.error = encode_error;
         enc_opts.comments = &vc;
         enc_opts.copy_comments = opt.copy_comments;
+        enc_opts.comment_padding = opt.comment_padding;
         enc_opts.with_skeleton = opt.with_skeleton;
         enc_opts.ignorelength = opt.ignorelength;
 
@@ -538,6 +550,11 @@ static void usage(void)
         "                      Default settings for the above two arguments are platform\n"
         "                      specific.\n"));
     fprintf(stdout, _(
+        " --comment-padding=n  Pad the comment packet to a multiple of n bytes.\n"
+        "                      Specify 0 to disable padding, or 1 to force it using an\n"
+        "                      automatically-determined amount. By default padding is\n"
+        "                      automatic, but disabled for short input files.\n"));
+    fprintf(stdout, _(
         " --utf8               Tells oggenc that the command line parameters date, title,\n"
         "                      album, artist, genre, and comment are already in UTF-8.\n"
         "                      On Windows, this switch applies to file names too.\n"
@@ -699,6 +716,19 @@ static void parse_options(int argc, char **argv, oe_options *opt)
                 if(!strcmp(long_options[option_index].name, "skeleton")) {
                     opt->with_skeleton = 1;
                 }
+                else if(!strcmp(long_options[option_index].name,
+                        "comment-padding")) {
+                    if(optarg)
+                    {
+                        if(sscanf(optarg, "%d", &opt->comment_padding) != 1) {
+                            fprintf(stderr, _("WARNING: Couldn't parse"
+                                    " comment-padding argument \"%s\"\n"),
+                                    optarg);
+                            opt->comment_padding = -1;
+                        }
+                    }
+                    else opt->comment_padding = 1;
+                }
                 else if(!strcmp(long_options[option_index].name, "managed")) {
                     if(!opt->managed){
                         if(!opt->quiet)
