Skip to content

Instantly share code, notes, and snippets.

@Ruzzz
Last active November 24, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ruzzz/a377b9d2a900b2d161218db49f6d13ee to your computer and use it in GitHub Desktop.
Save Ruzzz/a377b9d2a900b2d161218db49f6d13ee to your computer and use it in GitHub Desktop.
ffmpeg video encode draft

Initialize

  1. AVCodec* avcodec_find_encoder(AVCodecID)
  2. AVCodecContext* avcodec_alloc_context3(AVCodec*)
    1. av_opt_set(...)
    2. avcodec_open2(AVCodecContext*, AVCodecID)

Initialize additional

  • AVPacket* av_packet_alloc()
  • AVFrame* av_frame_alloc()
    • av_frame_get_buffer(AVFrame*)
  • struct SwsContext* sws_getContext()

Work in loop

  1. FILL FRAME DATA
  2. sws_scale(struct SwsContext*, ...) IF NEEDED
  3. avcodec_send_frame(AVCodecContext*, AVFrame*)
    1. avcodec_receive_packet(AVCodecContext*, AVPacket*) IF READY
    2. SAVE PACKET DATA
    3. av_packet_unref(AVPacket*)

Finalize additional

  • av_packet_free(AVPacket**)
  • av_frame_free(AVFrame**)
  • sws_freeContext(struct SwsContext*)

Finalize

  • avcodec_free_context(AVCodecContext**)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment