Formats AV

Index

General
Contenidors / Containers (MUX)

General

Contenidors / Containers (MUX)

.
Container
file ext file (UNIX) mime type
owner base brand ('ftyp')
video codecs
audio codecs
stream usage










file
transmission
3GP

video/3gpp
3GPP ISO Base media file format  (isobmff) (MPEG-4 part  12)(MP4reg) 3g??
  • MPEG-4
  • H263
  • H264/AVC
  • AMR-NB
  • AMR-WB
  • eAMR-WB
  • eAAC-Plus
  • MPEG-4 AAC
  • AAC-LC
x

MOV .mov ISO Media, Apple QuickTime movie video/quicktime Apple qt
x x x

MJ2 (Motion JPEG2000)









MP4 .mp4 ISO Media, MPEG v4 system
MPEG
  • MPEG-1 
  • MPEG-2 
  • MPEG-4 ASP
  • H264 / MPEG-4 AVC
  • MPEG-1
  • AC3
  • LPCM
  • DTS
  • AAC
x

DVB-FF
.dvb

video/vnd.dvb.file DVB
  • dvt1 (TS)
  • dvr1 (RTP)





ASF


Microsoft

x x x

AVI .avi

Microsoft

x x -

DivX


DivXNetworks

x x -

Flash Video .flv Macromedia Flash Video video/x-flv Adobe

  • Sorenson H.263 (Flash v6, v7)
  • VP6 (Flash v8)
  • Screen video
  • H.264
  • MP3
  • ADPCM
  • Linear PCM
  • Nellymoser
  • Speex
  • AAC
  • G.711
RTMP

.f4v

video/mp4 ISO base media file
  • H.264
  • AAC
  • HE-AAC
  • MP3



Matroska (wp)
.mkv
.mka
.mks


CoreCodec MCF

  • H.264
  • Realvideo
  • DivX
  • XviD
  • ...
  • AAC
  • Vorbis
  • Dolby AC3
  • MP3
  • ...
x

MCF


BSD

x x x

MPEG PS .mpg .mpeg
.vob
MPEG sequence, v2, program multiplex
MPEG

  • MPEG-1 
  • MPEG-2
  • MPEG-1
  • AC3
  • LPCM
  • DTS
  • AAC
?

MPEG TS .ts
.trp
MPEG transport stream data
(TeX font metric data)

MPEG

  • MPEG-1 
  • MPEG-2 
  • MPEG-4 ASP
  • H264 / MPEG-4 AVC
x

BDAV MPEG TS
.m2ts


MPEG

  • H264 / MPEG-4 AVC




MXF .mxf

SMPTE






OGG
(RFC 3533)



Xiph


  • Vorbis
x

OGM (RFC 3534)





  • Theora
  • Vorbis



RMVB


Real Networks

RealVideo x x

SVI (AVI) .svi

Samsung AVI
XVID 208x176
15fps
HAS_INDEX
IS_INTERLACED
TRUST_CKTYPE
mpga
2ch
44100Hz
128Kbps



VOB
(MPEG PS)



MPEG

  • MPEG 2 (part 2)
  • MPEG1 (l2)
  • MPEG2 (p3)
  • AC3
  • LPCM
  • DTS



WEBM
.webm

video/webm
audio/webm
Google
Matroska

VP8
Vorbis



