FFmpeg Source Code Analysis 2: main function and transcode function (to 2)

Source: Internet
Author: User

Original post address: http://blog.csdn.net/austinblog/article/details/24804455

 

First, we can see from the main function that the key explanation has been annotated. This function is in the FFMPEG. c file. The Code is as follows:

 

Int main (INT argc, char ** argv) {int ret; int64_t Ti; // registers the cleaning callback function register_exit (ffmpeg_cleanup); setvbuf (stderr, null, _ ionbf, 0);/* Win32 runtime needs this */av_log_set_flags (av_log_skip_repeated); parse_loglevel (argc, argv, options); If (argc> 1 &&! Strcmp (argv [1], "-d") {run_as_daemon = 1; av_log_set_callback (log_callback_null); argc --; argv ++;} // register the avcodec_register_all () component (); # If config_avdevice avdevice_register_all (); # endif initialize (); av_register_all (); avformat_network_init (); show_banner (argc, argv, options); term_init (); /* parse options and open all input/output files * // parse parameters and open the input/output file ret = ffmpeg_parse_options (argc, Argv); If (Ret <0) exit_program (1); If (nb_output_files <= 0 & nb_input_files = 0) {show_usage (); av_log (null, av_log_warning, "Use-h to get full help or, even better, run 'man % s' \ n", program_name); exit_program (1 );} /* File Converter/Grab */If (nb_output_files <= 0) {av_log (null, av_log_fatal, "at least one output file must be specified \ n "); exit_program (1);} // If (nb_input_files = 0) {// av_log (null, av_log_fatal, "at least one input file must be specified \ n"); // exit_program (1 ); //} current_time = Ti = getutime (); // audio/video conversion function if (transcode () <0) exit_program (1); Ti = getutime ()-Ti; if (do_benchmark) {printf ("RunTime: utime = % 0.3fs \ n", Ti/1000000.0);} av_log (null, av_log_debug, "%" priu64 "frames successfully decoded, % "priu64" decoding errors \ n ", decode_error_stat [0], de Code_error_stat [1]); If (decode_error_stat [0] + decode_error_stat [1]) * max_error_rate <limit [1]) exit_program (69); exit_program (limit? 255: main_return_code); Return main_return_code ;}

 

Read the transcode function below:

 

Static int transcode (void) {int ret, I; avformatcontext * OS; outputstream * ost; inputstream * IST; int64_t timer_start; // initialize the encoder that opens all output streams, open the decoder of all input streams and write the file headers of all output files. It will be detailed later. Ret = transcode_init (); If (Ret <0) goto fail; If (stdin_interaction) {av_log (null, av_log_info, "press [Q] to stop, [?] For Help \ n ");} timer_start = av_gettime (); # If have_pthreads if (ret = init_input_threads () <0) goto fail; # endif // loop, it does not exit until the system signal is received. While (! Received_sigterm) {int64_t cur_time = av_gettime ();/* If 'q' pressed, exits */If (stdin_interaction) if (check_keyboard_interaction (cur_time) <0) break; /* Check if there's any stream where output is still needed */If (! Need_output () {av_log (null, av_log_verbose, "No more output streams to write to, finishing. \ n "); break;} // specific conversion work, which will be detailed later. Ret = transcode_step (); If (Ret <0) {If (ret = averror_eof | ret = averror (eagain) continue; av_log (null, av_log_error, "Error while filtering. \ n "); break;}/* dump report by using the output first video and audio streams */print_report (0, timer_start, cur_time);} # If have_pthreads free_input_threads (); # endif // After the file is processed, write the remaining data in the buffer to the output file. /* At the end of stream, We must flush the decoder buffers */for (I = 0; I <nb_input_streams; I ++) {ist = input_streams [I]; if (! Input_files [ist-> file_index]-> eof_reached & ist-> decoding_needed) {output_packet (IST, null) ;}} flush_encoders (); term_exit (); /* write the trailer if needed and close file * // write the end of the output file (some do not need ). For (I = 0; I <nb_output_files; I ++) {OS = output_files [I]-> CTX; av_write_trailer (OS );} /* dump report by using the first video and audio streams */print_report (1, timer_start, av_gettime (); // disable all encoders. /* Close Each encoder */for (I = 0; I <nb_output_streams; I ++) {Ost = output_streams [I]; If (Ost-> encoding_needed) {av_freep (& Ost-> St-> codec-> stats_in); avcodec_close (Ost-> St-> codec) ;}// close all decoders. /* Close each decoder */for (I = 0; I <nb_input_streams; I ++) {ist = input_streams [I]; If (IST-> decoding_needed) {avcodec_close (IST-> St-> codec); If (IST-> hwaccel_uninit) ist-> hwaccel_uninit (IST-> St-> codec);}/* finished! */Ret = 0; fail: # If have_pthreads free_input_threads (); # endif if (output_streams) {for (I = 0; I <nb_output_streams; I ++) {Ost = output_streams [I]; If (OST) {If (Ost-> stream_copy) av_freep (& Ost-> St-> codec-> extradata ); if (Ost-> logfile) {fclose (Ost-> logfile); Ost-> logfile = NULL;} av_freep (& Ost-> St-> codec-> subtitle_header ); av_freep (& Ost-> forced_kf_pts); av_freep (& Ost-> apad); av_dict_free (& Ost-> opts); av_dict_free (& Ost-> swr_opts ); av_dict_free (& Ost-> resample_opts) ;}}return ret ;}

 

FFmpeg Source Code Analysis 2: main function and transcode function (to 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.