]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
* fixing bug that prevented resampling the picture and
[ffmpeg] / ffmpeg.c
index 56b884a0042a10d1ba9a5c9d2e88f44f9a50e7d5..697005458921bc963a614f60034e9361eb8666f1 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #define HAVE_AV_CONFIG_H
-#include "common.h"
 #include "avformat.h"
 #include "framehook.h"
-/* usleep() */
-#include "os_support.h"
 
 #ifndef CONFIG_WIN32
 #include <unistd.h>
@@ -38,7 +35,6 @@
 #include <stdlib.h>
 #endif
 #include <time.h>
-#include <ctype.h>
 
 #include "cmdutils.h"
 
@@ -471,6 +467,7 @@ static void do_video_out(AVFormatContext *s,
     static uint8_t *video_buffer;
     uint8_t *buf = NULL, *buf1 = NULL;
     AVCodecContext *enc, *dec;
+    enum PixelFormat target_pixfmt;
 
 #define VIDEO_BUFFER_SIZE (1024*1024)
 
@@ -538,7 +535,8 @@ static void do_video_out(AVFormatContext *s,
         return;
 
     /* convert pixel format if needed */
-    if (enc->pix_fmt != dec->pix_fmt) {
+    target_pixfmt = ost->video_resample ? PIX_FMT_YUV420P : enc->pix_fmt;
+    if (dec->pix_fmt != target_pixfmt) {
         int size;
 
         /* create temporary picture */
@@ -549,7 +547,7 @@ static void do_video_out(AVFormatContext *s,
         formatted_picture = &picture_format_temp;
         avpicture_fill(formatted_picture, buf, enc->pix_fmt, dec->width, dec->height);
         
-        if (img_convert(formatted_picture, enc->pix_fmt, 
+        if (img_convert(formatted_picture, target_pixfmt, 
                         in_picture, dec->pix_fmt, 
                         dec->width, dec->height) < 0) {
             fprintf(stderr, "pixel format conversion not handled\n");
@@ -565,6 +563,25 @@ static void do_video_out(AVFormatContext *s,
     if (ost->video_resample) {
         final_picture = &ost->pict_tmp;
         img_resample(ost->img_resample_ctx, final_picture, formatted_picture);
+       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 if (ost->video_crop) {
         picture_crop_temp.data[0] = formatted_picture->data[0] +
                 (ost->topBand * formatted_picture->linesize[0]) + ost->leftBand;
@@ -1125,18 +1142,20 @@ static int av_encode(AVFormatContext **output_files,
         ist = ist_table[i];
        is = input_files[ist->file_index];
         ist->pts = 0;
-        switch (ist->st->codec.codec_type) {
-        case CODEC_TYPE_AUDIO:
-           av_frac_init(&ist->next_pts, 
-                        0, 0, is->pts_num * ist->st->codec.sample_rate);
-            break;
-        case CODEC_TYPE_VIDEO:
-            av_frac_init(&ist->next_pts, 
-                        0, 0, is->pts_num * ist->st->codec.frame_rate);
-            break;
-        default:
-            break;
-       }
+        if (ist->decoding_needed) {
+            switch (ist->st->codec.codec_type) {
+            case CODEC_TYPE_AUDIO:
+                av_frac_init(&ist->next_pts, 
+                             0, 0, (uint64_t)is->pts_num * ist->st->codec.sample_rate);
+                break;
+            case CODEC_TYPE_VIDEO:
+                av_frac_init(&ist->next_pts, 
+                             0, 0, (uint64_t)is->pts_num * ist->st->codec.frame_rate);
+                break;
+            default:
+                break;
+            }
+        }
     }
     
     /* compute buffer size max (should use a complete heuristic) */
@@ -1277,7 +1296,7 @@ static int av_encode(AVFormatContext **output_files,
                     }
                     data_buf = (uint8_t *)samples;
                    av_frac_add(&ist->next_pts, 
-                               is->pts_den * data_size / (2 * ist->st->codec.channels));
+                               (uint64_t)is->pts_den * data_size / (2 * ist->st->codec.channels));
                     break;
                 case CODEC_TYPE_VIDEO:
                     {
@@ -1302,7 +1321,7 @@ static int av_encode(AVFormatContext **output_files,
                             continue;
                         }
                         av_frac_add(&ist->next_pts, 
-                                   is->pts_den * ist->st->codec.frame_rate_base);          
+                                   (uint64_t)is->pts_den * ist->st->codec.frame_rate_base);          
                     }
                     break;
                 default:
@@ -2194,6 +2213,9 @@ static void opt_output_file(const char *filename)
             avcodec_get_context_defaults(&st->codec);
 
             video_enc = &st->codec;
+            
+            if(!strcmp(file_oformat->name, "mp4") || !strcmp(file_oformat->name, "mov") || !strcmp(file_oformat->name, "3gp"))
+                video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
             if (video_stream_copy) {
                 st->stream_copy = 1;
                 video_enc->codec_type = CODEC_TYPE_VIDEO;
@@ -2692,7 +2714,7 @@ const OptionDef options[] = {
     { "idct_algo", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_idct_algo}, "set idct algo",  "algo" },
     { "er", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_resilience}, "set error resilience",  "n" },
     { "ec", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_concealment}, "set error concealment",  "bit_mask" },
-    { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames (only MPEG-4)", "frames" },
+    { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames", "frames" },
     { "hq", OPT_BOOL, {(void*)&mb_decision}, "activate high quality settings" },
     { "mbd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_decision}, "macroblock decision", "mode" },
     { "4mv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_4mv}, "use four motion vector by macroblock (only MPEG-4)" },