#include "config.h"#include <ctype.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <errno.h>#include <signal.h>#include <limits.h>#include "libavformat/avformat.h"#include "libavdevice/avdevice.h"#include "libswscale/swscale.h"#include "libavformat/framehook.h"#include "libavcodec/opt.h"#include "libavutil/fifo.h"#include "libavutil/avstring.h"#include "libavformat/os_support.h"#include <time.h>#include "cmdutils.h"#include <assert.h>Go to the source code of this file.
Data Structures | |
| struct | AVStreamMap |
| struct | AVMetaDataMap |
| struct | AVOutputStream |
| struct | AVInputStream |
| struct | AVInputFile |
Defines | |
| #define | MAX_FILES 20 |
| #define | QSCALE_NONE -99999 |
| #define | DEFAULT_PASS_LOGFILENAME "ffmpeg2pass" |
| #define | MAX_AUDIO_PACKET_SIZE (128 * 1024) |
| #define | AV_DELAY_MAX 0.100 |
| #define | SCALEBITS 10 |
| #define | ONE_HALF (1 << (SCALEBITS - 1)) |
| #define | FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) |
| #define | RGB_TO_Y(r, g, b) |
| #define | RGB_TO_U(r1, g1, b1, shift) |
| #define | RGB_TO_V(r1, g1, b1, shift) |
Functions | |
| static void | term_exit (void) |
| static void | sigterm_handler (int sig) |
| static void | term_init (void) |
| static int | read_key (void) |
| static int | decode_interrupt_cb (void) |
| static int | av_exit (int ret) |
| static int | read_ffserver_streams (AVFormatContext *s, const char *filename) |
| static double | get_sync_ipts (const AVOutputStream *ost) |
| static void | write_frame (AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc) |
| static void | do_audio_out (AVFormatContext *s, AVOutputStream *ost, AVInputStream *ist, unsigned char *buf, int size) |
| static void | pre_process_video_frame (AVInputStream *ist, AVPicture *picture, void **bufp) |
| static void | do_subtitle_out (AVFormatContext *s, AVOutputStream *ost, AVInputStream *ist, AVSubtitle *sub, int64_t pts) |
| static void | do_video_out (AVFormatContext *s, AVOutputStream *ost, AVInputStream *ist, AVFrame *in_picture, int *frame_size) |
| static double | psnr (double d) |
| static void | do_video_stats (AVFormatContext *os, AVOutputStream *ost, int frame_size) |
| static void | print_report (AVFormatContext **output_files, AVOutputStream **ost_table, int nb_ostreams, int is_last_report) |
| static int | output_packet (AVInputStream *ist, int ist_index, AVOutputStream **ost_table, int nb_ostreams, const AVPacket *pkt) |
| static void | print_sdp (AVFormatContext **avc, int n) |
| static int | stream_index_from_inputs (AVFormatContext **input_files, int nb_input_files, AVInputFile *file_table, AVInputStream **ist_table, enum CodecType type, int programid) |
| 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 void | opt_format (const char *arg) |
| static int | opt_default (const char *opt, const char *arg) |
| static void | opt_video_rc_override_string (const char *arg) |
| static int | opt_me_threshold (const char *opt, const char *arg) |
| static int | opt_verbose (const char *opt, const char *arg) |
| static void | opt_frame_rate (const char *arg) |
| static int | opt_bitrate (const char *opt, const char *arg) |
| static void | opt_frame_crop_top (const char *arg) |
| static void | opt_frame_crop_bottom (const char *arg) |
| static void | opt_frame_crop_left (const char *arg) |
| static void | opt_frame_crop_right (const char *arg) |
| static void | opt_frame_size (const char *arg) |
| static void | opt_pad_color (const char *arg) |
| static void | opt_frame_pad_top (const char *arg) |
| static void | opt_frame_pad_bottom (const char *arg) |
| static void | opt_frame_pad_left (const char *arg) |
| static void | opt_frame_pad_right (const char *arg) |
| static void | list_pix_fmts (void) |
| static void | opt_frame_pix_fmt (const char *arg) |
| static void | opt_frame_aspect_ratio (const char *arg) |
| static void | opt_qscale (const char *arg) |
| static void | opt_top_field_first (const char *arg) |
| static int | opt_thread_count (const char *opt, const char *arg) |
| static int | opt_audio_rate (const char *opt, const char *arg) |
| static int | opt_audio_channels (const char *opt, const char *arg) |
| static void | opt_video_channel (const char *arg) |
| static void | opt_video_standard (const char *arg) |
| static void | opt_codec (int *pstream_copy, char **pcodec_name, int codec_type, const char *arg) |
| static void | opt_audio_codec (const char *arg) |
| static void | opt_audio_tag (const char *arg) |
| static void | opt_video_tag (const char *arg) |
| static void | opt_video_codec (const char *arg) |
| static void | opt_subtitle_codec (const char *arg) |
| static void | opt_map (const char *arg) |
| static void | opt_map_meta_data (const char *arg) |
| static void | opt_input_ts_scale (const char *arg) |
| static int | opt_recording_time (const char *opt, const char *arg) |
| static int | opt_start_time (const char *opt, const char *arg) |
| static int | opt_rec_timestamp (const char *opt, const char *arg) |
| static int | opt_input_ts_offset (const char *opt, const char *arg) |
| static enum CodecID | find_codec_or_die (const char *name, int type, int encoder) |
| static void | set_context_opts (void *ctx, void *opts_ctx, int flags) |
| static void | opt_input_file (const char *filename) |
| static void | check_audio_video_sub_inputs (int *has_video_ptr, int *has_audio_ptr, int *has_subtitle_ptr) |
| static void | new_video_stream (AVFormatContext *oc) |
| static void | new_audio_stream (AVFormatContext *oc) |
| static void | new_subtitle_stream (AVFormatContext *oc) |
| static void | opt_new_audio_stream (void) |
| static void | opt_new_video_stream (void) |
| static void | opt_new_subtitle_stream (void) |
| static void | opt_output_file (const char *filename) |
| static void | opt_pass (const char *pass_str) |
| static int64_t | getutime (void) |
| static void | parse_matrix_coeffs (uint16_t *dest, const char *str) |
| static void | opt_inter_matrix (const char *arg) |
| static void | opt_intra_matrix (const char *arg) |
| static void | log_callback_help (void *ptr, int level, const char *fmt, va_list vl) |
| static void | show_help (void) |
| static void | opt_target (const char *arg) |
| static void | opt_vstats_file (const char *arg) |
| static void | opt_vstats (void) |
| static int | opt_bsf (const char *opt, const char *arg) |
| static int | opt_preset (const char *opt, const char *arg) |
| int | main (int argc, char **argv) |
Variables | |
| const char | program_name [] = "FFmpeg" |
| const int | program_birth_year = 2000 |
| static const OptionDef | options [] |
| static AVFormatContext * | input_files [MAX_FILES] |
| static int64_t | input_files_ts_offset [MAX_FILES] |
| static double | input_files_ts_scale [MAX_FILES][MAX_STREAMS] |
| static int | nb_input_files = 0 |
| static AVFormatContext * | output_files [MAX_FILES] |
| static int | nb_output_files = 0 |
| static AVStreamMap | stream_maps [MAX_FILES] |
| static int | nb_stream_maps |
| static AVMetaDataMap | meta_data_maps [MAX_FILES] |
| static int | nb_meta_data_maps |
| static AVInputFormat * | file_iformat |
| static AVOutputFormat * | file_oformat |
| static int | frame_width = 0 |
| static int | frame_height = 0 |
| static float | frame_aspect_ratio = 0 |
| static enum PixelFormat | frame_pix_fmt = PIX_FMT_NONE |
| static int | frame_padtop = 0 |
| static int | frame_padbottom = 0 |
| static int | frame_padleft = 0 |
| static int | frame_padright = 0 |
| static int | padcolor [3] = {16,128,128} |
| static int | frame_topBand = 0 |
| static int | frame_bottomBand = 0 |
| static int | frame_leftBand = 0 |
| static int | frame_rightBand = 0 |
| static int | max_frames [4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX} |
| static AVRational | frame_rate |
| static float | video_qscale = 0 |
| static uint16_t * | intra_matrix = NULL |
| static uint16_t * | inter_matrix = NULL |
| static const char * | video_rc_override_string = NULL |
| static int | video_disable = 0 |
| static int | video_discard = 0 |
| static char * | video_codec_name = NULL |
| static int | video_codec_tag = 0 |
| static int | same_quality = 0 |
| static int | do_deinterlace = 0 |
| static int | top_field_first = -1 |
| static int | me_threshold = 0 |
| static int | intra_dc_precision = 8 |
| static int | loop_input = 0 |
| static int | loop_output = AVFMT_NOOUTPUTLOOP |
| static int | qp_hist = 0 |
| static int | intra_only = 0 |
| static int | audio_sample_rate = 44100 |
| static float | audio_qscale = QSCALE_NONE |
| static int | audio_disable = 0 |
| static int | audio_channels = 1 |
| static char * | audio_codec_name = NULL |
| static int | audio_codec_tag = 0 |
| static char * | audio_language = NULL |
| static int | subtitle_disable = 0 |
| static char * | subtitle_codec_name = NULL |
| static char * | subtitle_language = NULL |
| static float | mux_preload = 0.5 |
| static float | mux_max_delay = 0.7 |
| static int64_t | recording_time = INT64_MAX |
| static int64_t | start_time = 0 |
| static int64_t | rec_timestamp = 0 |
| static int64_t | input_ts_offset = 0 |
| static int | file_overwrite = 0 |
| static char * | str_title = NULL |
| static char * | str_author = NULL |
| static char * | str_copyright = NULL |
| static char * | str_comment = NULL |
| static char * | str_genre = NULL |
| static char * | str_album = NULL |
| static int | do_benchmark = 0 |
| static int | do_hex_dump = 0 |
| static int | do_pkt_dump = 0 |
| static int | do_psnr = 0 |
| static int | do_pass = 0 |
| static char * | pass_logfilename = NULL |
| static int | audio_stream_copy = 0 |
| static int | video_stream_copy = 0 |
| static int | subtitle_stream_copy = 0 |
| static int | video_sync_method = -1 |
| static int | audio_sync_method = 0 |
| static float | audio_drift_threshold = 0.1 |
| static int | copy_ts = 0 |
| static int | opt_shortest = 0 |
| static int | video_global_header = 0 |
| static char * | vstats_filename |
| static FILE * | vstats_file |
| static int | opt_programid = 0 |
| static int | rate_emu = 0 |
| static int | video_channel = 0 |
| static char * | video_standard |
| static int | audio_volume = 256 |
| static int | using_stdin = 0 |
| static int | using_vhook = 0 |
| static int | verbose = 1 |
| static int | thread_count = 1 |
| static int | q_pressed = 0 |
| static int64_t | video_size = 0 |
| static int64_t | audio_size = 0 |
| static int64_t | extra_size = 0 |
| static int | nb_frames_dup = 0 |
| static int | nb_frames_drop = 0 |
| static int | input_sync |
| static uint64_t | limit_filesize = 0 |
| static int | pgmyuv_compatibility_hack = 0 |
| static float | dts_delta_threshold = 10 |
| static unsigned int | sws_flags = SWS_BICUBIC |
| static const char ** | opt_names |
| static int | opt_name_count |
| static AVCodecContext * | avctx_opts [CODEC_TYPE_NB] |
| static AVFormatContext * | avformat_opts |
| static struct SwsContext * | sws_opts |
| static int64_t | timer_start |
| static AVBitStreamFilterContext * | video_bitstream_filters = NULL |
| static AVBitStreamFilterContext * | audio_bitstream_filters = NULL |
| static AVBitStreamFilterContext * | subtitle_bitstream_filters = NULL |
| static AVBitStreamFilterContext * | bitstream_filters [MAX_FILES][MAX_STREAMS] |
| static volatile sig_atomic_t | received_sigterm = 0 |
| static int | bit_buffer_size = 1024*256 |
| static uint8_t * | bit_buffer = NULL |
| static const OptionDef | options [] |
| #define FIX | ( | x | ) | ((int) ((x) * (1<<SCALEBITS) + 0.5)) |
Definition at line 2372 of file ffmpeg.c.
Referenced by C_JPEG_TO_CCIR(), idct32(), and rgb24_to_yuv420p().
| #define MAX_AUDIO_PACKET_SIZE (128 * 1024) |
| #define ONE_HALF (1 << (SCALEBITS - 1)) |
| #define QSCALE_NONE -99999 |
| #define RGB_TO_U | ( | r1, | |||
| g1, | |||||
| b1, | |||||
| shift | ) |
| #define RGB_TO_V | ( | r1, | |||
| g1, | |||||
| b1, | |||||
| shift | ) |
| #define RGB_TO_Y | ( | r, | |||
| g, | |||||
| b | ) |
| #define SCALEBITS 10 |
| 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] |
Definition at line 1483 of file ffmpeg.c.
References av_gettime(), av_mallocz(), AVStream::codec, AVInputStream::discard, AVInputStream::file_index, AVInputStream::frame, AVInputStream::index, input_files, AVInputFile::ist_index, AVFormatContext::nb_streams, AVInputFile::nb_streams, NULL, AVCodecContext::rate_emu, AVInputStream::st, AVInputStream::start, and AVFormatContext::streams.
Referenced by main().
01488 { 01489 int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; 01490 AVFormatContext *is, *os; 01491 AVCodecContext *codec, *icodec; 01492 AVOutputStream *ost, **ost_table = NULL; 01493 AVInputStream *ist, **ist_table = NULL; 01494 AVInputFile *file_table; 01495 int key; 01496 int want_sdp = 1; 01497 01498 file_table= av_mallocz(nb_input_files * sizeof(AVInputFile)); 01499 if (!file_table) 01500 goto fail; 01501 01502 /* input stream init */ 01503 j = 0; 01504 for(i=0;i<nb_input_files;i++) { 01505 is = input_files[i]; 01506 file_table[i].ist_index = j; 01507 file_table[i].nb_streams = is->nb_streams; 01508 j += is->nb_streams; 01509 } 01510 nb_istreams = j; 01511 01512 ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *)); 01513 if (!ist_table) 01514 goto fail; 01515 01516 for(i=0;i<nb_istreams;i++) { 01517 ist = av_mallocz(sizeof(AVInputStream)); 01518 if (!ist) 01519 goto fail; 01520 ist_table[i] = ist; 01521 } 01522 j = 0; 01523 for(i=0;i<nb_input_files;i++) { 01524 is = input_files[i]; 01525 for(k=0;k<is->nb_streams;k++) { 01526 ist = ist_table[j++]; 01527 ist->st = is->streams[k]; 01528 ist->file_index = i; 01529 ist->index = k; 01530 ist->discard = 1; /* the stream is discarded by default 01531 (changed later) */ 01532 01533 if (ist->st->codec->rate_emu) { 01534 ist->start = av_gettime(); 01535 ist->frame = 0; 01536 } 01537 } 01538 } 01539 01540 /* output stream init */ 01541 nb_ostreams = 0; 01542 for(i=0;i<nb_output_files;i++) { 01543 os = output_files[i]; 01544 if (!os->nb_streams) { 01545 fprintf(stderr, "Output file does not contain any stream\n"); 01546 av_exit(1); 01547 } 01548 nb_ostreams += os->nb_streams; 01549 } 01550 if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { 01551 fprintf(stderr, "Number of stream maps must match number of output streams\n"); 01552 av_exit(1); 01553 } 01554 01555 /* Sanity check the mapping args -- do the input files & streams exist? */ 01556 for(i=0;i<nb_stream_maps;i++) { 01557 int fi = stream_maps[i].file_index; 01558 int si = stream_maps[i].stream_index; 01559 01560 if (fi < 0 || fi > nb_input_files - 1 || 01561 si < 0 || si > file_table[fi].nb_streams - 1) { 01562 fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); 01563 av_exit(1); 01564 } 01565 fi = stream_maps[i].sync_file_index; 01566 si = stream_maps[i].sync_stream_index; 01567 if (fi < 0 || fi > nb_input_files - 1 || 01568 si < 0 || si > file_table[fi].nb_streams - 1) { 01569 fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); 01570 av_exit(1); 01571 } 01572 } 01573 01574 ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams); 01575 if (!ost_table) 01576 goto fail; 01577 for(i=0;i<nb_ostreams;i++) { 01578 ost = av_mallocz(sizeof(AVOutputStream)); 01579 if (!ost) 01580 goto fail; 01581 ost_table[i] = ost; 01582 } 01583 01584 n = 0; 01585 for(k=0;k<nb_output_files;k++) { 01586 os = output_files[k]; 01587 for(i=0;i<os->nb_streams;i++) { 01588 int found; 01589 ost = ost_table[n++]; 01590 ost->file_index = k; 01591 ost->index = i; 01592 ost->st = os->streams[i]; 01593 if (nb_stream_maps > 0) { 01594 ost->source_index = file_table[stream_maps[n-1].file_index].ist_index + 01595 stream_maps[n-1].stream_index; 01596 01597 /* Sanity check that the stream types match */ 01598 if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) { 01599 fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", 01600 stream_maps[n-1].file_index, stream_maps[n-1].stream_index, 01601 ost->file_index, ost->index); 01602 av_exit(1); 01603 } 01604 01605 } else { 01606 if(opt_programid) { 01607 found = 0; 01608 j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid); 01609 if(j != -1) { 01610 ost->source_index = j; 01611 found = 1; 01612 } 01613 } else { 01614 /* get corresponding input stream index : we select the first one with the right type */ 01615 found = 0; 01616 for(j=0;j<nb_istreams;j++) { 01617 ist = ist_table[j]; 01618 if (ist->discard && 01619 ist->st->codec->codec_type == ost->st->codec->codec_type) { 01620 ost->source_index = j; 01621 found = 1; 01622 break; 01623 } 01624 } 01625 } 01626 01627 if (!found) { 01628 if(! opt_programid) { 01629 /* try again and reuse existing stream */ 01630 for(j=0;j<nb_istreams;j++) { 01631 ist = ist_table[j]; 01632 if (ist->st->codec->codec_type == ost->st->codec->codec_type) { 01633 ost->source_index = j; 01634 found = 1; 01635 } 01636 } 01637 } 01638 if (!found) { 01639 int i= ost->file_index; 01640 dump_format(output_files[i], i, output_files[i]->filename, 1); 01641 fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", 01642 ost->file_index, ost->index); 01643 av_exit(1); 01644 } 01645 } 01646 } 01647 ist = ist_table[ost->source_index]; 01648 ist->discard = 0; 01649 ost->sync_ist = (nb_stream_maps > 0) ? 01650 ist_table[file_table[stream_maps[n-1].sync_file_index].ist_index + 01651 stream_maps[n-1].sync_stream_index] : ist; 01652 } 01653 } 01654 01655 /* for each output stream, we compute the right encoding parameters */ 01656 for(i=0;i<nb_ostreams;i++) { 01657 ost = ost_table[i]; 01658 os = output_files[ost->file_index]; 01659 ist = ist_table[ost->source_index]; 01660 01661 codec = ost->st->codec; 01662 icodec = ist->st->codec; 01663 01664 if (!ost->st->language[0]) 01665 av_strlcpy(ost->st->language, ist->st->language, 01666 sizeof(ost->st->language)); 01667 01668 ost->st->disposition = ist->st->disposition; 01669 01670 if (ost->st->stream_copy) { 01671 /* if stream_copy is selected, no need to decode or encode */ 01672 codec->codec_id = icodec->codec_id; 01673 codec->codec_type = icodec->codec_type; 01674 01675 if(!codec->codec_tag){ 01676 if( !os->oformat->codec_tag 01677 || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) > 0 01678 || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) 01679 codec->codec_tag = icodec->codec_tag; 01680 } 01681 01682 codec->bit_rate = icodec->bit_rate; 01683 codec->extradata= icodec->extradata; 01684 codec->extradata_size= icodec->extradata_size; 01685 if(av_q2d(icodec->time_base) > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000) 01686 codec->time_base = icodec->time_base; 01687 else 01688 codec->time_base = ist->st->time_base; 01689 switch(codec->codec_type) { 01690 case CODEC_TYPE_AUDIO: 01691 if(audio_volume != 256) { 01692 fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); 01693 av_exit(1); 01694 } 01695 codec->sample_rate = icodec->sample_rate; 01696 codec->channels = icodec->channels; 01697 codec->frame_size = icodec->frame_size; 01698 codec->block_align= icodec->block_align; 01699 if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) 01700 codec->block_align= 0; 01701 if(codec->codec_id == CODEC_ID_AC3) 01702 codec->block_align= 0; 01703 break; 01704 case CODEC_TYPE_VIDEO: 01705 if(using_vhook) { 01706 fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\n"); 01707 av_exit(1); 01708 } 01709 codec->pix_fmt = icodec->pix_fmt; 01710 codec->width = icodec->width; 01711 codec->height = icodec->height; 01712 codec->has_b_frames = icodec->has_b_frames; 01713 break; 01714 case CODEC_TYPE_SUBTITLE: 01715 break; 01716 default: 01717 abort(); 01718 } 01719 } else { 01720 switch(codec->codec_type) { 01721 case CODEC_TYPE_AUDIO: 01722 if (av_fifo_init(&ost->fifo, 1024)) 01723 goto fail; 01724 ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; 01725 icodec->request_channels = codec->channels; 01726 ist->decoding_needed = 1; 01727 ost->encoding_needed = 1; 01728 break; 01729 case CODEC_TYPE_VIDEO: 01730 ost->video_crop = ((frame_leftBand + frame_rightBand + frame_topBand + frame_bottomBand) != 0); 01731 ost->video_pad = ((frame_padleft + frame_padright + frame_padtop + frame_padbottom) != 0); 01732 ost->video_resample = ((codec->width != icodec->width - 01733 (frame_leftBand + frame_rightBand) + 01734 (frame_padleft + frame_padright)) || 01735 (codec->height != icodec->height - 01736 (frame_topBand + frame_bottomBand) + 01737 (frame_padtop + frame_padbottom)) || 01738 (codec->pix_fmt != icodec->pix_fmt)); 01739 if (ost->video_crop) { 01740 ost->topBand = frame_topBand; 01741 ost->leftBand = frame_leftBand; 01742 } 01743 if (ost->video_pad) { 01744 ost->padtop = frame_padtop; 01745 ost->padleft = frame_padleft; 01746 ost->padbottom = frame_padbottom; 01747 ost->padright = frame_padright; 01748 if (!ost->video_resample) { 01749 avcodec_get_frame_defaults(&ost->pict_tmp); 01750 if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, 01751 codec->width, codec->height)) 01752 goto fail; 01753 } 01754 } 01755 if (ost->video_resample) { 01756 avcodec_get_frame_defaults(&ost->pict_tmp); 01757 if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, 01758 codec->width, codec->height)) { 01759 fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); 01760 av_exit(1); 01761 } 01762 sws_flags = av_get_int(sws_opts, "sws_flags", NULL); 01763 ost->img_resample_ctx = sws_getContext( 01764 icodec->width - (frame_leftBand + frame_rightBand), 01765 icodec->height - (frame_topBand + frame_bottomBand), 01766 icodec->pix_fmt, 01767 codec->width - (frame_padleft + frame_padright), 01768 codec->height - (frame_padtop + frame_padbottom), 01769 codec->pix_fmt, 01770 sws_flags, NULL, NULL, NULL); 01771 if (ost->img_resample_ctx == NULL) { 01772 fprintf(stderr, "Cannot get resampling context\n"); 01773 av_exit(1); 01774 } 01775 ost->resample_height = icodec->height - (frame_topBand + frame_bottomBand); 01776 } 01777 ost->encoding_needed = 1; 01778 ist->decoding_needed = 1; 01779 break; 01780 case CODEC_TYPE_SUBTITLE: 01781 ost->encoding_needed = 1; 01782 ist->decoding_needed = 1; 01783 break; 01784 default: 01785 abort(); 01786 break; 01787 } 01788 /* two pass mode */ 01789 if (ost->encoding_needed && 01790 (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { 01791 char logfilename[1024]; 01792 FILE *f; 01793 int size; 01794 char *logbuffer; 01795 01796 snprintf(logfilename, sizeof(logfilename), "%s-%d.log", 01797 pass_logfilename ? 01798 pass_logfilename : DEFAULT_PASS_LOGFILENAME, i); 01799 if (codec->flags & CODEC_FLAG_PASS1) { 01800 f = fopen(logfilename, "w"); 01801 if (!f) { 01802 perror(logfilename); 01803 av_exit(1); 01804 } 01805 ost->logfile = f; 01806 } else { 01807 /* read the log file */ 01808 f = fopen(logfilename, "r"); 01809 if (!f) { 01810 perror(logfilename); 01811 av_exit(1); 01812 } 01813 fseek(f, 0, SEEK_END); 01814 size = ftell(f); 01815 fseek(f, 0, SEEK_SET); 01816 logbuffer = av_malloc(size + 1); 01817 if (!logbuffer) { 01818 fprintf(stderr, "Could not allocate log buffer\n"); 01819 av_exit(1); 01820 } 01821 size = fread(logbuffer, 1, size, f); 01822 fclose(f); 01823 logbuffer[size] = '\0'; 01824 codec->stats_in = logbuffer; 01825 } 01826 } 01827 } 01828 if(codec->