]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
AltiVec implies a PPC CPU, so there is no need to check for both.
[ffmpeg] / ffmpeg.c
index 3bc751c0d478763f80e33e8cb36def81d67dcebe..951b0daec2d881a733c206de9a657a60e3e7a20a 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -343,6 +343,7 @@ static void term_init(void)
 
     tcgetattr (0, &tty);
     oldtty = tty;
+    atexit(term_exit);
 
     tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
                           |INLCR|IGNCR|ICRNL|IXON);
@@ -363,10 +364,6 @@ static void term_init(void)
     signal(SIGXCPU, sigterm_handler);
 #endif
 
-    /*
-    register a function to be called at normal program termination
-    */
-    atexit(term_exit);
 #if CONFIG_BEOS_NETSERVER
     fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
 #endif
@@ -1646,6 +1643,47 @@ static void print_sdp(AVFormatContext **avc, int n)
     fflush(stdout);
 }
 
+static int copy_chapters(int infile, int outfile)
+{
+    AVFormatContext *is = input_files[infile];
+    AVFormatContext *os = output_files[outfile];
+    int i;
+
+    for (i = 0; i < is->nb_chapters; i++) {
+        AVChapter *in_ch = is->chapters[i], *out_ch;
+        AVMetadataTag *t = NULL;
+        int64_t ts_off   = av_rescale_q(start_time - input_files_ts_offset[infile],
+                                      AV_TIME_BASE_Q, in_ch->time_base);
+        int64_t rt       = (recording_time == INT64_MAX) ? INT64_MAX :
+                           av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base);
+
+
+        if (in_ch->end < ts_off)
+            continue;
+        if (rt != INT64_MAX && in_ch->start > rt + ts_off)
+            break;
+
+        out_ch = av_mallocz(sizeof(AVChapter));
+        if (!out_ch)
+            return AVERROR(ENOMEM);
+
+        out_ch->id        = in_ch->id;
+        out_ch->time_base = in_ch->time_base;
+        out_ch->start     = FFMAX(0,  in_ch->start - ts_off);
+        out_ch->end       = FFMIN(rt, in_ch->end   - ts_off);
+
+        while ((t = av_metadata_get(in_ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
+            av_metadata_set2(&out_ch->metadata, t->key, t->value, 0);
+
+        os->nb_chapters++;
+        os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
+        if (!os->chapters)
+            return AVERROR(ENOMEM);
+        os->chapters[os->nb_chapters - 1] = out_ch;
+    }
+    return 0;
+}
+
 /*
  * The following code is the main loop of the file converter
  */
@@ -1920,7 +1958,7 @@ static int av_encode(AVFormatContext **output_files,
                 break;
             case CODEC_TYPE_VIDEO:
                 if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
-                    fprintf(stderr, "Video pixel format is unknown, stream cannot be decoded\n");
+                    fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
                     av_exit(1);
                 }
                 ost->video_crop = ((frame_leftBand + frame_rightBand + frame_topBand + frame_bottomBand) != 0);
@@ -2134,6 +2172,16 @@ static int av_encode(AVFormatContext **output_files,
                                     in_file->iformat->metadata_conv);
     }
 
+    /* copy chapters from the first input file that has them*/
+    for (i = 0; i < nb_input_files; i++) {
+        if (!input_files[i]->nb_chapters)
+            continue;
+
+        for (j = 0; j < nb_output_files; j++)
+            if ((ret = copy_chapters(i, j)) < 0)
+                goto dump_format;
+    }
+
     /* open files and write file headers */
     for(i=0;i<nb_output_files;i++) {
         os = output_files[i];
@@ -3147,7 +3195,11 @@ static void new_video_stream(AVFormatContext *oc)
                 if(*p == video_enc->pix_fmt)
                     break;
             }
-            if(*p == -1)
+            if(*p == -1
+               && !(   video_enc->codec_id==CODEC_ID_MJPEG
+                    && video_enc->strict_std_compliance <= FF_COMPLIANCE_INOFFICIAL
+                    && (   video_enc->pix_fmt == PIX_FMT_YUV420P
+                        || video_enc->pix_fmt == PIX_FMT_YUV422P)))
                 video_enc->pix_fmt = codec->pix_fmts[0];
         }