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)

PPTX
FFmpeg presentation
Lauren Sorensen
 
PDF
FFmpeg: A Retrospective
Samsung Open Source Group
 
PPT
FFMPEG on android
Yoss Cohen
 
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
 
FFmpeg presentation
Lauren Sorensen
 
FFmpeg: A Retrospective
Samsung Open Source Group
 
FFMPEG on android
Yoss Cohen
 
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
 

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
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
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
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
John Keats introduction and list of his important works
vatsalacpr
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
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