@@ -676,47 +676,10 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
676676 if (bsfc )
677677 av_packet_split_side_data (pkt );
678678
679- while (bsfc ) {
680- AVPacket new_pkt = * pkt ;
681- AVDictionaryEntry * bsf_arg = av_dict_get (ost -> bsf_args ,
682- bsfc -> filter -> name ,
683- NULL , 0 );
684- int a = av_bitstream_filter_filter (bsfc , avctx ,
685- bsf_arg ? bsf_arg -> value : NULL ,
686- & new_pkt .data , & new_pkt .size ,
687- pkt -> data , pkt -> size ,
688- pkt -> flags & AV_PKT_FLAG_KEY );
689- if (a == 0 && new_pkt .data != pkt -> data ) {
690- uint8_t * t = av_malloc (new_pkt .size + AV_INPUT_BUFFER_PADDING_SIZE ); //the new should be a subset of the old so cannot overflow
691- if (t ) {
692- memcpy (t , new_pkt .data , new_pkt .size );
693- memset (t + new_pkt .size , 0 , AV_INPUT_BUFFER_PADDING_SIZE );
694- new_pkt .data = t ;
695- new_pkt .buf = NULL ;
696- a = 1 ;
697- } else
698- a = AVERROR (ENOMEM );
699- }
700- if (a > 0 ) {
701- pkt -> side_data = NULL ;
702- pkt -> side_data_elems = 0 ;
703- av_packet_unref (pkt );
704- new_pkt .buf = av_buffer_create (new_pkt .data , new_pkt .size ,
705- av_buffer_default_free , NULL , 0 );
706- if (!new_pkt .buf )
707- exit_program (1 );
708- } else if (a < 0 ) {
709- new_pkt = * pkt ;
710- av_log (NULL , AV_LOG_ERROR , "Failed to open bitstream filter %s for stream %d with codec %s" ,
711- bsfc -> filter -> name , pkt -> stream_index ,
712- avctx -> codec ? avctx -> codec -> name : "copy" );
713- print_error ("" , a );
714- if (exit_on_error )
715- exit_program (1 );
716- }
717- * pkt = new_pkt ;
718-
719- bsfc = bsfc -> next ;
679+ if ((ret = av_apply_bitstream_filters (s , pkt , bsfc )) < 0 ) {
680+ print_error ("" , ret );
681+ if (exit_on_error )
682+ exit_program (1 );
720683 }
721684
722685 if (!(s -> oformat -> flags & AVFMT_NOTIMESTAMPS )) {
@@ -4176,7 +4139,6 @@ static int transcode(void)
41764139 av_dict_free (& ost -> sws_dict );
41774140 av_dict_free (& ost -> swr_opts );
41784141 av_dict_free (& ost -> resample_opts );
4179- av_dict_free (& ost -> bsf_args );
41804142 }
41814143 }
41824144 }
0 commit comments