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
            • codec_tag_string
            • codec_tag
            • video
              • width=1280
                height=720
                coded_width=1280
                coded_height=720
                has_b_frames=0
                sample_aspect_ratio=N/A
                display_aspect_ratio=N/A
                pix_fmt=yuv420p
                level=41
                color_range=unknown
                color_space=unknown
                color_transfer=unknown
                color_primaries=unknown
                chroma_location=left
                field_order=unknown
                timecode=N/A
                refs=1
                is_avc=true
                nal_length_size=4
                id=N/A
                r_frame_rate=60/1
                avg_frame_rate=6312950/218257
                time_base=1/16000
                start_pts=0
                start_time=0.000000
                duration_ts=69842240
                duration=4365.140000
                bit_rate=2490311
                max_bit_rate=N/A
                bits_per_raw_sample=8
                nb_frames=126259
                nb_read_frames=N/A
                nb_read_packets=N/A
                DISPOSITION:default=1
                DISPOSITION:dub=0
                DISPOSITION:original=0
                DISPOSITION:comment=0
                DISPOSITION:lyrics=0
                DISPOSITION:karaoke=0
                DISPOSITION:forced=0
                DISPOSITION:hearing_impaired=0
                DISPOSITION:visual_impaired=0
                DISPOSITION:clean_effects=0
                DISPOSITION:attached_pic=0
                DISPOSITION:timed_thumbnails=0
                TAG:language=und
                TAG:handler_name=VideoHandler
            • audio
              • sample_fmt=fltp
                sample_rate=44100
                channels=1
                channel_layout=mono
                bits_per_sample=0
                id=N/A
                r_frame_rate=0/0
                avg_frame_rate=0/0
                time_base=1/44100
                start_pts=0
                start_time=0.000000
                duration_ts=192504806
                duration=4365.188345
                bit_rate=125588
                max_bit_rate=125588
                bits_per_raw_sample=N/A
                nb_frames=187993
                nb_read_frames=N/A
                nb_read_packets=N/A
                DISPOSITION:default=1
                DISPOSITION:dub=0
                DISPOSITION:original=0
                DISPOSITION:comment=0
                DISPOSITION:lyrics=0
                DISPOSITION:karaoke=0
                DISPOSITION:forced=0
                DISPOSITION:hearing_impaired=0
                DISPOSITION:visual_impaired=0
                DISPOSITION:clean_effects=0
                DISPOSITION:attached_pic=0
                DISPOSITION:timed_thumbnails=0
                TAG:language=und
                TAG:handler_name=SoundHandler
            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 information:
              • ffprobe -v 0 -show_entries frame=coded_picture_number,pict_type,pkt_size -select_streams 0:8 794.ts
            • pts and image type:
              • ffprobe -show_entries frame=pkt_pts_time,pict_type -print_format compact=nk=1:p=0:s='\ ' -select_streams v:0 -i toto.mp4 >data_pts_type.dat
              • get only information about I-type images:
                • grep I data_pts_type.dat >data_pts_i.dat
              • gnuplot distance between two consecutive I-frames:
                • i_distance.plot
                  • delta_v(x) = ( vD = x - old_v, old_v = x, vD)
                    old_v = 0
                    set title "Delta time between consecutive I frames"
                    set boxwidth 1
                    set style fill solid 1.0
                    set style data boxes
                    plot 'data_pts_i.dat' using 1:(delta_v($1)) title 'Delta'
                • gnuplot -p i_distance.plot
        • 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=#
        • parse from json format
          • info_json=$(ffprobe -v 0 -print_format json -show_entries stream ${input_path})
            • video_stream=$(echo "${info_json}" | jq '.streams[] | select(.codec_type=="video")')
              • width=$(echo "${video_stream}" | jq '.width')
              • height=$(echo "${video_stream}" | jq '.height')
              • pix_fmt=$(echo "${video_stream}" | jq -r '.pix_fmt')
              • r_frame_rate=$(echo "${video_stream}" | jq -r '.r_frame_rate')
            • audio_stream=$(echo "${info_json}" | jq '.streams[] | select(.codec_type=="audio")')
              • sample_rate=$(echo "${audio_stream}" | jq -r '.sample_rate')
              • channels=$(echo "${audio_stream}" | jq '.channels')
        • ect_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)
          • ffplot
          • 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
  • TSDuck
    • TSDuck is also a large library to manipulate MPEG transport streams. C++, Java and Python developers can use bindings in their languages.
  • 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)
    • 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
    • Info
    • Docs
      • Documentation
      • All documentation
      • Filter documentation
      • wiki
        • Acceleració per maquinari / Hardware acceleration
          • HWAccelIntro
          • Usage
            • Detection
              • check whether ffmpeg has been compiled with nvenc support:
                • ffmpeg -codecs | grep nvenc
              • check whether ffmpeg has been compiled with nvenc support and system allows usage of nvenc:
                • ffmpeg -f lavfi -i nullsrc -c:v h264_nvenc -t 00:00:00 -f null /dev/null
                  • all ok (exit with 0)
                    • Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
                  • ffmpeg has not been compiled with cuda (exit with 1)
                    • Unknown encoder 'h264_nvenc'
                  • system is not able to deal with cuda (exit with 1)
                    • [h264_nvenc @ 0x762c00] dl_fn->cuda_dl->cuInit(0) failed -> CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
                • echo $?
                • example script:
                  • #!/bin/bash

                    function is_ffmpeg_nvenc_available {
                        # check whether ffmpeg has h264_nvenc coder and system is able to use it
                        ffmpeg -f lavfi -i nullsrc -c:v h264_nvenc -t 00:00:00 -f null /dev/null 1>/dev/null 2>&1
                        result=$?
                       
                        if ! (( result ))
                        then
                            # ffmpeg works ok
                            echo 1
                        else
                            # ffmpeg exits with 1 (error)
                            echo 0
                        fi
                    }

                    nvenc_available=$(is_ffmpeg_nvenc_available)

                    echo "nvenc_available: ${nvenc_available}"
            • Encoding
              • ffmpeg -y -f lavfi -i "testsrc=duration=20:size=1920x1080, format=pix_fmts=yuv420p" -f lavfi -i anoisesrc=duration=10:colour=pink:amplitude=0.5 -ac 2 -c:v h264_nvenc toto_nvenc.mp4
              • ffmpeg -f lavfi -i nullsrc -c:v h264_nvenc -gpu list -f null -
            • Decoding
              • ffmpeg -hwaccel cuda -i toto.mp4
            • Filtering
          • Output from ./configure
            system info






            vdpauinfo


            Mageia dependencies
            nv-codec-headers ? libvdpau-devel libva-devel lib64omxil-bellagio-devel
            CentOS/Alma/Rocky dependencies
            nv-codec-headers





            Debian/Raspbian dependencies









            libomxil-bellagio-dev
            provided pkg-config


            ffnvcodec






            auto-detect (no need to specify --enable-...)






            --enable-vdpau --enable-vaapi --enable-omx --enable-omx-rpi
            External libraries providing
            hardware acceleration:
            • ffmpeg -hwaccels

            cuda cuvid ffnvcodec nvdec nvenc v4l2_m2m vdpau vaapi omx
            Enabled decoders AV1










            H.263




            h263_v4l2m2m




            H.264
            h264_cuvid


            h264_v4l2m2m




            HEVC
            hevc_cuvid


            hevc_v4l2m2m




            MJPEG
            mjpeg_cuvid








            MPEG-1
            mpeg1_cuvid


            mpeg1_v4l2m2m




            MPEG-2
            mpeg2_cuvid


            mpeg2_v4l2m2m




            MPEG-4
            mpeg4_cuvid


            mpeg4_v4l2m2m




            VC1
            vc1_cuvid


            vc1_v4l2m2m




            VP8
            vp8_cuvid


            vp8_v4l2m2m




            VP9
            vp9_cuvid


            vp9_v4l2m2m



            Enabled hwaccels
            • ./configure --list-hwaccels
            AV1


            av1_nvdec


            av1_vaapi


            H.263






            h263_vaapi


            H.264


            h264_nvdec

            h264_vdpau h264_vaapi


            HEVC


            hevc_nvdec

            hevc_vdpau hevc_vaapi


            MJPEG


            mjpeg_nvdec


            mjpeg_vaapi


            MPEG-1


            mpeg1_nvdec

            mpeg1_vdpau



            MPEG-2


            mpeg2_nvdec

            mpeg2_vdpau mpeg2_vaapi


            MPEG-4


            mpeg4_nvdec

            mpeg4_vdpau mpeg4_vaapi


            VC1


            vc1_nvdec

            vc1_vdpau vc1_vaapi


            VP8


            vp8_nvdec


            vp8_vaapi


            VP9


            vp9_nvdec

            vp9_vdpau vp9_vaapi


            WMV3


            wmv3_nvdec

            wmv3_vdpau wmv3_vaapi

            Enabled encoders H.263




            h263_v4l2m2m




            H.264



            h264_nvenc, nvenc_h264 h264_v4l2m2m
            h264_vaapi h264_omx


            HEVC



            hevc_nvenc, nvenc_hevc hevc_v4l2m2m
            hevc_vaapi


            MJPEG






            mjpeg_vaapi


            MPEG-1










            MPEG-2






            mpeg2_vaapi


            MPEG-4




            mpeg4_v4l2m2m

            mpeg4_omx


            VP8




            vp8_v4l2m2m




          • configure option
            (./configure --list-hwaccels)
            codecs

            libav
            ffmpeg
            mjpeg mpeg1 mpeg2
            mpeg4
            h263
            h264
            hevc vc1
            vp8 vp9 wmv3

            --disable-dxva2






            x





            CUDA

            x x x x
            x x x x x x
            OpenMAX --enable-omx
            --enable-omx-rpi













            v4l2_m2m


            d d ed ed ed
            d


            VA API
            --enable-vaapi
            [--enable-vaapi]
            --enable-hwaccel=h264_vaapi
            x
            x
            x
            x
            x
            x x
            x x x
            VDA
            --enable-vda
            --enable-hwaccel=h264_vda




            x





            VDPAU
            --enable-hwaccel=h264_vdpau
            x x
            x

            x
            x x


            x
        • Creating multiple outputs
          • ... -f tee -flags +global_header -map 0:v -map 0:a "[...]...|[...]..."
          • Problemes / Problems
          • Examples:
            • 1 transcoding and 2 output muxers: HLS + RTMP
              • ffmpeg -i ... \
                -c:a ... -c:v ... \
                -f tee -flags +global_header -map 0:v -map 0:a \
                "[hls_time=2:hls_list_size=0:hls_wrap=0:start_number=1]toto.m3u8|[f=flv]rtmp://localhost:1935/..."
            • 2 transcodings: one with HLS+RTMP, the other one with HLS+SAP
              • ffmpeg -i ... \
                -vsync vfr -c:v h264 -preset medium -b:v 1000000 -vf scale=w=720:h=576 -g 25 -profile:v main -level 30 -keyint_min 25 -sc_threshold 0 \
                -c:a aac -strict -2 -b:a 128000 -ac 2 \
                -f tee -flags +global_header -map 0:v -map 0:a \
                "[hls_time=2:hls_list_size=0:hls_wrap=0:start_number=1]sd.m3u8|[f=flv]rtmp://localhost:1935/sd/..." \
                -vsync vfr -c:v h264 -preset medium -b:v 2000000 -vf scale=w=1280:h=720 -g 25 -profile:v high -level 31 -keyint_min 25 -sc_threshold 0 \
                -c:a aac -strict -2 -b:a 128000 -ac 2 \
                -f tee -flags +global_header -map 0:v -map 0:a \
                "[hls_time=2:hls_list_size=0:hls_wrap=0:start_number=1]hd.m3u8|[f=sap]sap://234.1.2.3" \
        • How to speed up / slow down a video time lapse, etc.
        • Option '-sameq' does NOT mean 'same quality'
        • How to take multiple screenshots to an image (tile, mosaic)
        • Create a mosaic out of several input videos
        • Filtering guide
      • options
      • more options
      • ffmpegX options
    • 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
      • list of available filters:
        • ffmpeg -filters
      • audio
        • ffmpeg -filter:a ...
        • ffmpeg -af ...
        • show information (see also showinfo for video)
        • (?) ffmpeg -i esports3.mp4 -filter:a aformat=sample_fmts=s16 ...
        • aresample
      • video
        • ffmpeg -filter:v ...
        • ffmpeg -vf ...
        • show information (see also ashowinfo for audio) (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):
          • ffmpeg -vf ...overlay...
          • ffmpeg -i ${video_src} -i ${logo_src} \
                   -filter_complex "[0:v]scale=320:-1[output]; [1:v][output]scale2ref=iw/8:-1[logo][output]; [output][logo]overlay=main_w/10:main_h/10[output]" -map "[output]" -map 0:a -c:v h264 -c:a aac -f tee "[f=mp4]output1_tl.mp4|[f=mpegts]output1_tl.ts" \
                   -filter_complex "[0:v]scale=640:-1[output]" -map "[output]" -map 0:a -c:v h264 -c:a aac -f tee "[f=mp4]output2.mp4"
        • display subtitles
          • dep
            • Mageia
              • urpmi libass-devel
          • ./configure ... --enable-libass
          • ffmpeg -vf 'subtitles'
        • scale (resize)
        • 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
                • sudo dnf install google-droid-sans-fonts
                  • fontfile=/usr/share/fonts/google-droid/DroidSansMono.ttf
                  • fontfile=/usr/share/fonts/google-droid-sans-fonts/DroidSans.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
                  • fontfile=/usr/share/fonts-droid-fallback/truetype/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
            • referenced variables



              • w width
                h

                text_w, tw




                line_h, lh

            • 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://...
            • timecode and present time, with audio, to 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
            • compte enrere / countdown
              • input=input.mp4
                duration=$(ffprobe -loglevel error -show_entries format=duration -of default=nw=1:nk=1 "$input")
                ffplay -f lavfi -i "color=color=DarkGray:size=1280x720:duration=${duration}" -vf "drawtext=fontfile=${fontfile}: text='%{eif\:$duration-t\:d}': x=(w-tw)/2: y=(h-lh)/2: fontcolor=white: fontsize=h/2"
          • Dynamic text
        • 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)
        • methods:



          concat demuxer
          ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav
          all files must have the same muxer and coders
          concat protocol
          ffmpeg -i "concat:input1.ts|input2.ts|input3.ts" -c copy output.ts

          concat filter
          ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \ -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \ -map "[outv]" -map "[outa]" output.mkv
        • ffmpeg: adding blankspace to end of video
        • concat demux
          • e.g. to preprend a preroll
            • create a preroll with the same parameters as main video:
              • /usr/local/bin/ffmpeg -y -f lavfi -i "pal75bars=duration=2.0:size=1280x720:r=25/1, format=pix_fmts=yuv420p" -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=44100" -c:v h264 -profile:v Main -ac 2 -c:a aac -video_track_timescale 25000 /tmp/toto.mp4
            • create a file with a playlist: input.txt
              • file ...
                file ...
            • play it
              • ffplay -f concat -safe 0 -i input.txt
        • Concat filter
          • Does not accept -c copy
          • ffmpeg -f lavfi -i "pal75bars=duration=3:size=640x360, format=pix_fmts=yuv420p" -f lavfi -i "anoisesrc=duration=3:colour=white:amplitude=0.2" -i toto.mp4 -filter_complex '[0:v:0][1:a:0][2:0][2:1] concat=n=2:v=1:a=1 [outv] [outa]' -map "[outv]" -map "[outa]" tutu.mp4
        • 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
              • ...
          • untrunc fork
            • anthwlock / untrunc
            • Compilació / Compilation
              • get the code from git
                • git clone https://github.com/anthwlock/untrunc.git untrunc_anthwlock
                • cd untrunc_anthwlock
              • compile
                • make FF_VER=4.2.3
              • ...
    • 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 ...
      • No B-frames
        • ffmpeg ... -bf 0 ...
    • 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 1 -i toto.png -f lavfi -i "sine=frequency=440:sample_rate=48000,aformat=channel_layouts=stereo" -vf "setdar=dar=16/9" -t 10 -pix_fmt yuv420p -c:v h264 -c:a aac toto_169.mp4
          • ffmpeg -loop 1 -i PM5544_with_non-PAL_signals.png -f lavfi -i "sine=frequency=440:sample_rate=48000,aformat=channel_layouts=stereo" -filter:v "scale=w=720:h=576,setdar=dar=4/3" -t 10 -pix_fmt yuv420p -c:v h264 -c:a aac pm5544.mp4
          • ffmpeg -loop 1 -i Philips_Pattern_pm5644.png -f lavfi -i "sine=frequency=440:sample_rate=48000,aformat=channel_layouts=stereo" -filter:v "scale=w=720:h=576,setdar=dar=16/9" -t 10 -pix_fmt yuv420p -c:v h264 -c:a aac pm5644.mp4
          • 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)
      • WebP
      • 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
      • input image output image satisfy only one destination dimension


        satisfy both destination dimensions


        width height inscribe excribe adapted pad


        • -vf "scale=${width}:-1"
        • # force height to be multiple of 2
          -vf "scale=${width}:-2"
        • -vf "scale=-1:${height}"
        • # force width to be multiple of 2
          -vf "scale=-2:${width}"
        • -vf "scale=${width}:${height}:force_original_aspect_ratio=decrease"
        • # force dimensions to be multiple of 2 (using pad)
          -vf "scale=${width}:${height}:force_original_aspect_ratio=decrease, pad='iw+mod(iw\,2)':'ih+mod(ih\,2)'"
        • # force dimensions to be multiple of 2 (a recent version of ffmpeg is needed)
          -vf "scale=${width}:${height}:force_original_aspect_ratio=decrease:force_divisible_by=2"
        -vf "scale=${width}:${height}:force_original_aspect_ratio=increase" -vf "scale=${width}:${height}"
        • this is the most generic solution to automatically add pillarbox or letterbox
        • first, we calculate the video region
          • min is used to allow pillarbox or letterbox
          • dar must be taken into account
          • output dar must be calculated offline, because ffmpeg does not do it (only for input dar)
          • ...
        • then we put the video on centre and pad it with black
          • pad=${out_width}:${out_height}:-1:-1
        • out_width=720
          out_height=576
          out_dar="4:3"
          out_dar_bar=${out_dar//:/\/}
          out_dar_float=$(echo "${out_dar_bar}" | bc -l)
          ffmpeg -y -v verbose -i ${input} -vf "scale=min(${out_width}\,trunc(${out_width}*dar/${out_dar_float}+0.5)):min(${out_height}\,trunc(${out_height}*${out_dar_float}/dar+0.5)), pad=${out_width}:${out_height}:-1:-1" ${output}
        pal_43
        PAL
        720x576, 4:3
        768x576 4:3 -vf "scale=768:-1"
        -> 768x614, 4:3
        (ok, but too high)
        -vf "scale=-1:576"
        -> 720x576, 4:3 (ok)
        -vf "scale=768:576:force_original_aspect_ratio=decrease"
        -> 720x576, 4:3 (ok)
        -vf "scale=768:576:force_original_aspect_ratio=increase"
        -> 768x614, 4:3 (ok, but too high)
        -vf "scale=768:576"
        -> 768x576, 4:3 (ok)


        1024x576
        16:9







        PAL anamorphic
        720x576, 16:9





        • -vf "scale=540:576, pad=720:576:-1:-1"
          -> 720x576, 16:9

        1280x720 16:9 -vf "scale=1280:-1"
        -> 1280x1024, 4:3
        (ok, but too high)
        -vf "scale=-1:720"
        -> 900x720, 4:3 (ok)
        -vf "scale=1280:720:force_original_aspect_ratio=decrease"
        -> 900x720, 4:3 (ok)
        -vf "scale=1280:720:force_original_aspect_ratio=increase"
        -> 1280*1024, 4:3 (ok, but too high)


        pal_169_anamorphic
        PAL anamorphic
        720x576, 16:9
        1024x576 16:9

        -vf "scale=1024:576:force_original_aspect_ratio=decrease"
        -> 720x576, 16:9 (ok, still anamorphic)

        -vf "scale=1024:576"
        -> 1024x576, 16:9 (ok)


        PAL
        720x576, 4:3







        1280x720 16:9 -vf "scale=1280:-1"
        -> 1280x1024, 4:3
        (ok, but too high)
        -vf "scale=-1:720"
        -> 900x720, 16:9 (ok, still anamorphic)
        -vf "scale=1280:720:force_original_aspect_ratio=decrease"
        -> 900x720, 16:9 (ok, still anamorphic)



        1280x720, 16:9 PAL
        720x576, 4:3






        1280x720, 16:9 PAL anamorphic
        720x576, 16:9






      • Variables
        • input description output
          in_w
          iw
          width out_w
          ow
          in_h
          ih
          height out_h
          oh
          a = (iw/ih) relation
          sar sample aspect ratio
          dar = (iw/ih)*sar display aspect ratio
      • vegeu pad amb libav / see simplified pad with libav
      • scale filter preserving aspect ratio:
        • "The scale filter forces the output display aspect ratio to be the same of the input, by changing the output sample aspect ratio."
        • force width:
          • ffmpeg ... -vf scale=320:-1...
        • force width, but height has to be multiple of n=2 (n can be any value):
          • ffmpeg ... -vf scale=320:-2...
        • inscribe into a maximum rectangle (*):
          • Resizing videos with ffmpeg/avconv to fit into static sized player
          • ffmpeg ... -vf "scale=w=854:h=480:force_original_aspect_ratio=decrease" ...
            • to force multiple of n (a recent version of ffmpeg is needed):
              • ... -vf "scale=320:h=180:force_original_aspect_ratio=decrease:force_divisible_by=2" ...
            • to force multiple of 2 using pad:
              • ... -vf "scale=320:h=180:force_original_aspect_ratio=decrease, pad='iw+mod(iw\,2)':'ih+mod(ih\,2)'" ...
            • to force output aspect (setdar=dar) to the same as input aspect (=dar):
              • ... setdar=dar=dar:max=16 ...
            • complete example:
              • ffmpeg -y  -f lavfi -i "testsrc=duration=10:size=720x576, format=pix_fmts=yuv420p" -f lavfi -i anoisesrc=duration=10:colour=pink:amplitude=0.5 -ac 2 -aspect 4:3 vídeo_43.mp4
                ffmpeg -i vídeo_43.mp4 -vf "scale=320:h=180:force_original_aspect_ratio=decrease, pad='iw+mod(iw\,2)':'ih+mod(ih\,2)', setdar=dar=dar:max=16" -c:a copy video_43_petit.mp4
              • ffmpeg -y  -f lavfi -i "testsrc=duration=10:size=720x576, format=pix_fmts=yuv420p" -f lavfi -i anoisesrc=duration=10:colour=pink:amplitude=0.5 -ac 2 -aspect 16:9 vídeo_169.mp4
                ffmpeg -i vídeo_169.mp4 -vf "scale=320:h=180:force_original_aspect_ratio=decrease, pad='iw+mod(iw\,2)':'ih+mod(ih\,2)', setdar=dar=dar:max=16" -c:a copy video_169_petit.mp4
          • 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 ...
        • # 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
        • ...
      • pad video filter
        • output sar is the same as input sar; dar may change according to this
        • 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'
          • ...
        • center
          • ... pad=1280:720:-1:-1
      • 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
        14:9
        16:9








        720x576 768x576 720x576 896x576 720x576 1024x576 1280x720 1920x1080 3840x2160
        dar size sar name create with ffmpeg 16:15 1:1 56:45 1:1 64:45 1:1 1:1 1:1 1:1
        4:3 720x576 16:15 PAL -f lavfi -i "testsrc=duration=10:size=720x576, format=pix_fmts=yuv420p" -aspect 4:3 video_720x576_43.mp4








        768x576 1:1
        -f lavfi -i "testsrc=duration=10:size=768x576, format=pix_fmts=yuv420p" video_768x576_43.mp4








        14:9 720x576 56:45 PAL 14:9 -f lavfi -i "testsrc=duration=10:size=720x576, format=pix_fmts=yuv420p" -aspect 14:9 video_720x576_149.mp4








        896x576 1:1
        -f lavfi -i "testsrc=duration=10:size=896x576, format=pix_fmts=yuv420p" video_896x576_149.mp4








        16:9 720x576 64:45 PAL anamorphic -f lavfi -i "testsrc=duration=10:size=720x576, format=pix_fmts=yuv420p" -aspect 16:9 video_720x576_169.mp4









        1024x576 1:1
        -f lavfi -i "testsrc=duration=10:size=1024x576, format=pix_fmts=yuv420p" video_1024x576_169.mp4









        1280x720 1:1 720 -f lavfi -i "testsrc=duration=10:size=1280x720, format=pix_fmts=yuv420p" video_1280x720_169.mp4









        1920x1080 1:1 1080 -f lavfi -i "testsrc=duration=10:size=1920x1080, format=pix_fmts=yuv420p" video_1920x1080_169.mp4









        3840x2160 1:1 4K, UHD -f lavfi -i "testsrc=duration=10:size=3840x2160, format=pix_fmts=yuv420p" video_3840x2160_169.mp4












      • 4:3
        16:9
        720x576 720x576
        4:3
        720x576
        -
        • -vf "scale=540:576, pad=720:576:-1:-1"
        • -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
        • -vf "scale=630:576, pad=720:576:-1:-1"
        • -s 630x576 -padleft 44 -padright 46 -aspect 16:9
        896x576
        16:9
        720x576
        -s 720x432
        -padtop 72 -padbottom 72
        -aspect 4:3
        -
        1024x576
        • -vf "scale=720:576"
        • -s 720x576 -aspect 16:9



      • 4:3 16:9
        dar
        sar 720x576 (out_sar=16/15) 720x576 (out_sar=64/45)
        4:3 720x576 16:15 -
        • -vf "scale=540:576, pad=720:576:-1:-1"
        768x576 1:1
        • -vf "scale=720:576"
        • -s 720x576 -aspect 4:3

        14:9 720x576 56:45
        • -vf "scale=..."
        • -s 720x492 -padtop 42 -padbottom 42 -aspect 4:3
        • -vf "scale=630:576, pad=720:576:-1:-1"
        896x576 1:1
        16:9 720x576 64:45
        • -vf "..."
        • -s 720x432 -padtop 72 -padbottom 72 -aspect 4:3
        -
        1024x576 1:1
        • -vf "scale=720:576"
        • -s 720x576 -aspect 16:9
        NOTE: scale preserves dar; pad preserves sar
      • Parameter calculation:
        • intermediate_width = in_width * (in_sar) / (out_sar) * out_height / in_height = in_dar / out_dar * out_width 
          • examples:
            • 720 * (16/15) / (64/45) = 540
            • 720 * (56/45) / (64/45) = 630
        • intermediate_height = in_height * (out_sar) / (in_sar) * out_width / in_width = out_dar / in_dar * out_height
          • examples:
            • ...
      • 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
    • Tall / Cut
      • -t <duration>
      • -to <position>
      • Obté un tall de 10 segons a partir de la posició 00:02:00.0
        • ffmpeg -ss 00:02:00.0 -t 00:00:10.0 -i toto.mp4 -c copy tall_00:02:00.0-00:02:10.0.mp4
        • ffmpeg -ss 00:02:00.0 -i toto.mp4 -t 00:00:10.0 -c copy tall_00:02:00.0-00:02:10.0.mp4
      • Obté un tall que va dels 00:02:00.0 als 00:02:20.0
        • ffmpeg -ss 00:02:00.0 -to 00:02:20.0 -i toto.mp4 -c copy tall_00:02:00.0-00:02:20.0.mp4
        • If you put -to option after -i option, you will get a file with duration 00:02:20.0, as -to position will be referred to the output
    • 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
    • Àudio / Audio
      • Multicanal / Multichannel
        • Manipulating audio channels
        • 2.8 Channel layout
        • Text to speech
          • flite -v -voice slt -t "left channel" FL.wav
        • Dolby ProLogic II
        • two mono audios in a stereo track (and a video stream)
          • ffmpeg \
            -f lavfi -i "pal75bars=duration=2.0:size=640x360:r=25/1, format=pix_fmts=yuv420p" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -c:v h264 \
            -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" \
            -c:a aac \
            -map 0:v -map "[a]" \
            video_stereo.mp4
          • ffmpeg \
            -f lavfi -i "pal75bars=duration=2.0:size=640x360:r=25/1, format=pix_fmts=yuv420p" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -c:v h264 \
            -filter_complex "[1:a][1:a]join=inputs=2:channel_layout=stereo[a]" \
            -c:a aac \
            -map 0:v -map "[a]" \
            video_stereo.mp4
        • six mono audios in a 5.1 track (and a video stream)
          • ffmpeg \
            -f lavfi -i "pal75bars=duration=2.0:size=640x360:r=25/1, format=pix_fmts=yuv420p" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -c:v h264 \
            -filter_complex "[1:a][2:a][3:a][4:a][5:a][6:a]join=inputs=6:channel_layout=5.1[a]" \
            -c:a aac \
            -map 0:v -map "[a]" \
            video_5_1.mp4
          • ffmpeg \
            -f lavfi -i "pal75bars=duration=2.0:size=640x360:r=25/1, format=pix_fmts=yuv420p" \
            -f lavfi -i "anoisesrc=duration=2.0:colour=pink:amplitude=0.5:sample_rate=48000" \
            -c:v h264 \
            -filter_complex "[1:a][1:a][1:a][1:a][1:a][1:a]join=inputs=6:channel_layout=5.1[a]" \
            -c:a aac \
            -map 0:v -map "[a]" \
            video_5_1.mp4
    • Sincronització àudio/vídeo / Audio/video synchronisation
    • Subtítols / Subtitles
      • llista de còdecs de subtítols suportats / list of supported subtitle codecs:
        • ffmpeg -codecs | grep "^...S"
      • extract subtitles
      • inclusió de subtítols / include subtitles
        • els colors per a diferents personatges es mantenen / colours for different characters in webvtt subtitles are preserved:
          • ffmpeg -i input.mp4 -i subtitles.ca.vtt -c copy -metadata:s:s:0 language=cat ouptut_cat.mkv
        • els colors per a diferents personatges no es mantenen / colours for different characters in webvtt subtitles are not preserved:
          • ffmpeg -i input.p4 -i subtitles.ca.vtt -c copy -c:s mov_text -metadata:s:s:0 language=cat ouptut_cat.mp4
      • 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 must 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 with default example janus.plugins.streaming.cfg.sample.in)
            • 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 -payload_type 100 rtp://224.1.2.3:5004 -c:a opus -b:a 16k -vn -f rtp -payload_type 111 rtp://224.1.2.3:5002 -sdp_file /tmp/barres_vp8_opus.sdp
            • 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)
                • workarounds:
                  • kill -TERM again
                  • 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ó: 21 de juny de 2023 / Last update: 21st June 2023

Valid HTML 4.01!

Cap a casa / Back home.