Container
file ext file (UNIX) mime type
owner base
video codecs
audio codecs
stream


  • Comparison of container formats (Wikipedia)
  • Container formats (MultimediaWiki)
  • Detailed Features for different Media Container Formats (eInfochips)
  • White paper: media container file formats (MP4/Quicktime structure)
  • Video file formats
  • Audio file formats
  • Audio file format FAQ
  • purpose
    package
    info
    anàlisi / analysis
    extraction (demux)
    remux
    conversió / conversion
    encryption
    general
    ffmpeg ffmpeg -i ffprobe
    ffplay -i esports_3.m2v -vf 'showinfo'


    ffmpeg
    libav avconv -i avprobe



    mplayer midentify


    mencoder
    kaa.metadata mminfo




    transcode



    transcode

    OpenCaster

    pesinfo
    esvideompeg2info
    tspcrmeasure
    [mpeg2video]vbv
    esaudioinfo
    ts2pes
    pes2es
    esvideompeg2pes
    esaudio2pes
    pesvideo2ts
    pesaudio2ts
    tscbrmuxer


    MPEG-4 MPEG4IP mp4info mp4trackdump mpeg_ps_extract
    mpeg4ip
    mp4fragmenter

    bento4 mp4info mp4dump


    x
    GPAC MP4Box -info MP4Box -diso MP4Box -h extract
    MP4Box -raw 1 toto.mp4
    MP4Box -add video.264 -add audio.aac toto.mp4
    MP4Box -add toto1.mp4#video -add audio.aac toto.mp4
    MP4Box

    JSVM

    BitStreamExtractorStatic



  • Info
  • Anàlisi / Analysis
    • bento4
    • H.264
    • MP4
    • GPAC
    • Gstreamer
    • avprobe (libav)
      • Usage
        • format
          • avprobe -v 0 -show_format toto.mp4
          • only duration inside [format]:
            • avprobe -v 0 -show_format_entry duration toto.mp4
        • streams
          • avprobe -v 0 -show_streams toto.mp4
        • packets
          • avprobe -v 0 -show_packets toto.mp4
    • ffplay
    • ffprobe (ffmpeg)
      • Usage
        • -show_entries (separated by ":")
          • -show_entries
            optional filter (frame=...,...,...:packet=...,...)
            format
            • bit_rate
            • duration
            • filename
            • format_name
            • nb_streams
            • nb_programs
            • probe_score
            • size
            • start_time
            stream
            • index
            • codec_name
            • codec_long_name
            • profile
            • codec_type
            • codec_time_base
            packet
            • codec_type
            • stream_index
            • pts
            • pts_time
            • dts
            • dts_time
            • duration
            • duration_time
            • convergence_duration
            • convergence_duration_time
            • size
            • pos
            • flags
            frame
            • media_type
            • stream_index
            • key_frame
            • pkt_pts
            • pkt_pts_time
            • pkt_dts
            • pkt_dts_time
            • best_effort_timestamp
            • best_effort_timestamp_time
            • pkt_duration
            • pkt_duration_time
            • pkt_pos
            • pkt_size
            • width
            • height
            • pix_fmt
            • sample_aspect_ratio
            • pict_type
            • coded_picture_number
            • display_picture_number
            • interlaced_frame
            • top_field_first
            • repeat_pict
            • color_range
            • color_space
            • color_primaries
            • color_transfer
            • chroma_location
          • Exemples / Examples
            • time, type, size
              • ffprobe -v 0 -show_entries frame=pkt_dts_time,pict_type,pkt_size -print_format compact=nk=1:p=0:s='\ ' -select_streams v:0 sintel.mkv
            • mixed (frame and stream)
              • ffprobe -v 0 -show_entries format=bit_rate,filename:stream=codec_type,index toto.mov
            • frame
              • ffprobe -v 0 -show_entries frame=coded_picture_number,pict_type,pkt_size -select_streams 0:8 794.ts
        • deprecated (use -show_entries instead)
          • -show_format
            • ffprobe -v 0 -show_format -print_format compact=item_sep=*:nokey=1 794.ts
            • ffprobe -v 0 -show_format -print_format json=compact=1 794.ts
          • -show_streams
            • ffprobe -v 0 -show_streams -print_format xml -pretty 794.ts > /tmp/794_streams.xml
            • ffprobe -v 0 -show_streams -print_format flat=s=_  794.ts
          • -show_frames
            • ffprobe -v 0 -show_frames -print_format xml -select_streams v:0 794.ts > /tmp/794_frames.xml
            • -print_format
              • print compact format
                • -print_format compact=item_sep=*:nokey=1
                • ffprobe -v 0 -show_entries frame=coded_picture_number,pict_type -print_format compact -i "concat:v1_init_gpac.mp4|v1_0_gpac.m4s|v1_1_gpac.m4s"
                • ffprobe -v 0 -show_entries packet=pts,dts -print_format compact -i "concat:v1_init_gpac.mp4|v1_0_gpac.m4s|v1_1_gpac.m4s"
                • without key names
                  • ffprobe -show_entries frame=coded_picture_number,pict_type:packet=pts_time -print_format compact=nk=1 -select_streams v:0 toto.mp4
                • print fields from frame and from packet:
                  • ffprobe -show_entries frame=coded_picture_number,pict_type:packet=pts_time -print_format compact -select_streams v:0 toto.mp4
                • with no section (p=0), no field keys (nk=1), space as a separator (s='\ '):
                  • -print_format compact=nk=1:p=0:s='\ '
              • print json
                • -print_format json=compact=1
              • print xml
                • -print_format xml
              • print csv format
                • ffprobe -show_entries frame=coded_picture_number,pict_type:packet=pts_time -print_format csv -select_streams v:0 toto.mp4
                • with a different character separator (#)
                  • ffprobe -show_entries frame=coded_picture_number,pict_type:packet=pts_time -print_format csv=s=# -select_streams v:0 toto.mp4
                • without printing section
                  • -print_format csv=p=0:s=#
            • video (-select_streams v:0) frames
              • video profile and level
                • ffprobe -show_streams -i toto.mp4
                  • profile=Baseline
                    ...
                    level=31
                    ...

              • duration
                • duration=$(ffprobe -i $video_path -show_format -v quiet | sed -n 's/duration=//p')
                  # keep only numbers and decimal point (discard N/A):
                  duration=$(echo $duration | tr -d -c 0-9.)

              • bit-rate extraction
                • bit_rate=$(ffprobe -v 0 -show_entries format=bit_rate toto.mp4 | sed -n 's/bit_rate=//p')
              • bit-rate calculation
                • eval $(ffprobe -v 0 -show_entries format=duration,size -print_format flat=s=_ 794.ts) && echo $format_size*8/$format_duration | bc -l
            • Tips
              • Passing options to ffprobe
              • FFprobe scripting question
              • HANDY TIP: Using FFprobe for stream analysis (plots with gnuplot) (requires a recent version of ffmpeg: /usr/local/bin/ffprobe)
                • plot.txt
                  • # GNUPLOT "plot.txt"
                    set title "Title"
                    set xlabel "frame #"
                    set ylabel "Bytes per frame"
                    #set yrange [0:120000]
                    #set ytics (120000, 110000, 100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000)
                    #set xrange [-10:850]
                    set lmargin 12
                    set rmargin 2
                    set grid
                    set pointsize 2
                    set label 1 "I frames"
                    set label 1 at graph .85, .96 tc lt 1
                    set label 2 "P frames"
                    set label 2 at graph .85, .92 tc lt 2
                    set label 3 "B frames"
                    set label 3 at graph .85, .88 tc lt 3
                    plot 'column.dat' using 3:1:2 notitle with i lc rgb variable
                • /usr/local/bin/ffprobe -show_entries frame=coded_picture_number,pict_type,pkt_size -select_streams v:0 794.ts | grep 'size\|coded_picture_number\|pict_type' > raw.dat && paste -s -d '\t\t\n' raw.dat > fixed.dat && sed -e 's/coded_picture_number=//g' -e 's/pkt_size=//g' -e 's/pict_type=//g' -e 's/I/167116800/g' -e 's/P/65280/g' -e 's/B/255/g' fixed.dat > column.dat && gnuplot -p < plot.txt
        • Extracció / Extraction (demux)
          • ffmpeg
          • MPEG4IP
            • mpeg_ps_extract
            • ...
          • libdvb
            • ts2es
            • ts2ps
            • ...
          • MKVToolnix (Matroska)
          • extraction of ES (elementary streams):


          • libdvb MPEG4IP GPAC
            MPEG-2 TS ts2es

            PS
            mpeg_ps_extract
            MPEG-4 MP4

            MP4Box -h extract
          • Extracció de pistes d'un DVD / Extract tracks from dvd (*) (*)
            • mkdir /media/dvd; mount /dev/dvd /media/dvd
            • tccat -i /dev/dvd -d 2 -T 6,-1,1 > fist.vob
            • mplayer dvd://TITOL -dvd-device DISPOSIU_o_IMATGE.ISO -dumpstream -dumpfile dvd.vob
              • mplayer dvd://1 -dvd-device /dev/dvd -dumpstream -dumpfile dvd.vob
              • mplayer dvd://4 -dvd-device toto.iso -dumpstream -dumpfile dvd.vob
            • vlc dvd:RUTA_DVD@TIT --audio-track X --sub-track Y --sout "#standard{access=file,mux=ps,dst=FICH_SAL}"
              • vlc dvd:/dev/dvd@4 --audio-track 1 --sub-track 1 --sout "#standard{access=file,mux=ps,dst=dvd.vob}"
              • vlc dvd:casinoRoyale.iso@4 --audio-track 1 --sub-track 1 --sout "#standard{access=file,mux=ps,dst=dvd.vob}"

        Conversió / Conversion

        • Programari/software
        • HOWTO Convert video files
        • MTS files (AVCHD: H.264 + AAC on MPEG2-TS, from camera)
        • Subtítols / Subtitles
                  • wget ...
                  • vobsub.c:
                    • rename getline to getlinia (or anything else)
                  • Makefile:
                    • INCLUDES := -I /usr/include/netpbm
                    • #LIBS += -lppm
                      LIBS += -lnetpbm
                  • make
                • subtitle2pgm
            • Gnome Subtitles
            • KSubtile
            • SubtitleEditor
            • Gaupol 
            • GSubEdit
            • Jubler
            • sub2srt
            • Subtitles
              • compensate the display time in 3 seconds:
                • subs -i -b 3 subtitle_file.sub
              • 24fps -> 25 fps:
                • subs -i -a 24/25 subtitle_file.sub
              • time from file1 and text from file2:
                • subs -z subtitle_file1.sub subtitle_file2.sub
        • MPEG4IP
          • info
          • rgb2yuv
          • yuvdump (YUV viewer)
        • Using MJPEG-tools
        • Using mencoder (mplayer)
        • Using transcode (tccat, tcextract):
          • urpmi
          • Subtitle manipulation tools for Linux
            1. DVD -> /home/user/rip/vob
            2. tccat -i /home/user/rip/vob | tcextract -x ps1 -t vob -a 0x22 > subs-en
            3. other languages:
              • to determine the sid for the preferred subtitles:
                • mplayer -dvd-device /space/st-tng/disc1/ -dvd 1 -vo null -ao null -frames 0 -v 2>&1 | grep sid
              • if you want language with sid 7, then add it to 0x20:
                • tccat -i /home/user/rip/vob | tcextract -x ps1 -t vob -a 0x27 > subs-it
            4. convert them to images:
              • subtitle2pgm -o english -c 255,0,255,255 < subs-en
            5. OCR:
              • pgm2txt english
            6. create srt file:
              • srttool -s -w < english.srtx > english.srt
          • Estabilització / Stabilization
        • libav (fork from ffmpeg)
          • Història / History
          • Instal·lació / Installation
          • Compilació / Compilation
          • pipe
            • syntax
              meaning
              example
              pipe:0
              stdin
              ... | avconv -i pipe:0 ...
              pipe:1
              stdout
              avconv ... pipe:1 | tee -a fitxer1 fitxer2
              pipe:2
              stderr

            • avconv -f video4linux2 -i /dev/video0 -s 320x240 -vcodec libx264 -f mpegts pipe:1 | avplay -i pipe:0
            • avconv -i tvc_794_20140821_1709.ts -c copy -f mpegts - | avplay -i -
            • mkfifo
              • mkfifo toto.ts
              • avconv -i ... -f mpegts - > toto.ts
              • [avconv -i ... -f mpegts -y toto.ts]
              • avplay toto.ts
              • simultaneous 2 outputs to 2 fifos (does not work)
                • mkfifo v1.ts v2.ts
                • ffmpeg -i sintel-1280-surround.mp4 -c:v libx264 -b:v 500k -s 640x360 -aspect 16:9 -an -f mpegts -y v1.ts -c:v libx264 -b:v 1500k -s 1280x720 -aspect 16:9 -f mpegts -y v2.ts
              • other examples
          • General
            • logs
              • avconv -loglevel debug ...
              • si voleu també els logs de debug de libx264:
                • ...
            • redirect stderr to a file:
              • avconv -y -loglevel debug ... > toto.debug 2>&1
          • Filtres / Filters
            • ffmpeg filters
            • Info about input (only available when specifying an output)
              • avconv -i input -filter:v showinfo output
          • Tall / Cut (5s)
            • avconv -threads auto -i toto.MTS -t 0:00:05.0 -c:v copy -c:a copy -f mpegts toto_5s.MTS
          • Concatenació / Concatenation
          • Entrellaçat / Interlaced
          • Rotació i rescalatge / Rotation and rescale
            • avconv -threads auto -i toto.mts -filter:v transpose=clock toto_clock.mp4
            • resize and then rotation:
              • libav <= 0.8.7
                • avconv -threads auto -i 00189_5s.MTS -filter:v scale=576:-1,transpose=clock -f mpegts 00189_5s_clock.MTS
              • avconv -threads auto -i 00189_5s.MTS -filter:v scale=w=576:h=-1,transpose=clock -f mpegts 00189_5s_clock.MTS
            • resize, rotation and pad:
              • avconv -threads auto -i 00189_5s.MTS -filter:v "scale=w=576:h=-1,transpose=clock,pad=width=720:height=576:x=(ow-iw)/2:y=0:color=black" -f mpegts 00189_5s_clock.MTS
              • avconv -threads auto -i 00189_5s.MTS -filter:v "scale=w=576:h=-1,transpose=clock,pad=width=720:height=576:x=(ow-iw)/2:y=0:color=black" -strict experimental 00189_5s_clock.mp4
          • Relació d'aspecte / Aspect ratio (ffmpeg)
            • # pad the input to get a final w/h ratio of 16:9
              pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2"
            • resize (1920x1080 16:9 -> 720x576 16:9 anamorphic) and transcode (H.264, AAC):
              • avconv -threads auto -i toto.MTS -filter:v "scale=w=720:h=576,setdar=dar=16/9" -strict experimental toto.mp4
            • resize from 1280x544 (2,35)
              • to SD 4:3 (with letterbox)
                • ffplay -i sintel-1280-surround.mp4 -vf 'pad=width=iw:height=iw*3/4:x=0:y=(oh-ih)/2, scale=w=720:h=576, setdar=dar=4:3'
                • ffmpeg -i sintel-1280-surround.mp4 -vf 'pad=width=iw:height=iw*3/4:x=0:y=(oh-ih)/2, scale=w=720:h=576, setdar=dar=4:3' -c:v mpeg2video -an sintel_pad_4\:3_v2.mp4
              • to HD 16:9 (with letterbox)
                • ffplay -i sintel-1280-surround.mp4 -vf 'pad=width=iw:height=iw*9/16:x=0:y=(oh-ih)/2'
              • to SD 16:9 anamorphic (with letterbox)
                • ffplay -i sintel-1280-surround.mp4 -vf 'pad=width=iw:height=iw*9/16:x=0:y=(oh-ih)/2, scale=w=720:h=576, setdar=dar=16:9'
                • ffmpeg -i sintel-1280-surround.mp4 -vf 'pad=width=iw:height=iw*9/16:x=0:y=(oh-ih)/2, scale=w=720:h=576, setdar=dar=16:9' -c:v libx264 -an sintel_pad_16:9.mp4
          • Sobreimpressió / Overlay
          • Transport Stream (TS) (see also ffmpeg TS)
          • MP4 (see also ffmpeg MP4)
          • Streaming (see also ffmpeg streaming)

            • server client (192.168.1.100)
              output option: -f ...

              (check that the port is not closed by the firewall)
              RTP / SDP
              rtp
              unicast
              • (?) avconv -re -i toto.mp4 -c:a copy -c:v copy -f rtp rtp://192.168.1.100:1234

              multicast
              • (?) avconv -re -i toto.mp4 -c:a copy -c:v copy -f rtp rtp://234.1.2.3:1234

              TS over UDP
              mpegts
              unicast
              • avconv -re -i toto.mp4 -bsf h264_mp4toannexb -c:a copy -c:v copy -f mpegts "udp://192.168.1.100:1234?ttl=10&buffer_size=65536&pkt_size=1316"
              • avconv -re -i toto.mp4 -f mpegts "udp://192.168.1.100:1234?ttl=10&buffer_size=65536&pkt_size=1316"
              • avplay -infbuf udp://@:1234
              • avplay -infbuf udp://@:1234?reuse=1
              multicast
              • avconv -re -i toto.mp4 -c:v copy -c:a copy -bsf h264_mp4toannexb -f mpegts "udp://234.1.2.3:1234?ttl=10&buffer_size=65536&pkt_size=1316"
              • avconv -re -i toto.mp4 -f mpegts "udp://234.1.2.3:1234?ttl=10&buffer_size=65536&pkt_size=1316"
              -re option is needed when input is a file
            • server
              • RTP / SDP
                • from file
                  • avconv -re -i ...
                • from camera
                  • avconv -f video4linux2 -i /dev/video0 -s 320x240 -vcodec libx264 -f rtp rtp://192.168.1.100:1234
                • send generated sdp (shown on screen when launching previous command) to client as toto.sdp
                  • v=0
                    o=- 0 0 IN IP4 127.0.0.1
                    s=No Name
                    c=IN IP4 192.168.1.100
                    t=0 0
                    a=tool:libavformat 55.0.1
                    m=video 1234 RTP/AVP 96
                    a=rtpmap:96 H264/90000
                    a=fmtp:96 packetization-mode=1
              • TS over UDP (use pkt_size=1316 to allocate 7 TS packets into one IP packet: 188*7=1316 < 1500):
                • (see also OpenCaster tsudpsend)
                • unicast (-re option needed if input is a file)
                  • avconv -i ... -f mpegts -muxrate 1200000 udp://unicast_destination_address:1234?buffer_size=65536&pkt_size=1316
                  • no transcoding (H.264/AAC) (depending on original mp4 file, the option -bsf may be necessary)
                    • avconv -re -i toto.mp4 -bsf h264_mp4toannexb -c:a copy -c:v copy -f mpegts udp://192.168.1.100:1234?ttl=10&buffer_size=65536&pkt_size=1316
                  • transcode from mp4 (h.264/aac) to mpeg2ts (mpeg2video/mp2):
                    • avconv -re -i toto.mp4 -f mpegts udp://192.168.1.100:1234?ttl=10&buffer_size=65536&pkt_size=1316
                • multicast
                  • avconv -i ... -f mpegts -muxrate 1200000 udp://multicast_destination_address:1234?ttl=10&buffer_size=65536&pkt_size=1316
                  • implicit transcoding to mpeg2video/mp2:
                    • avconv -re -i toto.mp4 -f mpegts udp://234.1.2.3:1234?ttl=10&buffer_size=65536&pkt_size=1316
                  • no transcoding:
                    • avconv -re -i toto.mp4 -c:v copy -c:a copy -bsf h264_mp4toannexb -f mpegts udp://234.1.2.3:1234?ttl=10&buffer_size=65536&pkt_size=1316
            • client (192.168.1.100)
              • RTP / SDP
                • unicast
                  • just play:
                    • avplay toto.sdp
                  • write the stream to a TS file with TS constant bit-rate (e.g. 80kbps):
                    • avconv -i toto.sdp -c:v copy -y -f mpegts -muxrate 80000 toto.ts
                • multicast
                  • ...
              • TS over UDP (see also ffmpeg UDP):
                • -infbuf option is needed to avoid errors (see also fifo_size for ffmpeg)
                • unicast
                  • avplay -infbuf udp://@:1234
                  • avconv ... -i udp://...fifo_size=...
                • multicast
                  • avplay -infbuf -i udp://@234.1.2.3:1234
          • H.264 / libx264 (see also ffmpeg with x264)
            • libx264
              • GOP size: 100
                • -g 100
            • baixa latència / low latency
            • x264 presets:
              • avconv -preset ultrafast
            • avconv presets
              • /usr/local/share/avconv/libx264-*.avpreset
                • avconv -pre:v 1080p50_60
              • /usr/local/share/avconv/libx264-toto_preset.avpreset (com es fa amb un fitxer local? quines opcions hi ha disponibles?)
                • slices=2
                  x264-params=cabac=0
                  ...
                • avconv ... -pre:v toto_preset ...
            • baseline profile del vídeo redimensionat a 360x* ("-1" fa que es mantingui la relació), a 800 kbps:
              • avconv -i toto.ts -filter:v scale=360:-1 -b:v 800k -profile:v baseline toto.mp4
            • Problemes / Problems
        • Using ffmpeg
          • Docs
          • ffplay -loglevel verbose ...
            • ffplay -v {quiet,panic,fatal,error,warning,info,verbose,debug} [-vf showinfo] ...
            • Protocol 'rtp' not on whitelist 'file,crypto'!
              • ffplay -safe 0 -protocol_whitelist rtp,udp,file,http,https,tcp,tls -i toto.sdp
            • keyboard (cursor over window showing video)
              • q      ESC quit
                f      toggle full screen
                p,SPC  pause
                a      cycle audio channel in the current program
                v      cycle video channel
                t      cycle subtitle channel in the current program
                c      cycle program
                w      cycle video filters or show modes
                s      activate frame-step mode
                left/right         seek backward/forward 10 seconds
                down/up            seek backward/forward 1 minute
                pg down/pg up      seek backward/forward 10 minutes
                mouse right click  seek to percentage in file corresponding to fraction of width
            • webcam
              • Capture / Webcam
              • Dispositius / Devices
                • v4l2-ctl --list-devices
                • v4l2-ctl -d /dev/video1 -L
                • v4l2-ctl -c <option>=<value>
              • Visualització / View
                • ffmpeg -f v4l2 -list_formats all -i /dev/video1
                • ffplay -f v4l2 -framerate 25 -video_size 1280x720 -fflags nobuffer -i /dev/video1
          • ffmpeg [-v ...] [options_for_input_file_0 [-i input_file_0]] [options_for_input_file_1 [-i input_file_1]] [-map 0:x] [-map 1:y] [options_for_output_file_0 [output_file_0]] [options_for_output_file_1 [output_file_1]] [options -newaudio] [options -newvideo]
          • keyboard actions (type "?" to see help)
            • ?      show this help
              +      increase verbosity
              -      decrease verbosity
              c      Send command to first matching filter supporting it
              C      Send/Que command to all matching filters
              D      cycle through available debug modes
              h      dump packets/hex press to cycle through the 3 states
              q      quit
              s      Show QP histogram
          • Generic options (show available ...):
            • ffmpeg -formats
            • ffmpeg -codecs
            • ffmpeg -filters
            • ffmpeg -pix_fmts (show available pixel formats: -pixel_format)
            • ffmpeg -sample_fmts
          • general parameters
            • -d daemonize (must be the very first option)
            • -stream_loop <number> (0: no loop; -1: infinite loop; n: number of loops)
            • -i input file
              • Video sources (synthetic videos)
                • [ffplay,ffmpeg] -f lavfi -i testsrc=size=1280x720 ...
            • -f container/ES_type
            • -loglevel, -v {quiet,panic,fatal,error,warning,info,verbose,debug,trace}
          • flags / fflags
          • video parameters
          • audio parameters
            • -c:a audio_codec
            • -b:a audio_bit-rate
            • -ac number_of_audio_channels
            • -ar audio_sampling_rate
          • -map input_file:index (when using map option, all output streams to be mapped must be specified; if output file can contain both audio and video, e.g. mp4, two -map must be specified)
            • examples (*):
              • ... -map 0:0 -map 0:2 ... toto.mp4
                • stream #0:0 (video) to toto.mp4 video track
                • stream #0:2 (2nd audio) to toto.mp4 main audio track
              • .. -map 0:0 -map 0:2 -map 0:1 ... toto.mp4 -newaudio
                • stream #0:0 (video) to toto.mp4 video track
                • stream #0:2 (2nd audio) to toto.mp4 main audio track
                • stream #0:1 (1st audio) to toto.mp4 secondary audio track
              • ... -map 0:3 -map 2:4 out_a.mp2 out_b.mp3
                • stream #0.3 to out_a.mp2
                • stream #2.4 to out_b.mp3
              • ffmpeg -i first_input.mp4 -i second_input.mp4 -i third_input.mp2 -map 0:0 -map 0:2 -map 1:1 -map 1:1 -map 2:1 toto.mp4 -newaudio out_a.mp2 out_b.mp3
                input
                output
                first_input.mp4 contains:
                • 0:0: video track
                • 0:1: audio track
                • 0:2: audio track
                -i first_input.mp4
                second_input.mp4 contains:
                • 1:0: video track
                • 1:1: audio track
                -i second_input.mp4
                third_input.mp2 contains:
                • 2:0: audio track
                • 2:1: audio track
                -i third_input.mp2
                -map 0:0 toto.mp4 toto.mp4 will contain the following tracks:
                • 0:0: video from first_input
                • 0:1: audio from second audio track from first_input
                • 0:2: audio from first audio track from second_input
                -map 0:2
                -map 1:1 -newaudio
                -map 1:1 out_a.mp2 out_a.mp2 will contain the following tracks:
                • 1:0: audio from first audio track from second_input
                -map 2:1 out_b.mp3 out_b.mp3 will contain the following tracks:
                • 2:0: audio from second audio track from third input
              • TS program selection
          • pipe
          • multiple inputs
          • múltiples sortides / multiple outputs
          • sample formats
          • Start from time (-ss) hh:mm:ss[:ff], during duration (-t):
            • ffmpeg ... -ss hh:mm:ss[:ff] -t hh:mm:ss[.dd] ...
            • specify -ss before -i to avoid anything but key frames: much faster (*)
            • "-ss seconds" for an entire number of seconds
          • filtres / filtering
            • FFmpeg Filters Documentation
            • Filtering guide (wiki)
            • chained filters
              • simple
              • complex
                • -filter_complex
            • list of available filters:
              • ffmpeg -filters
            • audio
              • ffmpeg -filter:a ...
              • ffmpeg -af ...
              • show information
              • (?) ffmpeg -i esports3.mp4 -filter:a aformat=sample_fmts=s16 ...
              • aresample
            • video
              • ffmpeg -filter:v ...
              • ffmpeg -vf ...
              • show information (n pts pts_time pos fmt sar s i iskey type checksum plane_checksum mean stdev)
              • remove the logo
                • ffplay -i tv3.m2v -vf 'delogo=x=620:y=40:w=50:h=50:band=10:show=0'
              • add a logo (see OpenCaster):
              • display subtitles
                • dep
                  • Mageia
                    • urpmi libass-devel
                • ./configure ... --enable-libass
                • ffmpeg -vf 'subtitles'
              • scale (resize)
                • Scaling (resizing) with ffmpeg
                • same aspect ratio:
                  • force width:
                    • ffmpeg ... -vf scale=320:-1...
                  • inscribe into a maximum rectangle (*):
                    • ffmpeg ... -vf scale=w=854:h=480:force_original_aspect_ratio=decrease ...
                    • ffmpeg ... -vf scale='ceil(min(1\,min(854/iw\,480/ih))*iw):-2' ...
                    • ffmpeg ... -vf scale='-2:ceil(min(1\,min(854/iw\,480/ih))*ih)' ...
                  • excribe around a minimum rectangle:
                    • ffmpeg ... -vf scale=w=854:h=480:force_original_aspect_ratio=increase ...
              • PIP
                • ffplay -i 324.m2v -vf 'movie=tv3.m2v, scale=180:-1 [petit]; [in][petit] overlay=16:16 [out]'
                • ffplay -i 794.ts -vst 11 -ast 12 -vf "movie=794.ts:s=0, scale=180:-1 [v1]; [in][v1] overlay=16:16 [out]"
                • ffmpeg -i 794.ts -filter_complex "[0:v:0]scale=width=240:height=180[petit]; [0:v:1][petit] overlay" -f mpegts - | ffplay -
                • ffmpeg -i 794.ts -b:v 2M -filter_complex "[0:v:0]scale=width=240:height=180[petit]; [0:p:803:v][petit] overlay" -f mpegts - | ffplay -
              • mosaic
                • ffmpeg -i 794.ts -b:v 4M -filter_complex "nullsrc=size=1280x720 [base]; [0:v:0] scale=width=640:height=360 [upperleft]; [0:v:1] scale=width=640:height=360 [upperright]; [0:v:2] scale=width=640:height=360 [lowerleft] ; [0:v:3] scale=width=640:height=360 [lowerright]; [base][upperleft] overlay [tmp1]; [tmp1][upperright] overlay=shortest=1:x=640 [tmp2]; [tmp2][lowerleft] overlay=shortest=1:y=360 [tmp3]; [tmp3][lowerright] overlay=shortest=1:x=640:y=360" -f mpegts - | ffplay -
              • drawtext
                • ffmpeg has to be compiled with --enable-libfreetype, and, optionally, --enable-fontconfig (to allow not specifying font)
                • Burnt in timecode
                  • Dependencies
                    • Mageia
                      • urpmi google-droid-sans-fonts
                        • fontfile=/usr/share/fonts/google-droid/DroidSansMono.ttf
                      • urpmi fonts-ttf-droid
                    • CentOS
                      • sudo yum install google-droid-sans-mono-fonts google-droid-sans-fonts
                        • fontfile=/usr/share/fonts/google-droid/DroidSansMono.ttf
                    • Ubuntu
                      • sudo apt-get install fonts-droid-fallback
                        • fontfile=/usr/share/fonts-droid/truetype/droid/DroidSansFallback.ttf
                  • ffplay -f lavfi -i testsrc=size=1280x720 -vf "drawtext=fontfile=${fontfile}: timecode='09\:57\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1"
                  • ffplay -f lavfi -i testsrc=size=1280x720 -vf "drawtext=fontfile=/usr/share/fonts/TTF/droid/DroidSans.ttf: timecode='09\:57\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1"
                  • ffmpeg -i sintel-1024-stereo.mp4 -vf "drawtext=fontfile=${fontfile}: timecode='00\:00\:00\:00': r=24: x=(w-tw)/2: y=h-(2*lh): fontsize=50: fontcolor=white: box=1: boxcolor=0x00000000@1" -c:a copy -c:v libx264 sintel-1024-stereo_timecode.mp4
                  • present time:
                    • ... -vf "drawtext=fontfile=${fontfile}: text='%{localtime\:%T}': r=24: x=(w-tw)/2: y=h-(2*lh): fontsize=50: fontcolor=white: box=1: boxcolor=0x00000000@1" ...
                  • timecode and present time:
                    • ffplay -f lavfi -i testsrc=size=1280x720:r=25 -vf "format=pix_fmts=yuv420p,  drawtext=fontfile=/usr/share/fonts/google-droid/DroidSans.ttf: text='%{gmtime\:%T %Z}': r=25: x=(w-tw)/3*2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=50, drawtext=fontfile=/usr/share/fonts/google-droid/DroidSans.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/3: y=h-(2*lh): fontsize=50: fontcolor=white: box=1: boxcolor=0x00000000@1"
                    • ffmpeg -f lavfi -i testsrc=size=1280x720:r=25 -vf "format=pix_fmts=yuv420p, drawtext=fontfile=/usr/share/fonts/google-droid/DroidSans.ttf: text='%{gmtime\:%T %Z}': r=25: x=(w-tw)/3*2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1: fontsize=50, drawtext=fontfile=/usr/share/fonts/google-droid/DroidSans.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/3: y=h-(2*lh): fontsize=50: fontcolor=white: box=1: boxcolor=0x00000000@1" -c:v libx264 -g 12 -keyint_min 12 -sc_threshold 0 -f flv rtmp://...
                  • resize to 1280x720, downmix to stereo, add timecode:
                    • ffmpeg -i big_buck_bunny_1080p_h264.mov -vf "scale=1280:-1, drawtext=fontfile=/usr/share/fonts/google-droid/DroidSans.ttf: timecode='00\:00\:00\:00': r=24: x=(w-tw)/2: y=h-(2*lh): fontsize=50: fontcolor=white: box=1: boxcolor=0x00000000@1" -ac 2 -c:a aac -strict -2 -b:a 64k -c:v libx264 -b:v 700k bbb_timecode_1280x720_700k_stereo.mp4
              • show DVB subtitles:
                • from ts file
                  • ffplay -i tvc_794_20140821_1709.ts -vst 2 -ast 7 -sst 23
                • from live dvb (no funciona, perquè potser tzap no conserva els subtítols)
                  • tzap -pr "TV3(TVC)"
                  • ffplay -f mpegts -i /dev/dvb/adapter0/dvr0 -vf 'subtitles=...
              • burn DVB subtitles:
                • ffmpeg -i tvc_794_20140821_1709.ts
                  •   Program 801
                        Metadata:
                          service_name    : ?TV3
                          service_provider: ?TVC
                        Stream #0:2[0x6f]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
                        Stream #0:7[0x70](cat): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 158 kb/s
                        Stream #0:6[0x72](v.o): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 94 kb/s
                        Stream #0:8[0x73](ac3): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 192 kb/s
                        Stream #0:22[0x74](a.d): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 94 kb/s
                        Stream #0:23[0x321](cat): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
                        Stream #0:24[0x32b](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
                    ...
                • ffmpeg -i tvc_794_20140821_1709.ts -filter_complex '[#0x6f][#0x321] overlay' -sn -map '#0x70' -f mpegts - | ffplay -
                • ffmpeg -i 794.ts -filter_complex '[0:v][0:s:0]overlay[v]' -map [v] -map 0:a ...
            • ffmpeg -f lavfi -i amovie=toto.ts,silencedetect=noise=0.0001 -f null -
            • blackframe
              • ffmpeg -f lavfi -i movie=tvc_hd_20121116-2345.ts,blackframe -f null -
          • segmentació / segmentation
            • HLS
            • segment
              • segment an mp4 file into segments of 2s duration each:
                • ffmpeg -i toto.mp4 -codec copy -f segment -segment_time 2 -segment_list toto.list toto.%06d.mp4
          • concatenació / concatenation
            • libav: Concatenació / Concatenation
            • MTS: Concatenació / Concatenation
            • Concatenate (How to concatenate (join, merge) media files) (wiki)
              • Concat filter
                • Does not accept -c copy
              • Manually
                • directly concatenable formats
                  • cat imput1.ts input2.ts > output.ts
                • not directly concatenable formats, but transmuxable to a concatenable format (e.g. H.264/AAC in MP4, to TS)
                  • mkfifo temp1 temp2
                    ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
                    ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
                    ffmpeg -f mpegts -i "concat:temp1|temp2" -c copy -bsf:a aac_adtstoasc output.mp4
                  • concat_mp4.sh
                    • #!/bin/bash

                      MIN_ARGS=2
                      if (( $# < $MIN_ARGS ))
                      then
                          cat <<EOF
                      Usage: `basename $0` <input1> <input2> <input3> ... <output>

                      Concatenate several MP4 files into a single one.
                      EOF
                          exit 1
                      fi

                      #TMP=/tmp
                      TMP=$(mktemp -d)

                      # get all the command line parameters, except for the last one, which is output
                      output=${@:$#:1}
                      len=$(($#-1))
                      inputs=${@:1:$len}

                      function get_metadata {
                          video_path=$1

                          echo "[$(basename $0).get_metadata] $video_path"

                          info=$(ffprobe -i $video_path -show_format -v quiet)
                          metadata_str=$(echo "$info" | awk 'BEGIN {ORS=" ";FS="="} /^TAG:/ {gsub(/TAG:/,""); print "-metadata " $1 "=\"" $2 "\""}')
                          echo "[$(basename $0).get_metadata] metadata_str: $metadata_str"

                          return
                      }

                      function finish {
                          # remove created fifos
                          rm -f $TMP/mcs_*
                      }

                      # call finish function when exiting
                      trap finish EXIT

                      echo "[$(basename $0)]"

                      # remove all previous tmp fifos (if exist)
                      rm -f $TMP/mcs_*

                      i=0
                      for f in $inputs
                      do
                          echo "[$(basename $0)]  input $i: $f"

                          if [[ -s $f ]]
                          then
                          # create fifo
                          fifo_name=$TMP/mcs_$i
                          mkfifo $fifo_name
                         
                          # copy to fifo
                          ffmpeg -i $f -y -c copy -bsf:v h264_mp4toannexb -f mpegts $fifo_name 2> /dev/null &

                          if (( i==0 ))
                          then
                              concat_str="concat:${fifo_name}"
                              # get metadata (e.g. creation date) only from the first file
                              get_metadata $f
                          else
                              concat_str="${concat_str}|${fifo_name}"
                          fi

                          else
                          echo "[$(basename $0)] WARNING: $f is not a valid input"
                          fi

                          (( i++ ))
                      done

                      echo "[$(basename $0)]  output: $output"

                      if [[ "$concat_str" ]]
                      then
                          echo "[$(basename $0)]  concat_str: $concat_str"
                          eval ffmpeg -y -f mpegts -i \"${concat_str}\" -c copy -bsf:a aac_adtstoasc $metadata_str $output
                      else
                          echo "[$(basename $0)] ERROR: no valid input files found"
                          exit 1
                      fi

                      exit 0
              • Using an external script
                • mmcat.sh
          • timestamps
          • info output is written to stderr (stdout is used for media data)
            • ffmpeg -i toto.mp2 toto.aac 2>toto.log
          • HOWTOs
          • Frame-rate
            • tbn, tbc, tbr
            • -r ...
            • -vsync
              • value
                string
                description
                -1
                auto
                "Chooses between 1 and 2 depending on muxer capabilities. This is the default method."
                0
                passthrough "Each frame is passed with its timestamp from the demuxer to the muxer."
                1
                cfr
                "Frames will be duplicated and dropped to achieve exactly the requested constant frame rate."
                2
                vfr
                "Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp."

                drop
                "As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate."
              • ffmpeg: -vsync 0 versus -r (frame rate)
            • Create a video by  fragmenting the provided one into fragments of different framerates:
              • vfr.sh
                • #!/bin/bash

                  video_path=$1
                  video_basename=$(basename $video_path)
                  video_name=${video_basename%.*}

                  # video
                  video_coder=h264
                  video_bitrate=500k

                  # audio
                  audio_coder=aac
                  audio_bitrate=128k

                  # get duration
                  duration=$(ffprobe -i $video_path -show_format -v quiet | sed -n 's/duration=//p')
                  # keep only numbers and decimal point (discard N/A):
                  duration=$(echo $duration | tr -d -c 0-9.)

                  echo "duration of ${video_path}: ${duration}"

                  fps_array=(30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 30 5 20 10 30 50 4 20 )
                  number_fragments=${#fps_array[@]}
                  echo "number_fragments: ${number_fragments}"

                  fragment_duration=$(echo ${duration}/${number_fragments} | bc )
                  echo "fragment_duration: ${fragment_duration}"
                  start=0
                  for fps in ${fps_array[@]}
                  do
                      echo "${fps} fps"
                      echo "  start: $start"

                      output_filename=$(printf "%s_%05d_%sfps.mp4" ${video_name} ${start} ${fps})
                      echo "  output_filename: ${output_filename}"

                      ffmpeg -y -ss ${start} -t ${fragment_duration} -i ${video_path} -vsync cfr -vf fps=${fps} -c:v ${video_coder} -b:v ${video_bitrate} -c:a ${audio_coder} -b:a ${audio_bitrate} ${output_filename}
                     
                      start=$(( start + fragment_duration ))
                  done


                  # final concatenation
                  final_output_filename="${video_name}_vfr.mp4"
                  script=concat_mp4.sh
                  if which ${script}
                  then
                      echo "script ${script} found"
                      concat_mp4.sh -o ${final_output_filename} ${video_name}*fps.mp4
                  else
                      echo "script ${script} not found"
                  fi

                  exit 0
          • Bit-rate
          • H.264 video (using x264) (see also libav with libx264)
          • Transport stream (TS) (see also libav TS)
            • Creating DVB-T compatible MPEG2 streams using FFMPEG
            • Generar un TS (Transport Stream) valido para DVB-T y DVB-T2 (TDT) (-mpegts...)
            • Encoding H.264 CBR videos with FFmpeg
            • -streamid ...
            • Mux bitrate (specified in bits per second) (Bitrate calculator)
              • -muxrate 19905882
            • mpegts encoding options:
              • -mpegts_original_network_id
              • -mpegts_transport_stream_id
              • -mpegts_service_id
              • -mpegts_pmt_start_pid
              • -mpegts_start_pid
              • -metadata service_provider="nom proveidor"
              • -metadata service_name="nom servei"
            • Program (service) selection:
              • Stream specifiers (bug)
              • Convert MPEG2TS to H264 ES
              • ffprobe
                • ffprobe -v 0 -show_frames -select_streams v:1 794.ts
              • play video (-vst) #0:11 and audio (-ast) #0:12
                • ffplay -i 794.ts -vst 11 -ast 12
              • from the first (0:) input file, select "Program 51" (:p:51:) video (:0), without transcoding (-c:v copy) into H.264 elementary stream (input video already was H.264):
                • ffmpeg -i input.ts -map 0:p:51:0 -c:v copy output.h264
              • select "program 802" video and two audios from input file and generate a TS:
                • ffmpeg -i 794.ts -map 0:p:802:0 -map 0:p:802:1 -map 0:p:802:2 -c:v copy -c:a copy /tmp/c33.ts
              • or directly select the stream id given by ffmpeg -i:
                • ffmpeg -i 794.ts
                  • Program 803
                      Metadata:
                        service_name    : ?3/24
                        service_provider: ?TVC
                      Stream #0:26[0x83]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
                      Stream #0:27[0x84](cat): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 158 kb/s
                      Stream #0:25[0x86](v.o): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 94 kb/s
                    [...]
                • ffmpeg -i 794.ts -map 0:26 -c:v copy /tmp/324.m2v
              • select by pid:
                • get the PIDs:
                  • ffmpeg -i
                    • nput #0, mpegts, from 'tvc_794_20140821_1709.ts':
                        Duration: 13:26:44.25, start: 758.128889, bitrate: 26 kb/s
                        Program 801
                          Metadata:
                            service_name    : ?TV3
                            service_provider: ?TVC
                          Stream #0:2[0x6f]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
                          Stream #0:7[0x70](cat): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 158 kb/s
                      ...
                • ff
                • ffmpeg -f mpegts -i udp://host:port -c:a:i:2300 aac -b:a 384k -c:v copy -f flv rtmp://host/live/stream
            • Transcoding from TS with MPEG-2 audio and video to TS with H.264 and MPEG-2 audio:
              • ffmpeg -i tvc_hd_20121116-2348.ts -c:a mp2 -ab 64k -ar 48000 -ac 1 -async 1 -c:v libx264 -threads 4 -preset veryfast -profile:v main -b:v 200k -s 256x144 -f mpegts toto2.ts
            • Creation of a TS from an ES (obtained with ffmpeg -i 794.ts -map 0:p:802:0 -c:v copy /tmp/c33.m2v):
              • ffmpeg -fflags +genpts -i /tmp/c33.m2v -c:v copy /tmp/c33_m2v.ts
          • MP4 (see also libav MP4)
            • mov / mp4 / ismv
            • Fragmentació / Fragmentation
            • H.264 + AAC
              • ffmpeg -i ... -c:v libx264 -b:v 800k -g 25 -keyint_min 25 -sc_threshold 0 -c:a aac -b:a 128k toto.mp4
            • MP4 files to be MPEG-DASHed with MP4Box, and played with dash.js (which requires -frag-rap option in MP4Box)
              • two representations with an added key frame every 2 (n_forced*2) seconds (see also libx264 GOP)
              • simultaneous two video representations and one audio representation, read at its rate (-re):
                • ffmpeg -re -i sintel_trailer-720p.mp4 \
                  -c:v libx264 -b:v 500k -s 640x360 -aspect 16:9 -keyint_min 24 -g 24 -r 24 -an sintel_trailer_640x360_500k.mp4 \
                  -c:v libx264 -b:v 1500k -s 1280x720 -aspect 16:9 -keyint_min 24 -g 24 -r 24 -an sintel_trailer_1280x720_1500k.mp4 \
                  -c:a aac -strict -2 -b:a 128k -vn sintel_trailer_audio_128k.mp4
                  • Stream mapping:
                      Stream #0:0 -> #0:0 (h264 -> libx264)
                      Stream #0:0 -> #1:0 (h264 -> libx264)
                      Stream #0:1 -> #2:0 (aac -> aac)
            • moov atom not found
              • Solució / Solution
                • untrunc
                  • ponchio / untrunc
                  • Compilació / Compilation
                    • get the code from git
                      • git clone https://github.com/ponchio/untrunc.git
                      • cd untrunc
                    • compile with a compiled ffmpeg (/usr/local)
                      • g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -I <path_to_src>/ffmpeg-3.4.2 -I/usr/local/include -lavformat -lavcodec -lavutil
                    • compile with a system ffmpeg
                      • ..
                  • Ús / Usage
                    • ...
          • FLV
            • ffmpeg -re -f lavfi -i "testsrc=size=864x480, format=pix_fmts=yuv420p" -f lavfi -i "sine=frequency=5000:sample_rate=44100, aformat=channel_layouts=stereo" -c:v h264 -b:v 600k -profile:v main -preset ultrafast -c:a aac -strict -2 -b:a 64k -f flv toto.flv
            • RTMP
              • Test Streaming With FFMPEG
                • ffmpeg -re -f lavfi -i "testsrc=size=1280x720:rate=24" -f lavfi -i sine=f=220:b=1 -af "volume=0.1" -codec:a aac -strict -2 -codec:v libx264 -preset ultrafast -profile:v main -tune zerolatency -pix_fmt yuv420p -g 48 -f flv rtmp://...
                  • Problems
                    • [flv @ 0x23df540] Packets are not in the proper order with respect to DTS
                      av_interleaved_write_frame(): Invalid argument
                      [flv @ 0x23df540] Failed to update header with correct duration.
                      [flv @ 0x23df540] Failed to update header with correct filesize.
                      • Solution: update ffmpeg
                        • problem is present with:
                          • libavformat    56.  4.101
                        • it is not present with: 
                          • libavformat    56. 25.101
          • Specific formats
            • Android video
              • Video encoding recommendations (Android Developers)


                lower quality
                higher quality
                video
                codec
                H.264 baseline profile
                H.264 baseline profile
                resolution
                176x144
                480x360
                frame rate
                12 fps
                30 fps
                bitrate
                56 Kbps
                500 Kbps
                audio
                codec
                AAC-LC
                AAC-LC
                channels
                1
                2
                bitrate
                24 Kbps
                128 Kbps

              • Converting Videos For The Android T-Mobile G1 Phone With Linux
              • Encoding Video for Android (Broken links)
              • PAL 16:9 to 480x320 ("-map 0:2" to use 2nd audio track) (DVD track extraction):
                • ffmpeg -threads 4 [-ss seconds] -i toto.vob -map 0:0 -map 0:2 -s 480x270 -padtop 24 -padbottom 26 -vcodec libx264 -vpre superfast -vpre baseline -b 480k -acodec libvo_aacenc -ab 128k -async 2 -sameq -aspect 3:2 toto_android.mp4
              • HD 1080i to 480x320 ("-ac 2" to downmix to 2 audio channels):
                • ffmpeg -threads 4 -i toto.MTS -s 480x270 -padtop 24 -padbottom 26 -vcodec libx264 -vpre superfast -vpre baseline -b 480k -acodec libvo_aacenc -ab 128k -ac 2 -r 25 -sameq -aspect 3:2 toto_android.mp4
              • ffmpeg -aspect 3:2 -i inputfilename.ext -aspect 3:2 -s 480x320 -vcodec h264 -b 480k -r 23.976 -acodec aac -ab 96k -sameq -pass 1 outputfilename.mp4
              • ffmpeg -aspect 4:3 -i inputfilename.ext -aspect 3:2 -s 400x300 -vcodec h264 -b 480k -r 23.976 -acodec aac -ab 96k -padtop 10 -padbottom 10 -padleft 40 -padright 40 -sameq -pass 1 outputfilename.mp4
              • ffmpeg -aspect 16:9 -i inputfilename.ext -aspect 3:2 -s 480x270 -vcodec h264 -b 480k -r 23.976 -acodec aac -ab 96k -padtop 24 -padbottom 26 -sameq -pass 1 outputfilename.mp4
            • HbbTV video
              • SD
                • ffmpeg -i toto.mp4 -s 720x576 -aspect 16:9 -r 25 -vcodec libx264 -vpre fast -sameq toto-576.mp4
              • HD
                • ...
            • TomPlayer video
              • ffmpeg -i toto.xxx -vcodec mpeg4 -b 700k -s 480x272 toto.avi
            • iPhone video
            • iPod video
              • iPod (Videolan)
              • iPod video guide
                • 1.5Mbit/s 640×480 H.264 videos
                  • ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -vpre slow -vpre ipod640 -b BIT_RATE -aspect WIDTH:HEIGHT -threads 0 -f ipod OUTPUT.mp4
                • 768kbit/s 320×240 H.264 videos
                  • ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -vpre slow -vpre ipod320 -b BIT_RATE -metdata "title=SOME_TITLE" -threads 0 -f ipod OUTPUT.mp4
              • commandline ffmpeg & x264 settings for Ipod 5.5
              • (*): ffmpeg -i input.mp4 -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 320x240 -vcodec libx264 -b 96k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 96k -bufsize 96k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 output.ts
              • ffmpeg -i <in file> -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -vcodec libx264 -s 320x240 -b 96k -bt 200k -maxrate 96k -bufsize 96k -rc_eq 'blurCplx^(1-qComp)' -level 30 -aspect 320:240 -async 2 -vpre mobile <output file>
                • libx264-mobile.ffpreset:
                  • flags=+loop
                    cmp=+chroma
                    partitions=+parti4×4+partp8×8+partb8×8
                    subq=5
                    trellis=1
                    refs=1
                    coder=0
                    me_range=16
                    keyint_min=25
                    sc_threshold=40
                    i_qfactor=0.71
                    qcomp=0.6
                    qmin=10
                    qmax=51
                    qdiff=4
                    g=30
              • x264 encoding guide
                • --level 1.3 --no-cabac --vbv-bufsize 768 --vbv-maxrate 768
            • PS3 video
            • Conversion for Portivity (60s starting at time 50)
              • ffmpeg -ss 50 -t 60 -i sp.mxf -vcodec libx264 -s 320x240 -b 160k -r 12.5 -acodec libfaac -ab 32k sp.mp4
              • [ffmpeg -ss 50 -t 60 -i sp.mxf -vcodec h264 -s 320x240 -b 160k -r 12.5 -acodec aac -ab 32k sp.mp4]
              • MP4Box -hint sp.mp4 (to be streamed by Darwin server)
            • To Samsung SVI (no funciona...):
              • ffmpeg -i toto.mp4 -f avi -s 208x176 -r 15 -vcodec xvid toto.svi
          • Just copy the audio ES
            • ffmpeg -acodec copy ...
          • General (ts -> h264/MP4) (plf needed):
            • ffmpeg -i toto.ts -vcodec {h264,libx264} -s 320x240 -r 15 -b 1000 -f mp4 toto.mp4
          • Elementary streams
            • From .m2v (elementary stream) to .h264 (elementary stream):
              • ffmpeg -i toto.m2v [-f h264] toto.h264
            • From .mp2 (elementary stream) to AAC (elementary stream) (plf needed):
              • ffmpeg -i toto.mp2 toto.aac
          • YUV
            • From .yuv video file (-s must be the first parameter):
              • ffmpeg -s 704x576 -i toto_704x576.yuv -f mp4 -vcodec {h264,libx264} toto.mp4
              • ffmpeg -s 720x576 -i 576i25_shields_ter.yuv -target pal-dvd -aspect 16:9 576i25_shields_ter.vob
              • ffmpeg -s 1280x720 -r 50 -i 720p50_shields_ter.yuv -target pal-dvd -aspect 16:9 720p50_shields_ter.vob
            • To .yuv video file:
              • ffmpeg -i toto.mp4 toto.yuv
          • Video codecs
            • MPEG-4 SP (simple profile):
              • ffmpeg ... -profile 0...
            • To force MPEG-4 ASP (advanced simple profile):
              • ffmpeg ... -profile 15...
            • To specify H.264 level:
              • ffmpeg ... -[v]level 30 ... (level 3.0)
            • To specify video profile (prefer -profile:v instead of -vprofile):
            • -profile:v MPEG-4 H.264 (libx264)
              0, 16 Simple Baseline
              1, 17 Simple Scalable Baseline
              2 Core Baseline
              3 Unknown Profile(49)
              4 Unknown Profile(65
              5 Scalable Texture
              6 Simple Face Anim
              7 Basic Anim Text
              8 Hybrid
              9 Adv RT Simple
              10 Core Scalable
              11 Adv Coding Efficieny
              12 Adv Core Profile
              13 Adv Scalable Texture
              14 Simple Studio
              15 Adv Simple

            • AVCHD to AVI (AVS forum)
              • FFmpeg Tutorial: Convert MTS/M2TS(AVCHD) to AVI
              • % xport -h sample.m2ts 1 1 1
                % mv bits0001.mpa sample.ac3
                % mkfifo pipe.yuv
                % ldecod -i bits0001.mpv -o pipe.yuv &
                % ffmpeg -r 29.97 -s 1440x1080 -i pipe.yuv -i /tmp/sample.ac3 -acodec copy -vcodec mpeg4 -aspect 16:9 -b 15000k sample.avi
                % rm pipe.yuv
            • GIF animat / Animated GIF
          • I-frames only
            • fmpeg ... -intra ...
          • B-frames
            • ffmpeg ... -bf number ...
          • image -> video
            • Timelapse / Stop motion
              • Subsample image file names
              • cp ranges
              • From several jpeg or png files:
                • Create a video slideshow from images
                • Reproducció / Play
                  • ffplay -framerate 50 -start_number 150 -i DSC%05d.JPG
                • Creació de vídeo / Video creation
                  • to 1280x720@8fps:
                    • ffmpeg -y -start_number 767 -r 8 -i DSC%05d.JPG -vf 'pad=max(iw\,ih*16/9):ow*9/16:(ow-iw)/2:(oh-ih)/2, scale=1280:-1' -c:v libx264 -f mp4 toto_8fps.mp4
                  • ffmpeg -start_number 150 -i DSC%05d.JPG -c:v libx264 -f mp4 toto.mp4
                  • ffmpeg -r 5 -start_number 150 -i DSC%05d.JPG -vf scale=1280:-1 -c:v libx264 -f mp4 toto.mp4
                  • ffmpeg -r 15 -start_number 150 -i toto%02d.png -f mp4 -vcodec {h264,libx264} toto.mp4
              • From all png files in a dir (globbing):
              • Smooth
              • From video
                • ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -an output.mp4
            • Make a Video File from a Single Frame:
              • ffmpeg -loop_input -vframes <number_of_frames> -i <input_file> <output_file>
              • Carta d'ajust / Test card
                • ffmpeg -loop_input -vframes 250 -i bars_grey.bmp -vcodec mpeg2video bars_grey.mpeg
            • From raw (c-generated) rgb images:
              • tvTestPattern > f.raw
              • ffmpeg -f rawvideo -pix_fmt rgb24 -s 720x576 -aspect 4:3 -i f.raw -f s16le -ac 2 -i /dev/zero -shortest -target dvd -b 4000 -ab 128 -ildct -ilme -y interlace_test2.mpeg
            • From raw UYVY 4:2:2 images:
              • ffmpeg -loop_input -f rawvideo -pix_fmt uyvy422 -s 720x576 -aspect 4:3 -i mostra.uyvy -f s16le -ac 2 -i <(dd if=/dev/zero bs=19200 count=1) -target pal-dvd toto.mpeg
                • ffplay toto.mpeg (durada infinita!) (de fet, es pot fer directament: ffplay -s 720x576 -f rawvideo -pix_fmt uyvy422 -i toto.uyvy)
            • mpeg animation (eg for DVD menus) from a single image (*):
              • ffmpeg -loop_input -t 1.0 -i stillframename -ar 48000 -f s16le -i <(dd if=/dev/zero bs=19200 count=1) -target pal-dvd outputmoviename
          • video -> images (thumbnails)
            • Extract only (-vframes 1 or -t 00:00:00:01) the 5th frame of second 20 (-ss 00:00:20:05), from file into a jpeg image (thumbnail) (*) (-ss before -i is much faster):
              • ffmpeg -ss 00:00:20:05 -i toto.mp4 -vframes 1 -f mjpeg toto.jpeg
              • ffmpeg -ss 00:00:20:05 -i toto.mp4 -vframes 1 -f singlejpeg -s 150x100 toto.jpeg (maybe singlejpeg is not supported)
            • ffmpegthumbnailer
            • Extract all frames from file into several jpeg files (implicit image2 format):
              • ffmpeg -i toto.mp4 toto%d.jpeg
            • Extract one frame every 1 second (-r 1) to several jpeg images:
              • ffmpeg -i toto.mp4 -r 1 toto%05d.jpeg
              • every 10 seconds: 
                • ffmpeg -i toto.mp4 -r 1/10 toto%05d.jpeg
              • use strftime (activate it with -strftime 1) in file name:
                • ffmpeg -i toto.mp4 -r 1/10 -strftime 1 "%Y-%m-%d_%H-%M-%S.jpg"
            • Multiple thumbnails:
              • ffmpeg -ss $i*$interval -i intro.mov -vframes 1 -s 320x240 thumb_$i.jpg
              • thumb.sh (allows output name of type img_<position_in_seconds>s.jpeg)
                • #!/bin/bash

                  input=$1
                  interval=$2

                  # output dimensions (aspect ratio will be preserved)
                  out_width=320
                  out_height=240

                  # video duration
                  duration=$(ffprobe -i $input -show_format -v quiet | sed -n 's/duration=//p')
                  duration_int=${duration%\.*}
                  echo "duration: $duration"

                  position=0
                  while (( position < duration_int ))
                  do
                      position_name=$(printf "%06d" $position)
                      echo $position_name
                      ffmpeg -v 0 -ss $position -i $input -vframes 1 -vf scale=w=${out_width}:h=${out_height}:force_original_aspect_ratio=decrease img_${position_name}s.jpeg
                      (( position=position+interval ))
                  done
            • ffmpeg-php
            • Generating Video Thumbnail Storyboards
            • Making thumbnails for movies with ffmpeg
          • Crop
            • part central del vídeo, amb relació 4:3
              • ffplay sintel-1024-stereo.mp4 -vf 'crop=ih*4/3:ih'
          • Relació d'aspecte / Aspect ratio
            • vegeu pad amb libav / see simplified pad with libav
            • scale filter: preserve aspect ratio (resulting video will inscribe inside a rectangle of 854x480, decreasing width or height as needed, while preserving the input aspect ratio)
            • pad video filter
              • qualsevol relació d'aspecte d'entrada, cap a sortida en 16:9
                • ffplay sintel-1024-stereo.mp4 -vf 'pad=max(iw\,ih*16/9):ow*9/16:(ow-iw)/2:(oh-ih)/2'
            • From anamorphic (active: 720x576) to letterbox (ETSI 300 294) (active: 720x432 (720/16*9 * 4/3/(720/576)=432); horizontal bars: (576-432)/2=72 heigth each) (padcolor will usually be black 000000) (sameq to have the same bitrate as the input):
              • ffmpeg ... -s 720x432 -padtop 72 -padbottom 72 -padcolor 00ff00 -sameq -aspect 4:3 ...




            • 4:3
              16:9
              720x576 720x576
              4:3
              720x576
              -
              -s 540x576
              -padleft 90 -padright 90
              -aspect 16:9
              768x576
              -s 720x576
              -aspect 4:3
              14:9
              720x576
              -s 720x492
              -padtop 42 -padbottom 42
              -aspect 4:3
              -s 630x576
              -padleft 44 -padright 46
              -aspect 16:9
              896x576
              16:9
              720x576
              -s 720x432
              -padtop 72 -padbottom 72
              -aspect 4:3
              -
              1024x576
              -s 720x576
              -aspect 16:9
            • Càlculs / Calculations (aspecte.ods, aspecte.c):
              • Input image
                • Wi: given input image width
                • Hi: given input image height
                • DARi: given input display aspect ratio
                • input anamorphic factor: Di = DARi / (Wi/Hi)
              • Output image
                • Wo: given output image width
                • Ho: given output image height
                • DARo: given output display aspect ratio
                • output anamorphic factor: Do = DARo / (Wo/Ho)
                • W'o: calculated output active image width
                • H'o: calculated output active image height
                • LR: calculated total number of pixels at sides (LR/2 at each side)
                • TB: calculated total number of pixels at top and bottom (TB/2 at each zone)
              • Pillar box (if calculated LR gives >0)
                • W'o=Wi * Di/Do * Ho/Hi
                • H'o=Ho
                • LR=Wo - W'o
              • Letter box (if calculated TB gives >0)
                • W'o=Wo
                • H'o=Hi * Do/Di * Wo/Wi
                • TB=Ho - H'o
          • Rotació / Rotation
            • ffmpeg -i toto.mp4 -vf transpose=2 toto_90.mp4
            • rotació + tall quadrat / rotation + squared crop:
              • ffmpeg -i toto.mp4 -filter 'crop=in_h,transpose=1' toto_1.mp4
          • Extracció / Extraction
            • Transport stream
            • Extract only video track
              • ffmpeg -i toto.vob -an -vcodec copy toto.m2v
            • Extract only audio (vn: no video) track:
              • ffmpeg -i toto.mxf -vn -acodec copy toto.mp2
              • ffmpeg -i toto.vob -map 0:3 -vn -acodec copy toto.wav
            • Extract only subtitles track:
              • ffmpeg -i toto.mov -vn -an -scodec copy toto.srt
              • ffmpeg -i toto.mov -map s:0 -vn -an -c:s copy toto2.srt
              • extract the second subtitles track from program 801 in a TS:
                • ffmpeg -i toto.ts ...
              • extract the cat dvb subtitles (in bold) from a SP TS file:
                • ffmpeg -i 120208_2318\(33\).ts
                    Program 802
                      Metadata:
                        service_name    : ?33
                        service_provider: ?TVC
                      Stream #0:0[0x79]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 15000 kb/s, 26.94 fps, 25 tbr, 90k tbn, 50 tbc
                      Stream #0:1[0x7a](cat): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16, 160 kb/s
                      Stream #0:2[0x7c](v.o): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16, 96 kb/s
                      Stream #0:3[0x7e](a.d): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16, 96 kb/s
                      Stream #0:4[0x85](cat): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
                      Stream #0:5[0x322](cat): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
                      Stream #0:6[0x32e](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
                      Stream #0:7[0x386]: Unknown: none ([5][0][0][0] / 0x0005)
                      Stream #0:8[0x259]: Unknown: none ([12][0][0][0] / 0x000C)
                • ffmpeg -i 120208_2318\(33\).ts -map 0:5 -vn -an -scodec copy toto.srt
                • ffmpeg -i 120208_2318\(33\).ts -map 0:5 -vn -an -scodec copy -f rawvideo dvbsub.dat (*)
                • ffmpeg -i 794_20121105_0026.ts -map 0:8 -vn -an -scodec copy -copyinkf -f srt dvbsub.srt (*)
          • [Ffmpeg-user] encode multiple audio tracks to a single output file
            • ffmpeg -i toto.vob -map 0:0 -map 0:1 -map 0:2 -acodec copy -vcodec copy toto_multi.vob -acodec copy -newaudio
          • Multiangle generation:
            • ffmpeg -i toto1.m2v -i toto2.m2v -vcodec copy toto.vob -vcodec copy -newvideo
          • Convert from VOB to TS:
            • ffmpeg -i toto.vob -sameq -acodec copy toto.ts
          • Multiplex ES:
            • ffmpeg -i toto.h264 -i toto.aac -vcodec copy -acodec copy toto.mp4
          • Audio sync
          • Subtítols / Subtitles
            • list of supported subtitle codecs:
              • ffmpeg -codecs | grep "^...S"
            • extract subtitles
            • delay and hardcode (using -filter_complex) subtitles:
              • ffmpeg -i input.ts -filter_complex '[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay' -sn -map '#0x2dc' output.mkv
            • Subtitle manipulation tools for Linux
          • Metadades / Metadata
          • Sobreimpressió / Superimpose
          • Conversió automàtica / Automatic conversion
          • Enregistrament / Recording
          • Streaming (see also libav streaming)
            • Streaming guide (ffmpeg wiki)
            • FFmpeg – the swiss army knife of Internet Streaming – part IV
            • Buffers:

              • buffer_size
                fifo_size
                infbuf

                s->buffer_size s->circular_buffer_size

                transmission
                -
                -
                reception
                • default: 7 * 4096 * 188 bytes
                • parameter in command:
                  • "... udp://127.0.0.1:1234?fifo_size=... "
                  • -fifo_size 64k -i bbb.sdp
                • only for ffplay
              • Pèrdua de paquets RTP / RTP packet loss
              • Per a veure la mida del buffer que s'ha establert finalment / To see the effectively set receiving or sending buffer size (double the specified buffer_size):
                • ffmpeg/ffplay -v debug ...
                  • [udp @ 0x7f4ddc00e8c0] end receive buffer size reported is 131072
                • ffmpeg/ffplay -v debug -buffer_size 65536 ...
                  • [udp @ 0x7f4ddc00e8c0] end receive buffer size reported is 131072
                • ffmpeg/ffplay -v debug -buffer_size 212992 ...
                  • [udp @ 0x7f4ddc00e8c0] end receive buffer size reported is 425984
              • El valor màxim que es pot especificar a buffer_size està limitat pel valor del paràmetre del kernel / Maximum value than can be specified by buffer_size option is maximum value limited by kernel parameters:
                • sudo sysctl net.core.rmem_max
                  • net.core.rmem_max = 212992
                • Si especifiqueu un valor més gran que net.core.rmem_max, se us mostrarà un avís / If you specify a value greater than net.core.rmem_max you will get a warning message:
                  • sudo sysctl net.core.rmem_max
                    • net.core.rmem_max = 212992
                  • ffmpeg -v debug -buffer_size=851968 ...
                    • [udp @ 0x15a2280] attempted to set receive buffer to size 851968 but it only ended up set as 425984
                • Per a poder incrementar el buffer_size més enllà de net.core.rmem_max, haureu de modificar el valor del paràmetre del kernel  / To increase buffer_size beyond net.core.rmem_max you need to increase the kernel parameter value:
                  • sudo sysctl -w net.core.rmem_max=851968
                  • ffmpeg -v debug -buffer_size=851968 ...
                    • [udp @ 0x1782280] end receive buffer size reported is 1703936
            • emission (use pkt_size=1316 to allocate 7 TS packets into one IP packet: 188*7=1316 < 1500):
              • ffmpeg -i toto -f mpegts udp://...:port?option1=value1&option2=value2
              • ffmpeg -f video4linux2 -i /dev/video0 -an -s 352x288 -vcodec mpeg2video  -f mpegts udp://172.16.2.146:1234?pkt_size=1316
              • ffmpeg -f video4linux2 -i /dev/video0 -s 352x288 -f mpegts -vcodec libx264 -vpre ultrafast -vpre baseline udp://172.16.2.146:1234?ttl=10&buffer_size=65536&pkt_size=1316
            • RTP
              • Jearquia de streaming / Streaming hierarchy
                • SDP
              • Fragmentation and packet size
                • ffmpeg -f rtp rtp://...?pkt_size=1472
                • headers (bytes)
                  RTP (pkt_size)
                  ethernet IP UDP header
                  payload
                  14
                  20
                  8
                  12
                  1460



                  1472 (default pkt_size)

                  1500 (default MTU for ethernet)
                  1514
                • when streaming to Janus (WebRTC) streaming plugin, the value of pkt_size mut be lower than 1472 (e.g. 1400). Otherwise the addition of headers for SRTP will overpass the MTU limit, and NACKs will appear.
              • No coding (from file)
                • Using SDP with increased buffer_size
                  • transmission (if not specified, buffer_size is 32kB (UDP_TX_BUF_SIZE))
                    • ffmpeg -v debug -protocol_whitelist rtp,udp,file,http,https,tcp,tls,rtmp -re -i bbb_stereo.mp4 -an -c:v copy -f rtp -buffer_size 128k rtp://234.5.6.7:5100 -vn -c:a copy -f rtp -buffer_size 256k rtp://234.5.6.7:5102 -sdp_file bbb_stereo.sdp
                    • with specified RTP packet size (32000 bytes) (not recommended, as network errors imply worse consequences):
                      • ffmpeg -v debug -protocol_whitelist rtp,udp,file,http,https,tcp,tls,rtmp -re -i bbb_stereo.mp4 -an -c:v copy -f rtp -buffer_size 128k rtp://234.5.6.7:5100?pkt_size=32000 -vn -c:a copy -f rtp -buffer_size 256k rtp://234.5.6.7:5102?pkt_size=32000 -sdp_file /mnt/nfs/sdp/bbb.sdp
                  • reception (if not specified, buffer_size is 64kB (UDP_MAX_PKT_SIZE))
                    • ffplay -v debug -protocol_whitelist rtp,udp,file,http,https,tcp,tls,rtmp -buffer_size 256k -i bbb.sdp
              • Coding
                • H.264
                  • ffmpeg -re -f lavfi -i testsrc=size=320x240:r=15 -c:v libx264 -g 15 -profile:v baseline -level 31 -keyint_min 15 -sc_threshold 0 -b:v 1M -pix_fmt yuv420p -f rtp rtp://127.0.0.1:8004 >/tmp/barres_h264.sdp
                • H.264 / AAC
                  • ffmpeg -re -f lavfi -i testsrc=size=320x240:r=15 -f lavfi -i sine=f=440:b=1 -c:v libx264 -profile:v baseline -b:v 1M -pix_fmt yuv420p -an -f rtp rtp://224.1.2.3:8004 -c:a aac -b:a 16k -vn -f rtp rtp://224.1.2.3:8002 >/tmp/barres_h264_aac.sdp
                • VP8 / Opus (e.g. for Janus streaming plugin)
                  • ffmpeg -re -f lavfi -i testsrc=size=320x240:r=15 -f lavfi -i sine=f=440:b=1 -c:v vp8 -b:v 1M -pix_fmt yuv420p -an -f rtp rtp://224.1.2.3:5004 -c:a opus -b:a 16k -vn -f rtp rtp://224.1.2.3:5002 >/tmp/barres_vp8_opus.sdp
              • Specify payload type (pt):
                • ffmpeg ... -f rtp -payload_type 100 rtp://...
              • Specify CNAME, to be included in RTCP SR "Source Description" (SDES) packets:
                • ... -f rtp -cname user123456789@host-87654321 rtp://...
                • Source Description in RTCP packets is needed by gstreamer as an RTP client, to honour RTCP incormation
              • Specify title, to be included in SDP as s=<title>
              • Problemes / Problems
                • Pèrdua de paquets en recepció / Packet loss in reception
                • En recepció / In reception
                  • [h264 @ 0x1795060] co located POCs unavailable
                    • Solució / Solution
                      • ...
                • En transmuxació / Transmuxing
            • RTMP
              • rtmp
              • ffserver accepts RTMP input - can it output to RTMP?
              • from inverted camera to an rtmp server:
                • ffmpeg -f video4linux2 -i /dev/video1 -s 640x480 -f flv -c:v libx264 -profile:v baseline -pix_fmt yuv420p -an -vf "vflip,hflip" -r 30 rtmp://...
              • from file to an rtmp server:
                • ffmpeg -re -i sintel-1024-stereo.mp4 -c:v copy -c:a aac -strict -2 -f
                  flv rtmp://...
              • from an rtmp server:
                • ffmpeg -i rtmp://...
                  • Problemes / Problems
                    • if ffmpeg is not receiving data from the rtmp server (because the process that feeds it has not cleanly terminated), it cannot be terminated (kill -TERM) (see nginx rtmp module)
                      • workaround: send some content to the rtmp server
            • low-latency
            • reception:
              • allow reuse multicast packets (UDP sockets) in reception (see also LIMBOS / mcreflect, Darwin reflector) (if not, only one application per computer will be able to receive the stream):
            • HLS
            • MPEG DASH
          • Problemes / Problems
          • Strange behaviours:
            • frame-rate conversion:
              • ffmpeg -i toto.m2v -r 12.5 toto.h264
                • ffmpeg -i toto.h264: ...12.50 tb(r)
                • vlc plays toto.h264 2x too fast; mplayer plays it correctly
              • ffmpeg -i toto.h264 -vcodec copy -r 12.5 toto.mp4
                • mp4info toto.mp4: ...@25.00 fps
                • vlc and mplayer play toto.h264 2x too fast;
              • ffmpeg -r 12.5 -i toto.h264 -vcodec copy toto_12.5.mp4
                • mp4info toto_12.5.mp4: ...@12.500 fps
                • vlc and mplayer play toto.mp4 correctly
              • ffmpeg -i toto.m2v -r 12.5 toto_direct.mp4
                • mp4info toto_direct.mp4: ...@12.580 fps
                • vlc and mplayer play toto.mp4 correctly
        .

        Subtítols / Subtitles

        Còdecs vídeo / Video codecs


        file ext file (UNIX) MPEG-4 RA FOUR CC license

        used by
        handler codec (1)
        MPEG MPEG-1 part 2







        MPEG-2 part 2
        .m2v MPEG sequence, v2, MP@ML progressive Y'CbCr 4:2:0 video, CCIR/ITU PAL 625, 25 fps


        MP2V

        MPEG-4 part 2: [advanced] simple profile
        .m4v MPEG sequence, v4, video, [advanced] simple vide mp4v MP4V

        part 10: AVC/H.264 .264 JVT NAL sequence, H.264 video
        avc1 AVC1
        FLV,
        F4V,
        ...



        avc2






        avc3 (amdt2)(*)






        svc1



        Apple
        ProRes (wp)








        Avid
        DNxHD (wp)







        Microsoft WMV







        VC-1



        vc-1


        Real Networks RealVideo







        Xiph.org
        Theora (based on VP3)








        BBC
        Dirac (VC-2)




        drac -

        Streambox
        ACT-L3








        Adobe
        Flash Video




        FLV1



        On2 (Google)
        VP3







        Theora
        VP6 (wp)








        with alpha



        VP6A


        FLV
        VP8








        Sorenson
        Sorenson Video /
        SVQ







        QuickTime
        Sorenson Spark /
        H.263







        FLV
        1. As shown by:
          • vlc: Tools / Codec information
          • mplayer: "VIDEO: [xxxx]"
          • (ffmpeg shows "h264" instead of avc1)

        Còdecs àudio / Audio Codecs

        MPEG 1 layer 3 MP3
        2 part 7

        profile enc dec
        AAC LC FAAC FAAD
        MAIN
        SRS / SSR
        LTP
        4 part 3
        4

        enc dec
        HE-AAC / AAC+ - FAAD2
        AAC-SSR

        AAC-LD

        BSAC


        Streaming

        Còdecs d'imatges / Image codecs

        http://www.francescpinyol.cat/formats_av.html
        Primera versió / First version: 3.IV.2006
        Darrera modificació: 13 de desembre de 2018 / Last update: 13th December 2018

        Valid HTML 4.01!

        Cap a casa / Back home.