1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
const AVBitStreamFilter *bsfilter = av_bsf_get_by_name("h264_mp4toannexb"); AVBSFContext *bsf_ctx = NULL;
av_bsf_alloc(bsfilter, &bsf_ctx);
avcodec_parameters_copy(bsf_ctx->par_in, ifmt_ctx->streams[videoindex]->codecpar); av_bsf_init(bsf_ctx); while (0 == file_end) { if((ret = av_read_frame(ifmt_ctx, pkt)) < 0) { file_end = 1; printf("read file end: ret:%d\n", ret); } if(ret == 0 && pkt->stream_index == videoindex) { int input_size = pkt->size; int out_pkt_count = 0; if (av_bsf_send_packet(bsf_ctx, pkt) != 0) { av_packet_unref(pkt); continue; } av_packet_unref(pkt); while(av_bsf_receive_packet(bsf_ctx, pkt) == 0) { out_pkt_count++; size_t size = fwrite(pkt->data, 1, pkt->size, outfp); if(size != pkt->size) { printf("fwrite failed-> write:%u, pkt_size:%u\n", size, pkt->size); } av_packet_unref(pkt); } if(out_pkt_count >= 2) { printf("cur pkt(size:%d) only get 1 out pkt, it get %d pkts\n", input_size, out_pkt_count); } } }
|