@ -55,14 +55,12 @@
# include "libavformat/ffm.h" // not public API
# if CONFIG_AVFILTER
# include "libavfilter / avcodec.h"
# include "libavfilter / avfilter.h"
# include "libavfilter / avfiltergraph.h"
# include "libavfilter / buffersink.h"
# include "libavfilter / buffersrc.h"
# include "libavfilter / vsrc_buffer.h"
# endif
# if HAVE_SYS_RESOURCE_H
# include <sys/types.h>
@ -245,8 +243,6 @@ typedef struct OutputStream {
/* video only */
int video_resample ;
AVFrame resample_frame ; /* temporary frame for image resampling */
struct SwsContext * img_resample_ctx ; /* for image resampling */
int resample_height ;
int resample_width ;
int resample_pix_fmt ;
@ -274,13 +270,11 @@ typedef struct OutputStream {
SwrContext * swr ;
# if CONFIG_AVFILTER
AVFilterContext * output_video_filter ;
AVFilterContext * input_video_filter ;
AVFilterBufferRef * picref ;
char * avfilter ;
AVFilterGraph * graph ;
# endif
int64_t sws_flags ;
AVDictionary * opts ;
@ -405,10 +399,8 @@ typedef struct OptionsContext {
int nb_presets ;
SpecifierOpt * copy_initial_nonkeyframes ;
int nb_copy_initial_nonkeyframes ;
# if CONFIG_AVFILTER
SpecifierOpt * filters ;
int nb_filters ;
# endif
} OptionsContext ;
# define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
@ -597,8 +589,6 @@ static void filter_release_buffer(AVFilterBuffer *fb)
unref_buffer ( buf - > ist , buf ) ;
}
# if CONFIG_AVFILTER
static int configure_video_filters ( InputStream * ist , OutputStream * ost )
{
AVFilterContext * last_filter , * filter ;
@ -693,7 +683,6 @@ static int configure_video_filters(InputStream *ist, OutputStream *ost)
return 0 ;
}
# endif /* CONFIG_AVFILTER */
static void term_exit ( void )
{
@ -863,9 +852,7 @@ void av_noreturn exit_program(int ret)
av_freep ( & async_buf ) ;
allocated_async_buf_size = 0 ;
# if CONFIG_AVFILTER
avfilter_uninit ( ) ;
# endif
avformat_network_deinit ( ) ;
if ( received_sigterm ) {
@ -1439,65 +1426,6 @@ static void do_subtitle_out(AVFormatContext *s,
}
}
static void do_video_resample ( OutputStream * ost ,
InputStream * ist ,
AVFrame * in_picture ,
AVFrame * * out_picture )
{
# if CONFIG_AVFILTER
* out_picture = in_picture ;
# else
AVCodecContext * dec = ist - > st - > codec ;
AVCodecContext * enc = ost - > st - > codec ;
int resample_changed = ost - > resample_width ! = in_picture - > width | |
ost - > resample_height ! = in_picture - > height | |
ost - > resample_pix_fmt ! = in_picture - > format ;
* out_picture = in_picture ;
if ( resample_changed ) {
av_log ( NULL , AV_LOG_INFO ,
" Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s / frm size:%dx%d fmt:%s \n " ,
ist - > file_index , ist - > st - > index ,
ost - > resample_width , ost - > resample_height , av_get_pix_fmt_name ( ost - > resample_pix_fmt ) ,
dec - > width , dec - > height , av_get_pix_fmt_name ( dec - > pix_fmt ) ,
in_picture - > width , in_picture - > height , av_get_pix_fmt_name ( in_picture - > format ) ) ;
ost - > resample_width = in_picture - > width ;
ost - > resample_height = in_picture - > height ;
ost - > resample_pix_fmt = in_picture - > format ;
}
ost - > video_resample = in_picture - > width ! = enc - > width | |
in_picture - > height ! = enc - > height | |
in_picture - > format ! = enc - > pix_fmt ;
if ( ost - > video_resample ) {
* out_picture = & ost - > resample_frame ;
if ( ! ost - > img_resample_ctx | | resample_changed ) {
/* initialize the destination picture */
if ( ! ost - > resample_frame . data [ 0 ] ) {
avcodec_get_frame_defaults ( & ost - > resample_frame ) ;
if ( avpicture_alloc ( ( AVPicture * ) & ost - > resample_frame , enc - > pix_fmt ,
enc - > width , enc - > height ) ) {
av_log ( NULL , AV_LOG_FATAL , " Cannot allocate temp picture, check pix fmt \n " ) ;
exit_program ( 1 ) ;
}
}
/* initialize a new scaler context */
sws_freeContext ( ost - > img_resample_ctx ) ;
ost - > img_resample_ctx = sws_getContext ( in_picture - > width , in_picture - > height , in_picture - > format ,
enc - > width , enc - > height , enc - > pix_fmt ,
ost - > sws_flags , NULL , NULL , NULL ) ;
if ( ost - > img_resample_ctx = = NULL ) {
av_log ( NULL , AV_LOG_FATAL , " Cannot get resampling context \n " ) ;
exit_program ( 1 ) ;
}
}
sws_scale ( ost - > img_resample_ctx , in_picture - > data , in_picture - > linesize ,
0 , ost - > resample_height , ( * out_picture ) - > data , ( * out_picture ) - > linesize ) ;
}
# endif
}
static double psnr ( double d )
{
return - 10.0 * log ( d ) / log ( 10.0 ) ;
@ -1545,7 +1473,6 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
InputStream * ist , AVFrame * in_picture )
{
int nb_frames , i , ret , format_video_sync ;
AVFrame * final_picture ;
AVCodecContext * enc ;
double sync_ipts , delta ;
double duration = 0 ;
@ -1607,8 +1534,6 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
av_log ( NULL , AV_LOG_VERBOSE , " *** %d dup! \n " , nb_frames - 1 ) ;
}
do_video_resample ( ost , ist , in_picture , & final_picture ) ;
/* duplicates frame if needed */
for ( i = 0 ; i < nb_frames ; i + + ) {
AVPacket pkt ;
@ -1623,7 +1548,7 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
method . */
enc - > coded_frame - > interlaced_frame = in_picture - > interlaced_frame ;
enc - > coded_frame - > top_field_first = in_picture - > top_field_first ;
pkt . data = ( uint8_t * ) f inal _picture;
pkt . data = ( uint8_t * ) in_picture ;
pkt . size = sizeof ( AVPicture ) ;
pkt . pts = av_rescale_q ( ost - > sync_opts , enc - > time_base , ost - > st - > time_base ) ;
pkt . flags | = AV_PKT_FLAG_KEY ;
@ -1633,7 +1558,7 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
int got_packet ;
AVFrame big_picture ;
big_picture = * f inal _picture;
big_picture = * in_picture ;
/* better than nothing: use input picture interlaced
settings */
big_picture . interlaced_frame = in_picture - > interlaced_frame ;
@ -2157,7 +2082,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
pre_process_video_frame ( ist , ( AVPicture * ) decoded_frame , & buffer_to_free ) ;
# if CONFIG_AVFILTER
frame_sample_aspect = av_opt_ptr ( avcodec_get_frame_class ( ) , decoded_frame , " sample_aspect_ratio " ) ;
for ( i = 0 ; i < nb_output_streams ; i + + ) {
OutputStream * ost = ost = & output_streams [ i ] ;
@ -2189,7 +2113,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
}
}
}
# endif
rate_emu_sleep ( ist ) ;
@ -2199,7 +2122,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
if ( ! check_output_constraints ( ist , ost ) | | ! ost - > encoding_needed )
continue ;
# if CONFIG_AVFILTER
while ( av_buffersink_poll_frame ( ost - > output_video_filter ) ) {
AVRational ist_pts_tb = ost - > output_video_filter - > inputs [ 0 ] - > time_base ;
AVFrame * filtered_frame ;
@ -2222,9 +2144,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
cont :
avfilter_unref_buffer ( ost - > picref ) ;
}
# else
do_video_out ( output_files [ ost - > file_index ] . ctx , ost , ist , decoded_frame ) ;
# endif
}
fail :
@ -2679,12 +2598,10 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
AV_TIME_BASE_Q ,
codec - > time_base ) ;
# if CONFIG_AVFILTER
if ( configure_video_filters ( ist , ost ) ) {
av_log ( NULL , AV_LOG_FATAL , " Error opening filters! \n " ) ;
exit_program ( 1 ) ;
}
# endif
break ;
case AVMEDIA_TYPE_SUBTITLE :
codec - > time_base = ( AVRational ) { 1 , 1000 } ;
@ -2924,7 +2841,6 @@ static int transcode(OutputFile *output_files, int nb_output_files,
do_pkt_dump = 1 ;
av_log_set_level ( AV_LOG_DEBUG ) ;
}
# if CONFIG_AVFILTER
if ( key = = ' c ' | | key = = ' C ' ) {
char buf [ 4096 ] , target [ 64 ] , command [ 256 ] , arg [ 256 ] = { 0 } ;
double time ;
@ -2957,7 +2873,6 @@ static int transcode(OutputFile *output_files, int nb_output_files,
" only %d given in string '%s' \n " , n , buf ) ;
}
}
# endif
if ( key = = ' d ' | | key = = ' D ' ) {
int debug = 0 ;
if ( key = = ' D ' ) {
@ -3170,9 +3085,7 @@ static int transcode(OutputFile *output_files, int nb_output_files,
av_freep ( & ost - > st - > codec - > stats_in ) ;
avcodec_close ( ost - > st - > codec ) ;
}
# if CONFIG_AVFILTER
avfilter_graph_free ( & ost - > graph ) ;
# endif
}
/* close each decoder */
@ -3202,10 +3115,7 @@ static int transcode(OutputFile *output_files, int nb_output_files,
av_fifo_free ( ost - > fifo ) ; /* works even if fifo is not
initialized but set to zero */
av_freep ( & ost - > st - > codec - > subtitle_header ) ;
av_free ( ost - > resample_frame . data [ 0 ] ) ;
av_free ( ost - > forced_kf_pts ) ;
if ( ost - > video_resample )
sws_freeContext ( ost - > img_resample_ctx ) ;
swr_free ( & ost - > swr ) ;
av_dict_free ( & ost - > opts ) ;
}
@ -4141,11 +4051,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
ost - > top_field_first = - 1 ;
MATCH_PER_STREAM_OPT ( top_field_first , i , ost - > top_field_first , oc , st ) ;
# if CONFIG_AVFILTER
MATCH_PER_STREAM_OPT ( filters , str , filters , oc , st ) ;
if ( filters )
ost - > avfilter = av_strdup ( filters ) ;
# endif
} else {
MATCH_PER_STREAM_OPT ( copy_initial_nonkeyframes , i , ost - > copy_initial_nonkeyframes , oc , st ) ;
}
@ -5080,9 +4988,7 @@ static const OptionDef options[] = {
{ " q " , HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC , { . off = OFFSET ( qscale ) } , " use fixed quality scale (VBR) " , " q " } ,
{ " qscale " , HAS_ARG | OPT_EXPERT | OPT_FUNC2 , { ( void * ) opt_qscale } , " use fixed quality scale (VBR) " , " q " } ,
{ " profile " , HAS_ARG | OPT_EXPERT | OPT_FUNC2 , { ( void * ) opt_profile } , " set profile " , " profile " } ,
# if CONFIG_AVFILTER
{ " filter " , HAS_ARG | OPT_STRING | OPT_SPEC , { . off = OFFSET ( filters ) } , " set stream filterchain " , " filter_list " } ,
# endif
{ " stats " , OPT_BOOL , { & print_stats } , " print progress report during encoding " , } ,
{ " attach " , HAS_ARG | OPT_FUNC2 , { ( void * ) opt_attach } , " add an attachment to the output file " , " filename " } ,
{ " dump_attachment " , HAS_ARG | OPT_STRING | OPT_SPEC , { . off = OFFSET ( dump_attachment ) } , " extract an attachment into a file " , " filename " } ,
@ -5119,9 +5025,7 @@ static const OptionDef options[] = {
{ " psnr " , OPT_BOOL | OPT_EXPERT | OPT_VIDEO , { ( void * ) & do_psnr } , " calculate PSNR of compressed frames " } ,
{ " vstats " , OPT_EXPERT | OPT_VIDEO , { ( void * ) & opt_vstats } , " dump video coding statistics to file " } ,
{ " vstats_file " , HAS_ARG | OPT_EXPERT | OPT_VIDEO , { ( void * ) opt_vstats_file } , " dump video coding statistics to file " , " file " } ,
# if CONFIG_AVFILTER
{ " vf " , HAS_ARG | OPT_VIDEO | OPT_FUNC2 , { ( void * ) opt_video_filters } , " video filters " , " filter list " } ,
# endif
{ " intra_matrix " , HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC , { . off = OFFSET ( intra_matrices ) } , " specify intra matrix coeffs " , " matrix " } ,
{ " inter_matrix " , HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC , { . off = OFFSET ( inter_matrices ) } , " specify inter matrix coeffs " , " matrix " } ,
{ " top " , HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_INT | OPT_SPEC , { . off = OFFSET ( top_field_first ) } , " top=1/bottom=0/auto=-1 field first " , " " } ,
@ -5196,9 +5100,7 @@ int main(int argc, char **argv)
# if CONFIG_AVDEVICE
avdevice_register_all ( ) ;
# endif
# if CONFIG_AVFILTER
avfilter_register_all ( ) ;
# endif
av_register_all ( ) ;
avformat_network_init ( ) ;