FFmpeg

2,416 views

Published on

0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,416
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
136
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • FFmpeg

    1. 1. FFmpeg2012-04-01 Eric
    2. 2. outline work flow process structure my SOP
    3. 3. work flow process Input Video DataFile Demuxer stream Decoder Audio Data Subtitle Data
    4. 4. work flow processOutput Video DataFile Muxer stream Encoder Audio Data Subtitle Data
    5. 5. structureAVFormatContext Stream[n] AVStream AVCodecContext Codec Codec Bitrate FPS ………. Sample_rate …..
    6. 6. my SOP
    7. 7. step 1 include headers extern "C" { #include "libavformat/avformat.h" #include "libavutil/base64.h" } initial ffmpeg av_register_all()
    8. 8. step 2link library FFMPEGLIBS = -lavcodec -lavformat -lavutil
    9. 9. step 3 set up out format AVFormatContext avformat_alloc_context AVOutputFormat av_guess_format if format did not support, please set up configure file.
    10. 10. step 4 we need to prepare some codec structures. AVFormatContext av_new_stream(c, channel) video audio AVStream AVStream video audio stream->codecAVCodecContext AVCodecContext
    11. 11. step 5 set up video codec msrAVCodecContextVideo->codec_id = CODEC_ID_MPEG4; msrAVCodecContextVideo->codec_type = CODEC_TYPE_VIDEO; msrAVCodecContextVideo->bit_rate= iBitrate; msrAVCodecContextVideo->width= iWidth; msrAVCodecContextVideo->height= iHeight; msrAVCodecContextVideo->time_base.den = iFps; msrAVCodecContextVideo->time_base.num = 1; msrAVCodecContextVideo->gop_size= iFps; msrAVCodecContextVideo->pix_fmt= PIX_FMT_YUV420P; msrAVCodecContextVideo->max_b_frames=0;
    12. 12. step 6 set up audio codec msrAVCodecContextAudio = msrAVStreamAudio->codec; msrAVCodecContextAudio->codec_id = CODEC_ID_PCM_S16LE; msrAVCodecContextAudio->codec_type = CODEC_TYPE_AUDIO; msrAVCodecContextAudio->bit_rate = 128000 ; msrAVCodecContextAudio->sample_rate = 8000; msrAVCodecContextAudio->channels = 1;
    13. 13. step 7 open file descriptor and write header if(url_fopen(&sAVFormatContext->pb, pathName, URL_WRONLY) < 0) { //error handle } av_write_header(sAVFormatContext); the pathName can be following file://tmp/aaaa tcp://x99 udp://x88
    14. 14. step 8 try to write some data AVPacket sePacket; av_init_packet(&sePacket); sePacket.flags |= PKT_FLAG_KEY; sePacket.stream_index = channel; //which channel sePacket.data = data; sePacket.size = len; //sePacket.pts = ???; //explain later av_write_frame(sAVFormatContext, &sePacket); printf(“pts: %dn”, sePacket.pts); av_free_packet(&sePacket); if(sAVFormatContext->pb->error < 0) { //error handle }
    15. 15. step 9 close file descriptor if(sAVFormatContext->pb != NULL){ av_write_trailer(sAVFormatContext); if(url_fclose(sAVFormatContext->pb) < 0) { perror("Close file failed."); } sAVFormatContext->pb = NULL; }
    16. 16. step 10 get pts against different codec 1. let ffmpeg print and simulate it. 2. see RFC. 3. find pts calculate from ffmpeg source code.
    17. 17. Thanks a lot.

    ×