]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
Actually add flag (somehow got lost in my previous patchset?), fixes broken
[ffmpeg] / ffmpeg.c
index c053a239555b86fdab675304cf03c3845d2df851..5d882446475f00439c5f36bc64b321e8e2474dee 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -515,6 +515,7 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
     s->nb_streams = ic->nb_streams;
     for(i=0;i<ic->nb_streams;i++) {
         AVStream *st;
+        AVCodec *codec;
 
         // FIXME: a more elegant solution is needed
         st = av_mallocz(sizeof(AVStream));
@@ -524,13 +525,21 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
             print_error(filename, AVERROR(ENOMEM));
             av_exit(1);
         }
-        memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
+        avcodec_copy_context(st->codec, ic->streams[i]->codec);
         s->streams[i] = st;
 
-        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_stream_copy)
-            st->stream_copy = 1;
-        else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_stream_copy)
-            st->stream_copy = 1;
+        codec = avcodec_find_encoder(st->codec->codec_id);
+        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+            if (audio_stream_copy) {
+                st->stream_copy = 1;
+            } else
+                choose_sample_fmt(st, codec);
+        } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+            if (video_stream_copy) {
+                st->stream_copy = 1;
+            } else
+                choose_pixel_fmt(st, codec);
+        }
 
         if(!st->codec->thread_count)
             st->codec->thread_count = 1;
@@ -563,7 +572,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx
         int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
                                           &new_pkt.data, &new_pkt.size,
                                           pkt->data, pkt->size,
-                                          pkt->flags & PKT_FLAG_KEY);
+                                          pkt->flags & AV_PKT_FLAG_KEY);
         if(a>0){
             av_free_packet(pkt);
             new_pkt.destruct= av_destruct_packet;
@@ -768,7 +777,7 @@ need_realloc:
             pkt.size= ret;
             if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
                 pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
-            pkt.flags |= PKT_FLAG_KEY;
+            pkt.flags |= AV_PKT_FLAG_KEY;
             write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
 
             ost->sync_opts += enc->frame_size;
@@ -803,7 +812,7 @@ need_realloc:
         pkt.size= ret;
         if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
             pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
-        pkt.flags |= PKT_FLAG_KEY;
+        pkt.flags |= AV_PKT_FLAG_KEY;
         write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
     }
 }
@@ -1077,7 +1086,7 @@ static void do_video_out(AVFormatContext *s,
             pkt.data= (uint8_t *)final_picture;
             pkt.size=  sizeof(AVPicture);
             pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
-            pkt.flags |= PKT_FLAG_KEY;
+            pkt.flags |= AV_PKT_FLAG_KEY;
 
             write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
             enc->coded_frame = old_frame;
@@ -1125,7 +1134,7 @@ static void do_video_out(AVFormatContext *s,
    pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/
 
                 if(enc->coded_frame->key_frame)
-                    pkt.flags |= PKT_FLAG_KEY;
+                    pkt.flags |= AV_PKT_FLAG_KEY;
                 write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
                 *frame_size = ret;
                 video_size += ret;
@@ -1507,7 +1516,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
 
                         av_init_packet(&opkt);
 
-                        if ((!ost->frame_number && !(pkt->flags & PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
+                        if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
                             continue;
 
                         /* no reencoding needed : output the packet directly */
@@ -1515,7 +1524,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
 
                         avcodec_get_frame_defaults(&avframe);
                         ost->st->codec->coded_frame= &avframe;
-                        avframe.key_frame = pkt->flags & PKT_FLAG_KEY;
+                        avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY;
 
                         if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
                             audio_size += data_size;
@@ -1544,7 +1553,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
                            && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO
                            && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO
                            ) {
-                            if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
+                            if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY))
                                 opkt.destruct= av_destruct_packet;
                         } else {
                             opkt.data = data_buf;
@@ -1627,7 +1636,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
                                 av_exit(1);
                             }
                             audio_size += ret;
-                            pkt.flags |= PKT_FLAG_KEY;
+                            pkt.flags |= AV_PKT_FLAG_KEY;
                             break;
                         case AVMEDIA_TYPE_VIDEO:
                             ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
@@ -1637,7 +1646,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
                             }
                             video_size += ret;
                             if(enc->coded_frame && enc->coded_frame->key_frame)
-                                pkt.flags |= PKT_FLAG_KEY;
+                                pkt.flags |= AV_PKT_FLAG_KEY;
                             if (ost->logfile && enc->stats_out) {
                                 fprintf(ost->logfile, "%s", enc->stats_out);
                             }
@@ -1717,11 +1726,11 @@ static int copy_chapters(int infile, int outfile)
 /*
  * The following code is the main loop of the file converter
  */
-static int av_encode(AVFormatContext **output_files,
-                     int nb_output_files,
-                     AVFormatContext **input_files,
-                     int nb_input_files,
-                     AVStreamMap *stream_maps, int nb_stream_maps)
+static int av_transcode(AVFormatContext **output_files,
+                        int nb_output_files,
+                        AVFormatContext **input_files,
+                        int nb_input_files,
+                        AVStreamMap *stream_maps, int nb_stream_maps)
 {
     int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
     AVFormatContext *is, *os;
@@ -2063,8 +2072,6 @@ static int av_encode(AVFormatContext **output_files,
                 (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
                 char logfilename[1024];
                 FILE *f;
-                int size;
-                char *logbuffer;
 
                 snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
                          pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
@@ -2077,23 +2084,12 @@ static int av_encode(AVFormatContext **output_files,
                     }
                     ost->logfile = f;
                 } else {
-                    /* read the log file */
-                    f = fopen(logfilename, "r");
-                    if (!f) {
-                        fprintf(stderr, "Cannot read log file '%s' for pass-2 encoding: %s\n", logfilename, strerror(errno));
-                        av_exit(1);
-                    }
-                    fseek(f, 0, SEEK_END);
-                    size = ftell(f);
-                    fseek(f, 0, SEEK_SET);
-                    logbuffer = av_malloc(size + 1);
-                    if (!logbuffer) {
-                        fprintf(stderr, "Could not allocate log buffer\n");
+                    char  *logbuffer;
+                    size_t logbuffer_size;
+                    if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
+                        fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
                         av_exit(1);
                     }
-                    size = fread(logbuffer, 1, size, f);
-                    fclose(f);
-                    logbuffer[size] = '\0';
                     codec->stats_in = logbuffer;
                 }
             }
@@ -2992,7 +2988,7 @@ static void opt_input_file(const char *filename)
             }else{
                 found=1;
                 for(j=0; j<p->nb_stream_indexes; j++){
-                    ic->streams[p->stream_index[j]]->discard= 0;
+                    ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT;
                 }
             }
         }
@@ -4119,8 +4115,8 @@ int main(int argc, char **argv)
     }
 
     ti = getutime();
-    if (av_encode(output_files, nb_output_files, input_files, nb_input_files,
-                  stream_maps, nb_stream_maps) < 0)
+    if (av_transcode(output_files, nb_output_files, input_files, nb_input_files,
+                     stream_maps, nb_stream_maps) < 0)
         av_exit(1);
     ti = getutime() - ti;
     if (do_benchmark) {