SlideShare a Scribd company logo
FFmpeg
2012-04-01 Eric
outline
 work flow process
 structure
 my SOP
work flow process

   Input


                                    Video Data
File   Demuxer   stream   Decoder   Audio Data
                                    Subtitle Data
work flow process

Output

                                  Video Data
File   Muxer   stream   Encoder   Audio Data

                                  Subtitle Data
structure
AVFormatContext




  Stream[n]       AVStream


                             AVCodecContext
                  Codec
                                 Codec
                                 Bitrate
                                  FPS
                     ……….
                               Sample_rate
                                  …..
my SOP
step 1
 include headers

           extern	 "C"	 {
           #include	 "libavformat/avformat.h"
           #include	 "libavutil/base64.h"
           }

  initial ffmpeg

           av_register_all()
step 2

link library


        FFMPEGLIBS	 =	 -lavcodec	 -lavformat	 -lavutil
step 3
 set up out format

   AVFormatContext          avformat_alloc_context




   AVOutputFormat           av_guess_format




  if format did not support, please set up configure file.
step 4
 we need to prepare some codec
 structures.

        AVFormatContext




                                    av_new_stream(c, channel)
    video                 audio
   AVStream           AVStream

    video                 audio
                                    stream->codec
AVCodecContext     AVCodecContext
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;
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;
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
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
      }
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;
 }
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.
Thanks a lot.

More Related Content

Viewers also liked (20)

PDF
FFmpeg
David Bařina
 
PDF
Lunch and Learn - FFmpeg
Nuruddin Ashr
 
PDF
FFmpeg - the universal multimedia toolkit
Stefano Sabatini
 
PPTX
Why Open Source is Important and What are We Doing About it?
Samsung Open Source Group
 
PDF
Ffmpeg
duquoi
 
PDF
work order of logic laboratory
FS Karimi
 
PDF
Bozorgmeh os lab
FS Karimi
 
PPTX
Gun make
psychesnet Hsieh
 
TXT
Programs for Operating System
LPU
 
PDF
Os file
mominabrar
 
DOCX
Os lab file c programs
Kandarp Tiwari
 
DOCX
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
PDF
O.s. lab all_experimets
Guru Janbheshver University, Hisar
 
KEY
Openssl
psychesnet Hsieh
 
DOCX
Ooad lab manual
Umamurthi Umamurthi
 
DOCX
Ooad lab manual(original)
dipenpatelpatel
 
KEY
ipv6 introduction & environment buildup
psychesnet Hsieh
 
PDF
Operating system lab manual
Meerut Institute of Technology
 
PPTX
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
Luca Berardinelli
 
Lunch and Learn - FFmpeg
Nuruddin Ashr
 
FFmpeg - the universal multimedia toolkit
Stefano Sabatini
 
Why Open Source is Important and What are We Doing About it?
Samsung Open Source Group
 
Ffmpeg
duquoi
 
work order of logic laboratory
FS Karimi
 
Bozorgmeh os lab
FS Karimi
 
Programs for Operating System
LPU
 
Os file
mominabrar
 
Os lab file c programs
Kandarp Tiwari
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
O.s. lab all_experimets
Guru Janbheshver University, Hisar
 
Ooad lab manual
Umamurthi Umamurthi
 
Ooad lab manual(original)
dipenpatelpatel
 
ipv6 introduction & environment buildup
psychesnet Hsieh
 
Operating system lab manual
Meerut Institute of Technology
 
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
Luca Berardinelli
 

Similar to FFmpeg (20)

PDF
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Chris Adamson
 
PDF
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
PDF
php & performance
simon8410
 
PDF
Introduction to Snort Rule Writing
Cisco DevNet
 
KEY
Prepare for PHP Test Fest 2009
PHPBelgium
 
PDF
Pascal script maxbox_ekon_14_2
Max Kleiner
 
PDF
Statyczna analiza kodu PHP
The Software House
 
PDF
Webvideo, FFmpeg und Drupal
Walter Ebert
 
PDF
Embedded Recipes 2019 - Testing firmware the devops way
Anne Nicolas
 
PPTX
Code Igniter Code Sniffer
Albert Rosa
 
PDF
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Chris Adamson
 
