Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Issues
  • #1011
Closed
Open
Issue created Jul 19, 2022 by Administrator@rootContributor

How to convert the packet's format from avcc to annex-b?

Created by: bazige

I want to convert the video frame of avcc to annex-b, but currently pyav does not encapsulate a similar interface. I have implemented avcc2annex through c++, but I am not sure if AVFormatContext *pFormatCtx_ is different from pyav's class *av.codec.context.CodecContext, can you help me? Or is there any better suggestion other than calling the ffmpeg command line?

const AVBitStreamFilter *pFilter = av_bsf_get_by_name("h264_mp4toannexb");

int avcc2annex(AVFormatContext *pFormatCtx_, AVPacket *pkt, int videoStream) 
{
    AVBSFContext *pBsfCtx_ = nullptr; 
    int ret = av_bsf_alloc(pFilter, &pBsfCtx_);
    if (ret != 0) {
        LOG("Alloc bsf failed!");
        return -1;
    }

    ret = avcodec_parameters_from_context(pBsfCtx_->par_in, pFormatCtx_->streams[videoStream]->codec);
    if (ret < 0) {
        LOG("Set Codec failed!");
        return -1;
    }

    ret = av_bsf_init(pBsfCtx_);
    if (ret < 0) {
        LOG("Init bsf failed!");
        return -1;
    }

    av_bsf_send_packet(pBsfCtx_, pkt);
    ret = av_bsf_receive_packet(pBsfCtx_, pkt);
    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
        return -1;
    else if (ret < 0) {
        LOG("Receive packet failed!");
        return -1;
    }
    return 0;
}
Assignee
Assign to
Time tracking