| | |
| | | ,format_name_("mp4") |
| | | ,in_v_stream_(NULL) |
| | | ,in_a_stream_(NULL) |
| | | ,bsf_h264(NULL) |
| | | ,bsf_hevc(NULL) |
| | | {} |
| | | |
| | | FormatOut::~FormatOut() |
| | | { |
| | | clear(); |
| | | |
| | | if (bsf_h264) av_bsf_free(&bsf_h264); |
| | | if (bsf_hevc) av_bsf_free(&bsf_hevc); |
| | | } |
| | | |
| | | void FormatOut::clear(){ |
| | |
| | | flag = writeHeader(&avdic); |
| | | av_dict_free(&avdic); |
| | | } |
| | | |
| | | |
| | | if (v){ |
| | | if (v->codecpar->codec_id == AV_CODEC_ID_H264){ |
| | | char p[100] = {0}; |
| | | char *sub = av_fourcc_make_string(p, v->codecpar->codec_tag); |
| | | if (strcmp(sub, "avc1") == 0){ |
| | | const AVBitStreamFilter *f = av_bsf_get_by_name("h264_mp4toannexb"); |
| | | if (f){ |
| | | if (av_bsf_alloc(f, &bsf_h264) >= 0){ |
| | | if (avcodec_parameters_copy(bsf_h264->par_in, v->codecpar) >= 0){ |
| | | if (av_bsf_init(bsf_h264) < 0) bsf_h264 = NULL; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | |
| | | |
| | | bool FormatOut::writeFrame2(AVPacket *pkt, bool interleaved){ |
| | | |
| | | // h264_mp4toanatax |
| | | if (bsf_h264){ |
| | | if (av_bsf_send_packet(bsf_h264, pkt) < 0){ |
| | | logIt("bsf_h264 send packet failed"); |
| | | return true; |
| | | } |
| | | if (av_bsf_receive_packet(bsf_h264, pkt) < 0){ |
| | | logIt("bsf_h264 recv packet failed"); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | // |
| | | int ret = 0; |
| | | if(interleaved){ |
| | | ret = av_interleaved_write_frame(ctx_, pkt); |