PPT
Virtual platform
sean chen
 
PDF
PHP & Performance
毅 吕
 
PDF
Tips
mclee
 
PDF
Orchestrating the execution of workflows for media streaming service and even...
Shuen-Huei Guan
 
PDF
Stupid Video Tricks, CocoaConf Seattle 2014
Chris Adamson
 
PDF
Efficient System Monitoring in Cloud Native Environments
Gergely Szabó
 
PDF
eBPF Tooling and Debugging Infrastructure
Netronome
 
PDF
SDAccel Design Contest: Vivado HLS
NECST Lab @ Politecnico di Milano
 
PPTX
Modern Linux Tracing Landscape
Sasha Goldshtein
 
Media Frameworks Versus Swift (Swift by Northwest, October 2017)
Chris Adamson
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
php & performance
simon8410
 
Introduction to Snort Rule Writing
Cisco DevNet
 
Prepare for PHP Test Fest 2009
PHPBelgium
 
Pascal script maxbox_ekon_14_2
Max Kleiner
 
Statyczna analiza kodu PHP
The Software House
 
Webvideo, FFmpeg und Drupal
Walter Ebert
 
Embedded Recipes 2019 - Testing firmware the devops way
Anne Nicolas
 
Code Igniter Code Sniffer
Albert Rosa
 
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Chris Adamson
 
Virtual platform
sean chen
 
PHP & Performance
毅 吕
 
Tips
mclee
 
Orchestrating the execution of workflows for media streaming service and even...
Shuen-Huei Guan
 
Stupid Video Tricks, CocoaConf Seattle 2014
Chris Adamson
 
Efficient System Monitoring in Cloud Native Environments
Gergely Szabó
 
eBPF Tooling and Debugging Infrastructure
Netronome
 
SDAccel Design Contest: Vivado HLS
NECST Lab @ Politecnico di Milano
 
Modern Linux Tracing Landscape
Sasha Goldshtein
 
Ad

Recently uploaded (20)

PDF
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
10CLA Term 3 Week 4 Study Techniques.pptx
mansk2
 
PPTX
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
PPTX
VOMITINGS - NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Joint Mobility : Fundamentals of Joint Mobility
Sreeraj S R
 
PPTX
national medicinal plants board mpharm.pptx
SHAHEEN SHABBIR
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Qweb Templates and Operations in Odoo 18
Celine George
 
PPTX
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
THE HUMAN INTEGUMENTARY SYSTEM#MLT#BCRAPC.pptx
Subham Panja
 
PPTX
quizbeenutirtion-230726075512-0387d08e.pptx
domingoriahlyne
 
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
Various Psychological tests: challenges and contemporary trends in psychologi...
santoshmohalik1
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
10CLA Term 3 Week 4 Study Techniques.pptx
mansk2
 
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
VOMITINGS - NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Joint Mobility : Fundamentals of Joint Mobility
Sreeraj S R
 
national medicinal plants board mpharm.pptx
SHAHEEN SHABBIR
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Qweb Templates and Operations in Odoo 18
Celine George
 
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
THE HUMAN INTEGUMENTARY SYSTEM#MLT#BCRAPC.pptx
Subham Panja
 
quizbeenutirtion-230726075512-0387d08e.pptx
domingoriahlyne
 
Ad

FFmpeg

  • 2. outline work flow process structure my SOP
  • 3. work flow process Input Video Data File Demuxer stream Decoder Audio Data Subtitle Data
  • 4. work flow process Output Video Data File Muxer stream Encoder Audio Data Subtitle Data
  • 5. structure AVFormatContext Stream[n] AVStream AVCodecContext Codec Codec Bitrate FPS ………. Sample_rate …..
  • 7. step 1 include headers extern "C" { #include "libavformat/avformat.h" #include "libavutil/base64.h" } initial ffmpeg av_register_all()
  • 8. step 2 link library FFMPEGLIBS = -lavcodec -lavformat -lavutil
  • 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. step 4 we need to prepare some codec structures. AVFormatContext av_new_stream(c, channel) video audio AVStream AVStream video audio stream->codec AVCodecContext AVCodecContext
  • 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. 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. 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. 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. 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. 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.

Editor's Notes