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}"
            • Decoding and encoding

              ffplay ffmpeg
              decoding
              • -vcodec h264_cuvid
              • -c:v h264_cuvid
              • -hwaccel cuda
              • -c:v h264_cuvid
              encoding -
              • -c:v h264_nvenc
            • Decoding
              • ffmpeg -h decoder=h264_cuvid
              • ffplay -vcodec h264_cuvid toto.mp4
              • ffmpeg -hwaccel cuda -i toto.mp4 ...
            • Encoding
              • ffmpeg -h encoder=h264_nvenc
              • 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 -
            • Transcoding
              • ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input -c:v h264_nvenc -preset slow output
            • Filtering
          • Output from ./configure when compiling
            system info



            vdpauinfo


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





            Debian/Raspbian dependencies






            libomxil-bellagio-dev
            provided pkg-config







            auto-detect (no need to specify --enable-...)
            ffnvcodec
            x
            [--enable-vdpau] --enable-vaapi --enable-omx --enable-omx-rpi
            External libraries providing
            hardware acceleration:
            • ffmpeg -hwaccels
              • Hardware acceleration methods:

            cuda





            codec suffix
            (ffmpeg -codecs, ./configure --list-hwaccels)

            cuvid, nvenc nvdec v4l2_m2m vdpau vaapi omx
            Possible hwaccels (decoders?)
            ./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 decoders
            • ffmpeg -codecs
            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 encoders
            • ffmpeg -codecs
            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}
      • -hide_banner
    • 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 (v<6) / -fpsmax (v≥6)
      • -vsync (v<6) / -fps_mode (v≥6)
        • 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
        • one mono audio on left channel, silence on right channel:
          • 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 "anullsrc=duration=2.0:sample_rate=48000:channel_layout=mono" \
            -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
        • 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
      • Mesures / Measurements
        • altres
        • ebur128
        • volumedetect
          • general levels
            • ffmpeg -hide_banner -i toto.mp4 -filter:a "volumedetect" -f null /dev/null
          • levels only from left channel
            • ffmpeg -hide_banner -i toto.mp4 -filter:a "pan=mono|c0=FL,volumedetect" -f null /dev/null
            • mean_volume=$(ffmpeg -hide_banner -i toto.mp4 -filter:a "pan=mono|c0=FL,volumedetect" -f null /dev/n 2>&1 | awk '/mean_volume/ {print $5}')
          • levels only from right channel
            • ffmpeg -hide_banner -i toto.mp4 -filter:a "pan=mono|c0=FR,volumedetect" -f null /dev/null
        • ...
      • VU-meter
        • ffmpeg -hide_banner -i toto.mp4 -filter_complex "showvolume=rate=30:f=0.95:o=h:m=p:dm=1:h=60:w=480:ds=log:s=2" -c:v libx264 -c:a aac -f mpegts - | ffplay -window_title "Peak Volume" -i -
    • 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://...
        • RTCP
          • Specify CNAME in both streams (audio and video), to be included in RTCP SR "Source Description" (SDES) packets:
        • 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

libav / ffmpeg compilation on Linux

  • See also GPAC compilation
  • How-To Build FFmpeg on Debian Squeeze
  • Dependencies
    • General
      • Mageia
        • 64 bits (x86_64)
          • urpmi glibc-devel libstdc++-devel gcc lib64SDL-devel lib64sdl2.0-devel lib64raw1394-devel lib64dc1394-devel lib64gsm-devel lib64speex-devel lib64zlib-devel yasm
        • 32 bits
          • urpmi libSDL-devel libdc1394-devel libgsm-devel libspeex-devel zlib-devel yasm
      • Mandriva:
        • urpmi libSDL-devel libdc1394-devel libgsm-devel libspeex-devel zlib1-devel yasm
      • Ubuntu
        • 32/64 bits
          • sudo apt-get install gcc make yasm
      • CentOS
        • CentOS 8
          • sudo dnf -y install epel-release
          • sudo dnf config-manager --set-enabled powertools
          • sudo dnf -y install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
        • CentOS 7
          • sudo yum install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
        • sudo yum install gcc make yasm
    • Specific

      • ffmpeg
        dependencies
        configure
        src Mageia
        Ubuntu
        CentOS / Alma

        --enable-gpl --enable-nonfree
        32-bit
        64-bit


        general






        gcc make yasm
        lib64freetype6-devel
        lib64freetype2-devel
        gcc make yasm gcc make yasm
        ffplay

        [--disable-ffplay]



        libsdl2.0-devel
        lib64sdl2.0-devel


        tls
        --enable-openssl




        libssl-dev openssl-devel
        pulse audio
        --enable-libpulse




        libpulse-dev pulseaudio-libs-devel
        audio codecs

        MP3
        --enable-libmp3lame


        liblame-devel lib64lame-devel
        lib64mp3lame-devel
        libmp3lame-dev lame-devel
        AAC
        (native)







        --enable-libvo-aacenc


        libvo-aacenc-devel lib64vo-aacenc-devel libvo-aacenc-dev
        --enable-libfaac
        x

        libfaac-devel


        --enable-libfdk-aac
        x
        fdk-aac
        lib64fdk-aac-devel
        libfdk-aac-dev
        fdk-aac-devel
        AAC+
        --enable-libaacplus







        --enable-libfdk-aac
        x




        fdk-aac-devel
        HE-AAC
        --enable-libfdk-aac
        x




        fdk-aac-devel
        Opus
        --enable-libopus




        lib64opus-devel

        opus-devel
        Vorbis




        libvorbis-devel

        libvorbis-devel
        video codecs
        AV1








        Dirac
        --enable-libschroedinger


        libdirac-devel
        libschroedinger-devel
        lib64dirac-devel
        lib64schroedinger-devel
        libschroedinger-dev
        Theora
        --enable-libtheora


        libtheora-devel lib64theora-devel libtheora-dev libtheora-devel
        VPX (VP8, VP9)
        --enable-libvpx

        libvpx
        libvpx-devel lib64vpx-devel libvpx-dev libvpx-devel
        H.264 / AVC
        --enable-libx264 x

        x264 libx264-devel lib64x264-devel libx264-dev x264-devel
        H.265 / HEVC
        --enable-libx265

        x265


        x265-devel
        Xvid
        --enable-libxvid x


        libxvid-devel lib64xvid-devel
        lib64xvidcore-devel

        libxvidcore-dev
        image
        JPEG




        jpeg-devel



        JPEG 2000
        --enable-libopenjpeg



        libopenjpeg-devel lib64openjpeg-devel

        PNG




        libpng-devel


        WebP --enable-libwebp



        lib64webp-devel
        libwebp-dev
        libwebp-devel
        filters
        drawtext
        --enable-libfreetype [--enable-fontconfig]







        subtitles
        --enable-libass






        transport
        https
        --enable-openssl

        x






        SRT --enable-libsrt

        srt



        muxers DASH --enable-demuxer=dash --enable-libxml2






        hardware acceleration
        ./configure --list-hwaccels
        CUDA [--enable-cuvid]
        (auto enabled if devel libraries are installed)


        ffnvcodec
        nv-codec-headers (ffnvcodec)

        nvenc [--enabled-nvenc] (auto enabled)

        ffnvcodec
        nv-codec-headers (ffnvcodec) libffmpeg-nvenc-dev
        nv-codec-headers
        VDPAU (Nvidia) [--enable-vdpau] (auto enabled if devel libraries are installed)



        lib64vdpau-devel

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




        ...

        v4l M2M








        VA API (Intel) [--enable-vaapi]
        (auto enabled if devel libraries are installed)




        lib64va-devel

      • ffmpeg >= 0.6.1:
        • urpmi tetex-texi2html libjack-devel libvpx-devel jpeg-devel libpng-devel bzip2-devel rtmp-devel vdpau-devel libva-devel libfaad2-devel opencore-amr-devel [x264-devel]
  • Baixada / Download
    • ffmpeg
      • releases
        • version="4.2.3"
          wget http://ffmpeg.org/releases/ffmpeg-${version}.tar.gz
          tar xvf ffmpeg-${version}.tar.gz
      • development (git repository):
        • git clone git://git.ffmpeg.org/ffmpeg.git (git clone git://github.com/FFmpeg/FFmpeg.git ffmpeg)
          • libvpx-decoder >=0.9.1
          • libx264 >= 0.99 (/usr/include/x264.h: #define X264_BUILD 99)
    • libav
      • versions
        • 9.8
          • wget http://www.libav.org/releases/libav-9.8.tar.gz
        • 0.8.7
          • wget http://www.libav.org/releases/libav-0.8.7.tar.gz
      • development (git repository):
        • first time:
          • git clone git://git.libav.org/libav.git libav
        • cd libav
        • not the first time:
          • git pull
  • Dependències
    • x264
    • x265
    • ffnvcodec
      • Mageia 9
        • version provided by package nv-codec-headers is 11.1.5.2, not valid for ffmpeg compilation
        • use git version instead
      • git clone https://github.com/FFmpeg/nv-codec-headers.git
      • cd nv-codec-headers
      • checkout version that matches installed cuda version
        • git checkout n11.1.5.3
      • sudo make install
      • IMPORTANT: before compiling ffmpeg:
        • export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
      • pkg-config --exists --print-errors "ffnvcodec >= 11.1.5.3"
  • Compilació / Compilation
    • Passos / steps
      1. configuration
        • License:
          configure option
          resulting license
          (no option)
          LGPL v3 or later
          --enable-nonfree nonfree and unredistributable
          --enable-gpl GPL v3 or later
        • Acceleració per maquinari / Hardware acceleration (Linux graphics (Intel))
        • AAC audio (MPEG-4)
          • option 1:
            • use native embedded aac encoder (not experimental any more)
            • if you are coding your own client, you need to allow experimental codecs:
              • p_codec = avcodec_find_encoder_by_name("aac");

                AVDictionary *opts = NULL;
                av_dict_set(&opts, "strict", "experimental", 0);
                if (avcodec_open2(p_codec_ctx, p_codec, &opts) < 0) {
                ...
          • option 2:
            • use an external coder:
              • ./configure ... --enable-libfdk-aac --enable-nonfree ...
                • p_codec = avcodec_find_encoder_by_name("libfdk_aac");
              • ./configure ... --enable-libvo-aacenc ...
                • p_codec = avcodec_find_encoder_by_name("libvo_aacenc");
          • Exemples / Examples:
        • Configuration examples:
          • H264 + AAC (native) + [https]
            • ./configure --enable-gpl --enable-libx264 --enable-shared [--enable-nonfree --enable-openssl]
          • H264 + HE-AAC (Fraunhofer)
            • ./configure --enable-nonfree --enable-libfdk-aac --enable-gpl --enable-libx264 --enable-shared
          • Usual codecs
            • ./configure --enable-nonfree --enable-libfdk-aac --enable-gpl --enable-libx264 --enable-libtheora --enable-libvpx --enable-shared
            • ./configure [--enable-nonfree --enable-libfdk-aac] [--enable-gpl --enable-libx264 --enable-libxvid] --enable-libtheora --enable-libvpx --enable-shared
            • ./configure [--enable-nonfree --enable-libfdk-aac] [--enable-gpl --enable-libx264 --enable-libxvid] --enable-libtheora --enable-version3 --enable-libmp3lame --enable-libvpx --enable-shared
            • ./configure [--enable-nonfree --enable-libfdk-aac] [--enable-gpl --enable-libx264 --enable-libxvid] --enable-libtheora --enable-version3 --enable-libschroedinger --enable-libmp3lame --enable-libvpx --enable-shared
          • SRT (srt.pc is installed in /usr/local/lib64/pkgconfig/)
            • PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/:/usr/local/lib/pkgconfig/ ./configure --enable-libsrt ...
          • Complet (inclou SRT) / Complete (including SRT)
            • sudo dnf install  lib64freetype2-devel lib64sdl2.0-devel lib64mp3lame-devel lib64vo-aacenc-devel lib64fdk-aac-devel lib64opus-devel lib64dirac-devel lib64schroedinger-devel lib64theora-devel lib64vpx-devel lib64x264-devel lib64x265-devel lib64xvidcore-devel lib64openjpeg-devel lib64webp-devel nv-codec-headers lib64vdpau-devel lib64va-devel
            • PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/:/usr/local/lib/pkgconfig/ ./configure --enable-shared --enable-nonfree --enable-gpl --enable-openssl --enable-libpulse --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libopenjpeg --enable-libwebp --enable-libfreetype --enable-fontconfig --enable-libsrt --enable-demuxer=dash --enable-libxml2
          • close to dextop for CentOS
            • --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
              --enable-nonfree
              --enable-libfdk-aac
              --enable-gpl --enable-libx264 --enable-libx265
              --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads
              --disable-static --enable-shared --shlibdir=/usr/lib64 --enable-runtime-cpudetect
          • CentOS dextop
            • ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
                built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
                configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
      2. make
      3. sudo make install
      4. update ld:
        • echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
        • ldconfig
    • Problemes / Problems:
      • compatibility with gstreamer compilation
        • ffmpeg must be installed after gstreamer, because gstreamer is going to install its own version of ffmpeg headers in /usr/local/include/libavcodec ... and a missmatch between (minor) versions will occur:
          • installed by gstreamer:
            • grep "define LIBAVCODEC_VERSION_" /usr/local/include/libavcodec/version.h
          • installed by ffmpeg:
            • grep "define LIBAVCODEC_VERSION_" ~/src/ffmpeg-4.2.3/libavcodec/version.h
        • if gstreamer were installed after ffmpeg, janus will not be able to be compiled with postprocessing option --enable-post-processing
      • libavcodec/libavcodec.so: undefined reference to `x264_encoder_open_160'
        • ls -l /usr/local/lib64/ | grep libx264
          • lrwxrwxrwx. 1 root root        14 15 març 18:47 libx264.so -> libx264.so.160
            -rwxr-xr-x. 1 root root   9014288 15 març 18:42 libx264.so.160
      • missing some libx264-*ffpresets

ffmpeg compilation on MSWindows

  • using cygwin
    • [Mplayer-cygwin] list
    • setup Cygwin. Install packages:
      • make
      • gcc
      • diffutils (cmp)
      • patch
    • install and compile yasm (nasm not always works)

    • static dynamic
      x264
      (*)
      svn co svn://svn.videolan.org/x264/trunk x264

      patch -p0 < dll.patch
      ./configure ./configure --enable-shared
      modify config.mak:
      delete all -mno-cygwin occurences

      make libx264.a make
      install -m 644 libx264.a /usr/local/lib
      install -m 644 x264.h /usr/local/include
      make install
      ffmpeg svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
      modify libavcodec/mpegaudiodec.c. Add line:
      #define llrint lrint or apply a patch

      ./configure --enable-libx264 --enable-gpl ./configure --enable-shared --disable-static --enable-libx264 --enable-gpl
      make
      make install
  • using MinGW
    • ffmpeg Windows help
    • setup MinGW
      • install MSYS in c:\msys (from minGW / Download / Current)
        • MSYS_1.0.10.exe
      • install MinGW in c:\MinGW (from minGW / Download / Current) (use f.i. 7zip to untar)
        • MinGW Runtime: mingw-runtime-3.9.tar.gz
        • Windows API: w32api-3.6.tar.gz
        • binutils: binutils-2.15.91-20040904-1.tar.gz
        • GCC: gcc-core-3.4.2-20040916-1.tar.gz, gcc-g++-3.4.2-20040916-1.tar.gz
      • copy needed tools from MS Visual:
        • copy c:\Archivos de programa\Microsoft Visual Studio .NET 2003\Vc7\bin\lib.exe, link.exe -> c:\MinGW\bin
        • copy c:\Archivos de programa\Microsoft Visual Studio .NET 2003\Common7\IDE\mspdb71.dll -> c:\MinGW\bin
      • Start / MinGW / MSYS / msys.exe
    • install and compile yasm (nasm not always works)
    • compile x264
    • compile ffmpeg
    • cd /c/.../gpac_extra_libs/ffmpeg
    • ./configure --enable-shared --disable-debug --enable-memalign-hack
    • make

x264 compilation

  • Dependencies
    • Alma
      • sudo dnf install git nasm gcc make
  • git clone https://code.videolan.org/videolan/x264.git
  • cd x264
  • git checkout stable
  • ./configure --enable-shared
  • make
  • sudo make install
  • if you will want to compile ffmpeg with x264 support:
    • sudo make install-lib-shared
    • and configure ffmpeg with:
      • ...
  • if ...:
    • sudo make install-lib-static

x265 compilation

  • dependències / dependencies
    • Mageia
      • urpmi task-c++-devel
  • one of the following
    • x265.org
      • hg clone https://bitbucket.org/multicoreware/x265
    • Videolan x265
      • hg clone http://hg.videolan.org/x265
  • cd x265/build
  • cmake ../source
  • make
  • sudo make install
  • to avoid "ERROR: x265 not found" when configuring ffmpeg with --enable-x265, check that /usr/local/lib/pkgconfig is on pkg-config path:
    • pkg-config --list-all | grep x265
    • if nothing appears, then:
      • export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
      • to make it permanent:
        • ...

GPAC

  • Linux compilation
    • fmpeg / libav gpac



      ffmpeg configure
      errors when compiling gpac
      solutions
      dashcast problems
      library
      version
      ./configure
      gpac modifications from mpeg2video source

      extra_lib







      libav 9
      9.8





      9.10
      --enable-debug --enable-gpl --enable-libx264 --enable-version3 --enable-shared audio_decoder.c:215:58: error: ‘AVFrame’ has no member named ‘channels’: solved in r4959

      ok
      incorrect mp2 output audio (estrident) from aac input
      10





      git
      git





      ffmpeg 1.2
      1.2.4





      2.0
      2.0.2
      --enable-debug --enable-gpl --enable-libx264 --enable-version3 --enable-shared
      (no errors)
      ok incorrect mp2 output audio (estrident) from aac input
      2.1
      2.1.1 --enable-debug --enable-gpl --enable-libx264 --enable-version3 --enable-shared
      (no errors)
      -
      ok
      incorrect mp2 output audio (estrident) from aac input
      2.1.2

      2.1.3



      2.2
      2.2 --enable-debug --enable-gpl --enable-libx264 --enable-libx265 --enable-version3 --enable-shared --enable-avresample



      2.3
      2.3.3
      --enable-debug --enable-gpl --enable-libx264 --enable-libx265 --enable-version3 --enable-shared --enable-avresample --enable-libfreetype




      2.4






    • step 1: install needed libraries
      • to compile your own version of libav/ffmpeg, choose one of the following:
        • ffmpeg from source
        • libav from source
          • libav 9.10
            • cd libav-9.10; ./configure --enable-debug --enable-gpl --enable-libx264 --enable-version3 --enable-shared
          • GPAC rev >=4772 (22nd sep 2013): install and compile libav from git (55)
          • GPAC rev >= 4731: install or compile libav 9.8 (54) (only libs are needed):
          • GPAC rev < 4731: install or compile libav version 0.8.7 (53) (only libs are needed):
            • cd ~/src/libav-0.8.7/
            • make install-libs
        • gpac_extra_lib (ffmpeg and other libraries, provided by gpac)
          • steps
            • urpmi automake (to avoid aclocal not found)
            • cd gpac/extra_lib
            • wget https://sourceforge.net/p/gpac/code/HEAD/tree/trunk/gpac_extra_libs/gpac_extra_libs.zip
            • unzip gpac_extra_libs.zip
            • chmod +x compile.sh */configure */bootstrap
            • ./compile.sh
          • problems
            • configure.in:27: error: 'AM_CONFIG_HEADER': this macro is obsolete.
                  You should use the 'AC_CONFIG_HEADERS' macro instead.
      • Paquets / Packages
        • CentOS
          • sudo yum install ...
        • Mageia 2/3/4, 64bit:
          • if you have compiled your own version of libav/ffmpeg:
            • urpmi lib64pulseaudio-devel lib64xv-devel lib64xmlrpc-c-devel lib64cairo-devel lib64wxgtku2.8-devel lib64openjpeg-devel lib64faad2-devel lib64mad-devel lib64a52dec-devel [lib64sdl2.0-devel]
          • if you use the system libav/ffmpeg:
            • urpmi lib64pulseaudio-devel lib64xv-devel lib64xmlrpc-c-devel lib64cairo-devel lib64wxgtku2.8-devel lib64openjpeg-devel lib64faad2-devel lib64mad-devel lib64a52dec-devel lib64ffmpeg-devel[lib64sdl2.0-devel]
        • Ubuntu (*)
          • if you have compiled your own version of libav/ffmpeg:
            • sudo apt-get install make pkg-config g++ zlib1g-dev libsdl1.2-dev [libsdl2-dev]
          • if you use the system libav/ffmpeg:
            • sudo apt-get install make pkg-config g++ zlib1g-dev firefox-dev libfreetype6-dev libjpeg62-dev libpng12-dev libopenjpeg-dev libmad0-dev libfaad-dev libogg-dev libvorbis-dev libtheora-dev liba52-0.7.4-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libxv-dev x11proto-video-dev libgl1-mesa-dev x11proto-gl-dev linux-sound-base libxvidcore-dev libssl-dev libjack-dev libasound2-dev libpulse-dev libsdl1.2-dev dvb-apps libavcodec-extra-53 libavdevice-dev libmozjs185-dev
        • Mageia 1:
          • urpmi libmad-devel libxvid-devel libjs-devel libopenjpeg-devel libjpeg-devel liba52dec-devel libSDL-devel libcairo-devel libwxgtku2.8-devel libpulseaudio-devel libxmlrpc-c-devel libxulrunner-devel libxv1-devel libffmpeg-devel libdirectfb-devel
        • Mandriva 2010.2:
          • add plf to your distribution sources (Easy URPMI)
          • urpmi libmad-devel libxvid-devel libjs-devel libopenjpeg-devel libjpeg-devel liba52dec-devel libSDL-devel libwxgtku2.8-devel libpulseaudio-devel libxmlrpc-c-devel libxulrunner-devel xulrunner-headless-devel libxv1-devel libffmpeg-devel
        • Mandriva 2008.x:
          • from 2008.1: urpmi libfaad2-devel libffmpeg-devel (liblame-devel libfaac-devel libmpeg4ip-devel liba52dec-devel libmrnb-devel libtheora-devel libvorbis-devel libx264-devel libmrwb-devel) libglib2.0-devel libmesaglut3-devel
          • from 2008.0: urpmi libfreetype6-devel libjs-devel libmad0-devel libopenjpeg1-devel libopenssl0.9.8-devel libpng-devel libSDL1.2-devel libwxgtk2.8-devel (libxml2-devel) libwxgtku2.8-devel 
        • Mandriva 2007.x:
          • urpmi libfaad2_0-devel libffmpeg51-devel libfreetype6-devel libjpeg62-devel libjs1-devel libmad0-devel libogg0-devel libopenjpeg1-devel  libopenssl0.9.8-devel libpng3-devel libSDL1.2-devel libtheora0-devel  libvorbis0-devel libwxgtk2.6-devel libwxgtku2.6-devel libxml2-devel libxvid4-devel zlib1-devel libmesaglut3-devel
          • ln -s /usr/include/js-1.5 /usr/include/js
    • step 2: get GPAC source:
    • step 3: compile gpac (Compiling GPAC on Ubuntu)
      • Problemes / Problems
      • Dashcast modifications
      • modify GPAC code according to libav / ffmpeg versions used:
        • ffmpeg 2.2 (compiled with --enable-avresample)
          • gpac/applications/dashcast/Makefile (GPAC svn > r5237)
            • CFLAGS+=-DDC_AUDIO_RESAMPLER
              LINKLIBS+=-lavresample
        • ffmpeg 2.1
          • (no modifications needed on latest svn gpac)
        • libav git
          • if using GPAC rev>=4772 (2013-09-22)
            • ffmpeg_decode.c:112:7: error: ‘CODEC_ID_SVQ3’ undeclared (first use in this function)
              ...
              • Solució / Solution:
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' modules/ffmpeg_in/ffmpeg_decode.c
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' modules/ffmpeg_in/ffmpeg_demux.c
            • modules/ffmpeg_in/ffmpeg_decode.c:633: undefined reference to `avcodec_decode_audio3'
              • Solution:
                • use libav 9.x
          • if using GPAC rev. >= 4731 (2013-09-05)
            • error: ‘AV_CH_LAYOUT_STEREO’ undeclared
              • Solució / Solution:
                • audio_muxer.h
                  • #include "libavcodec/version.h"
                    #if (LIBAVCODEC_VERSION_MAJOR>53)
                    #include "libavutil/channel_layout.h"
                    #endif
            • error: ‘AVStream’ has no member named ‘r_frame_rate’
              • libavformat/avformat.h
              • solució / solution
                • video_decoder.c
                  • comment if statament where r_frame_rate appears
            • error: ‘CODEC_ID_RAWVIDEO’ undeclared
              • solució / solution
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' video_decoder.c
            • error: ‘CODEC_ID_H264’ undeclared
              • sol:
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' video_encoder.c
            • video_encoder.o: In function `dc_video_encoder_encode':
              video_encoder.c:(.text+0x26b): undefined reference to `avcodec_encode_video'
              • in libav from git, avcodec_encode_video has changed to avcodec_encode_video2 and parameters are different (libavcodec/avcodec.h)
              • sol:
                • use libav 9.1
          • make sure that extra_lib is not refrenced by configure:
            • rm -rf extra_lib
          • error: ‘CODEC_ID_MPEG4’ not declared in this scope
            • Solució / Solution:
              • cd modules/ffmpeg_in/
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' ffmpeg_decode.c
                • sed -i 's/CODEC_ID/AV_CODEC_ID/g' ffmpeg_demux.c
                • sed -i 's/av_close_input_file/avformat_close_input/g' ffmpeg_demux.c
                • sed -i 's/av_open_input_stream/avformat_open_input/g' ffmpeg_demux.c
                • ...
          • applications/dashcast/audio_encoder.h
            • #include "libautil/channel_layout.h"
          • ‘AVStream’ has no member named ‘r_frame_rate’
            • it is an issue in libav from repository; use libav-9.1 instead
        • libav 9.10
          • ...
        • libav 9.8
          • if using GPAC rev. >= 4731 (2013-09-05)
            • error: ‘AV_CH_LAYOUT_STEREO’ undeclared
              • Solució / Solution:
                • audio_muxer.h
                  • #include "libavcodec/version.h"
                    #if (LIBAVCODEC_VERSION_MAJOR>53)
                    #include "libavutil/channel_layout.h"
                    #endif
        • libav 53 / 0.8.7 / ffmpeg
          • no GPAC modifications needed
      • ./configure [--enable-debug] [--use-js=no]
      • make
      • make install
      • update ld.so:
        • new fashion (e.g. Mageia 3):
          • echo /usr/local/lib > /etc/ld.so.conf.d/local32.conf
          • ldconfig
        • old fashion
          • add lines to /etc/ld.so.conf
            • /usr/local/lib
            • /usr/lib/xulrunner-1.9.../
      • ldconfig
      • MP4Box usage
    • Problemes / Problems
      • durant la compilació / during compilation
        • with libav
        • problems with libavformat/avio.h
          • error: ‘URL_WRONLY’ was not declared in this scope
        • compilation with libav (>0.8.7) instead of ffmpeg or libav 0.8.7
          • /usr/bin/ld: /usr/local/lib/libavcodec.a(allcodecs.o): relocation R_X86_64_32 against `ff_a64multi_encoder' can not be used when making a shared object; recompile with -fPIC
            • Solució / Solution:
              • assegureu-vos que libav s'ha compilat amb l'opció: /make sure that libav was compiled with option:
                • --enable-shared
          • problems with ffmpeg libavcodec/avcodec.h (*) and libav (ffmpeg fork)
        • /usr/bin/ld: /usr/local/lib/libavcodec.a(allcodecs.o): relocation R_X86_64_32 against `ff_a64multi_encoder' can not be used when making a shared object; recompile with -fPIC
        • ../../bin/gcc/libgpac.so: undefined reference to `JSVAL_NULL'
          ../../bin/gcc/libgpac.so: undefined reference to `JSVAL_VOID'
          • solution:
            • ??
        • undefined reference to JS_ClearNewbornRoots
        • DirectFB not found by configure
          • solution:
            • bug: in configure file, you shoud have:
              • directfb_inc="/usr/include/directfb"
      • després de la compilació / after compilation
        • confirm that the following files point to the right place (/usr/local/lib/libav...):
          • ldd /usr/local/lib/gpac/gm_ffmpeg_in.so
            • libavcodec.so.54 => /usr/local/lib/libavcodec.so.54
              ...
          • ldd /usr/local/bin/DashCast
          • ldd /usr/local/bin/MP4Client
          • if not:
            • /etc/ld.so.conf.d/local32.conf
              • /usr/local/lib
            • ldconfig
        • ldd DashCast apunta a libavcodec.53, i heu compilat amb la versió 54:
          • Solució:
            • comproveu que els fitxers a bin/gcc/DashCast i altres .so són recents. Si no, esborreu-los i feu make
      • en execució / on execution
        • DashCast
          • si feu servir l'ffmpeg (o bé altres paquets de la distribució), us podeu trobar que DashCast us dóna errors del tipus "Cannot open video file", perquè es barregen versions de l'ffmpeg i libav / if you are using ffmpeg or libav packages from your distribution, you may find errors like "Cannot open video file", because several versions of the libraries are mixed (confirm with "ldd DashCast")
            • Solució / Solution:
              • desinstal·leu els paquets de la distribució, perquè gpac agafi els que acabeu de compilar / uninstall distribution development packages, so as gpac takes the newly compiled files:
                • ubuntu:
                  • sudo apt-get remove libavcodec-dev libavformat-dev libavutil-dev
              • comproveu ldd / check ldd
          • "Cannot open output audio codec" / "Cannot open output audio stream"
            • us hi podeu trobar si feu servir aac com a còdec àudio de sortida amb el DashCast
            • solució / Solution:
          • "Cannot find a video stream"
            • Solution:
              • make sure that ./configure gives:
                • FFMPEG: system
          • L'àudio de sortida (mp2) és soroll estrident / Output audio (mp2) is an annoying noise:
          • dashcast.conf file is not generated
            • if -conf option is not used, a generic dashcast.conf file should be generated and written, but only after DashCast is cleanly closed (q)
          • "Rep v1 UTC diff at segment close: 7769 is lower than cumulated segment duration 15000 (diff -7231) - frame rate is probably not correct or frames were lost !!"
            • occurs with libav-9.10
            • Solution
              • ??
    • compile osmozilla (plug-in for Firefox)
      • urpmi libxulrunner-devel
      • cd applications/osmozilla
      • make
      • make install (as user)
      • Desenvolupament / Development
        • applications/osmozilla/osmo_npapi.{cpp,h}
        • applications/osmozilla/osmozilla.cpp
      • Utilització / Usage
      • Problems:
    • compile MP4Client (ja es compila en la compilació general / already compiled in general compilation):
      • cd applications/mp4client
      • modify Makefile:
        • comment line:
          • #rm...
      • make
      • make install
      • MP4Client usage
    • compile gpac with OpenSVC (gpac/modules/opensvc_dec)
      • compile and install OpenSVC libraries
      • modify modules/Makefile (solved in rev 3686):
        • PLUGDIRS=aac_in ... opensvc_dec
      • compile gpac
      • usage
        • ~/.gpacrc
          • You can directly use ctrl+(H,L) or add shortcuts to ~/.gpacrc (during playback, they are taken into account when the MP4Client window has the focus: WINDOW SHORTCUTS):
            • [Shortcuts]
              QualityDown=1
              QualityUp=2
              TemporalIdDown=8
              TemporalIdUp=9
          • In [System] section, check that "codec_04_21" is not associated to "FFMPEG decoder". It must be associated to "OpenSVC Decoder":
            • codec_04_21="FFMPEG decoder"
            • codec_04_21="OpenSVC Decoder"
          • In [PluginsCache] section, check that opensvc_dec is not an invalid module.
        • MP4Client toto_svc.mp4 (amb fitxers .264 no funciona bé)
        • To change layer:
          • Ctrl+H
          • Ctrl+L
      • Problems
        • Segmentation fault
        • [Thread MediaManager] Couldn't set priority(2) for thread ID 0x00000000
          [Thread MediaManager] Couldn't set priority(2) for thread ID 0xb1077b70
          • Solution:
            • ??
    • compile hbbtvplayer
      • cd applications/hbbtvplayer/hbbtvbrowserplugin
        • chmod +x autogen.sh
        • ./autogen.sh
        • ./configure
        • make install
      • cd applications/hbbtvplayer/hbbtvterminal
        • (webkit-1.0 >= 1.5.2)
        • chmod +x autogen.sh
        • ./autogen.sh
        • ./configure
        • make install
    • compile with OpenHEVC decoder (HEVC)
    • compile gpac
      • [chmod +x configure]
      • run configure:
        • cvs: ./configure
        • svn (portivity): ./configure --disable-ipv6 (to avoid error in utils/os_net.c: sin_port)
        • 0.4.2-rc2: ./configure --use-ffmpeg=local
      • to prepare for debugging:
        • ./configure --enable-debug
        • to get an unstripped installed /usr/local/lib/libgpac-xx-DEV.so (to be used by gdb):
          • src/Makefile: INSTFLAGS= (not INSTFLAGS=-s, which installs a stripped version in /usr/local/lib)
      • make
      • (gcc -O3  -fno-strict-aliasing -Wno-pointer-sign -Wall -I/home/fpinyol/src/svn-portivity/trunk/wp5/gpac_0.4.4/include -DGPAC_HAS_SPIDERMONKEY -DXP_UNIX -I/usr/include/js -c -o laser/lsr_[dec,enc,tables].o laser/lsr_[dec,enc,tables].c)
      • make install
      • add line to /etc/ld.so.conf:
        • /usr/local/lib
      • ldconfig
    • using kdevelop
      • Import project: C (?with automake)
    • using Eclipse (Indigo) and subversion (SVN)
      • Setup Eclipse with Subversion
      • From scratch:
        • ...
      • From existing and working svn tree:
        • File -> Import...
        • C/C++ / Existing Code as Makefile project
        • Existing code location: Browse...
        • Toolchain for Indexer Settings: Linux GCC
      • Config for using debug:
        • ./configure --enable-debug
      • Build targets
    • using Eclipse and CVS
      • CVS
        • File / New / Project: CVS / Projects from CVS
        • Create a new repository location
          • Host: gpac.cvs.sourceforge.net
          • Repository path: /cvsroot/gpac
          • User: anonymous
          • Password:
          • Connection type: pserver
        • Use specified module name: gpac
        • Check Out As: Check out as a project configured using New Project wizard
        • Select tag: HEAD
        • Select a wizard: C / C Project
        • Project name: gpac_cvs
        • Project types: Makefile project
        • Configuration: Default
        • cd gpac_cvs; chmod +x configure; ./configure --enable-debug
        • Project / Build All
      • Build targets
    • Build on Eclipse
      • ./configure --enable-debug
      • Make Targets: applications / testapps / broadcaster
        • gpac
          • select "gpac"
          • Add make target:
            • Project -> Make target -> Create...
              • Target name: "gpac_all"
              • Make target: "all"
              • (?) Deactivate "Run all project builders"
          • Build make target:
            • Project -> Make target -> Build...
        • broadcaster
          • Add make "broadcaster_all" target:
            • Target name: broadcaster_all
            • Make target: all
            • Deactivate "Run all project builders"
          • Build:
            • Select "broadcaster_all" / Build Make target
          • Add make "broadcaster_clean" target:
            • Target name: broadcaster_clean
            • Make target: clean
            • Deactivate "Run all project builders"
          • Build:
            • ...
      • Launch an application on debug mode:
        • Run -> Debug Configurations...
        • C / C++ Application
        • New
          • Name: "DashCast_toto"
          • Main
            • C / C++ Application: bin/gcc/DashCast
            • Project: gpac
          • Arguments
            • "-av toto.mp4 -live-media -seg-dur 10000"
        • New
          • Name: "MP4Box_1"
          • Main
            • C / C++ Application: bin/gcc/MP4Box
            • Project: gpac
        • New
          • Name: "MP4Box_add"
          • Main
            • C / C++ Application: bin/gcc/MP4Box
            • Project: gpac
          • Arguments
            • "-add toto.h264 toto.mp4"
      • Debug
        • Open Debug Dialog / C/C++ Local Application
        • Environment:
          • Variable: LD_LIBRARY_PATH
          • Value: .../gpac_cvs/bin/gcc
  • DashCast usage
  • DashCast modifications (gpac/applications/dashcast)
    • audio transcode to AAC (instead of MP2) (needed by HbbTV 1.5):
      • dashcast.conf
        • [a1]
          type=audio
          bitrate=192000
          samplerate=48000
          channels=2
          codec=aac
      • applications/dashcast/audio_muxer.h (not needed anymore?)
        • #include "libavcodec/version.h"
          #if (LIBAVCODEC_VERSION_MAJOR>53)
          #include "libavutil/channel_layout.h"
          #endif
      • applications/dashcast/audio_muxer.c, in function dc_gpac_audio_moov_create:
        • //esd->decoderConfig->objectTypeIndication = GPAC_OTI_AUDIO_MPEG1;
          esd->decoderConfig->objectTypeIndication = GPAC_OTI_AUDIO_AAC_MPEG4;
        • //acfg.base_object_type = GF_M4A_LAYER2;
          acfg.base_object_type = GF_M4A_AAC_LC;
        • //audio_stream->codec->sample_fmt = AV_SAMPLE_FMT_S16;
          audio_stream->codec->sample_fmt = audio_codec_ctx->sample_fmt;
      • applications/dashcast/audio_encoder.c, in function dc_audio_encoder_open:
        • //p_aout->p_codec = avcodec_find_encoder_by_name("mp2"); p_aout->p_codec = avcodec_find_encoder_by_name(p_adata->psz_codec);
        • //audio_output_file->codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
          if( strcmp(audio_data_conf->codec, "aac") == 0 ) {
              audio_output_file->codec_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
          }
          else {
              audio_output_file->codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
          }
        • /* open the audio codec */
          AVDictionary *opts = NULL;
          if( strcmp(audio_data_conf->codec, "aac") == 0 ) {
            av_dict_set(&opts, "strict", "experimental", 0);
          }
          //if (avcodec_open2(audio_output_file->codec_ctx, audio_output_file->codec, NULL) < 0) {
          if (avcodec_open2(audio_output_file->codec_ctx, audio_output_file->codec, &opts) < 0) {
              /*FIXME: if we enter here (set "mp2" as a codec and "200000" as a bitrate -> deadlock*/
              GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Cannot open output audio codec\n"));
              return -1;
          }
    • avc1 vs avc3 (revision >=4726)
      • controler.c
        • avc1:
          • #define VIDEO_MUXER GPAC_INIT_VIDEO_MUXER_AVC1
        • avc3:
          • #define VIDEO_MUXER GPAC_INIT_VIDEO_MUXER_AVC3
    • applications/dashcast/video_encoder.c, in function dc_video_encoder_open (needed for having SPS and PPS available on video_muxer.c) (solved on revision 4726: avc1)
      • p_voutf->p_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
    • applications/dashcast/video_muxer.c, in function dc_gpac_video_moov_create
      • avccfg = gf_odf_avc_cfg_new();
      • SPS and PPS on init mp4 (modification on video_encoder.c needed. see above) (solved on revision 4726: avc1)
        • int sps_size, pps_size, nal_separator_size;
          nal_separator_size = 4; // 00 00 00 01
          pps_size = 4;
          sps_size = p_video_codec_ctx->extradata_size - 2*nal_separator_size - pps_size;

          /*SPS*/
          GF_AVCConfigSlot *sl_sps;
          sl_sps = (GF_AVCConfigSlot*)gf_malloc(sizeof(GF_AVCConfigSlot));
          sl_sps->size = sps_size;
          sl_sps->data = (char *)gf_malloc(sizeof(char) *sl_sps->size);
          memcpy(sl_sps->data, p_video_codec_ctx->extradata + nal_separator_size, sizeof(char)*sl_sps->size);
          gf_list_add(avccfg->sequenceParameterSets, sl_sps);

          /*PPS*/
          GF_AVCConfigSlot *sl_pps;
          sl_pps = (GF_AVCConfigSlot*)gf_malloc(sizeof(GF_AVCConfigSlot));
          sl_pps->size = pps_size;
          sl_pps->data = (char *)gf_malloc(sizeof(char) * sl_pps->size);
          memcpy(sl_pps->data, p_video_codec_ctx->extradata + sps_size + 2*nal_separator_size, sizeof(char)*sl_pps->size);
          gf_list_add(avccfg->pictureParameterSets, sl_pps);
      • avc1 instead of avc3 (inband). (Needed by HbbTV 1.5) Comment the following fragment: (solved on revision 4726: avc1)
        • /*
          gf_odf_avc_cfg_del(avccfg);
          //printf("time scale: %d \n",
          //        p_video_codec_ctx->time_base.den);
          ret = gf_isom_avc_set_inband_config(p_voutf->p_isof, track, 1);
          if (ret != GF_OK) {
              fprintf(stderr, "%s: gf_isom_avc_set_inband_config\n",
                      gf_error_to_string(ret));
              return -1;
          }
          */
      • size on [tkhd] and [avc1]:
        • u32 width, height;
          width=640;
          height=360;
        • // set size in [tkhd]
          gf_isom_set_track_layout_info(p_voutf->p_isof, track, width<<16, height<<16, 0<<16, 0<<16, 0);
        • // set size in [avc1]
          // requires adding GF_EXPORT before "GF_Err gf_isom_set_visual_info(GF_ISOFile...",
          // in file src/isomedia/isom_write.c
          ret = gf_isom_set_visual_info(p_voutf->p_isof, track, di, width, height);
      • alternate brand:
        • // set alternate brand
          gf_isom_modify_alternate_brand(p_voutf->p_isof, GF_4CC('a','v','c','1'), 1);
      • other modifications to avccfg:
        • // other modifications to avccfg
          avccfg->AVCLevelIndication = 31;
          ret = gf_isom_avc_config_update(p_voutf->p_isof, track, di, avccfg);
      • ret = gf_isom_finalize_for_fragment(p_voutf->p_isof, 1);
  • Linux usage
    • Fonts
      • import MSWindows fonts
        • Mandriva Control Centre / System / Manage Windows fonts / Obtain Windows fonts 
      • modify ~/.gpacrc:
        • [FontEngine]
          FontDirectory=/usr/share/fonts/drakfont/ttf
  • MS Windows compilation
    • compile gpac_extra_libs
    • compile ffmpeg
    • MSYS_1.0.10.exe
    • MinGW Runtime: mingw-runtime-3.9.tar.gz
    • Windows API: w32api-3.6.tar.gz
    • binutils: binutils-2.15.91-20040904-1.tar.gz
    • GCC: gcc-core-3.4.2-20040916-1.tar.gz, gcc-g++-3.4.2-20040916-1.tar.gz
    • copy needed tools from MS Visual:
    • copy c:\Archivos de programa\Microsoft Visual Studio .NET 2003\Vc7\bin\lib.exe, link.exe -> c:\MinGW\bin
    • copy c:\Archivos de programa\Microsoft Visual Studio .NET 2003\Common7\IDE\mspdb71.dll -> c:\MinGW\bin
    • Start / MinGW / MSYS / msys.exe
    • some checks
    • cd /c/.../gpac_extra_libs/lib
    • mkdir w32_deb w32_rel
    • edit /c/.../gpac_extra_libs/libavformat/Makefile and fix the bug:
    • cp avcodec... should be: cp avformat...
    • cd /c/.../gpac_extra_libs/ffmpeg
    • ./configure --enable-shared --disable-debug --enable-memalign-hack
    • make
    • compile the rest of gpac_extra_libs with MS Visual:
    • Open build\msvc6\BuildAll.dsw
    • Batch Build
    • compile gpac with MSVisual 6.0
      • Open gpac\build\msvc6\gpac.dsw
      • set gpac_dll as active (StartUp) project
      • Build libgpac_dll
    • compile gpac with MSVisual 2005 (svn portivity)
      • open build/win32/win32.sln
      • check "Solution Platforms": Win32
      • for computers with HT or dual core: set 1 parallel process
      • Build solution
  • MS Windows Mobile compilation
    1. Be sure you have VS2005 and WM 5.0 Developer Resource Kit installed
    2. From the VS2005 open the solution file for WM5 located at: <download folder>\build\wm5\wm5.sln 
    3. Select the correct solution configuration and platform (Debug/Release and Windows Mobile 5.0 Pocket PC SDK (ARMV4I) 
    4. Connect you device using the USB cable and verify that you can communicate with it (Explore from the ActiveSync) 
    5. Compile and deploy as usual

VideoLAN

  • Compilació/Compilation VLC:
    • Dependències / Dependences:
      • Mageia
        • 64b:
          • urpmi lib64lua-devel lib64mad-devel lib64a52dec-devel lib64xcb-devel lib64xml2-devel lib64gcrypt-devel
        • 32b:
          • urpmi autoconf automake libtool-base
          • urpmi liblua-devel libxpm-devel libqt4-devel  libmad-devel libgcrypt-devel gcc-c++ [liba52dec-devel libffmpeg-devel]
      • Ubuntu
        • sudo apt-get install autoconf libtool
        • sudo apt-get install liblua5.2-dev lua5.2 libmad0-dev liba52-0.7.4-dev libxcb-shm0-dev libxcb-composite0-dev libxcb-xv0-dev libxml2-dev libxcrypt-dev libgcrypt20-dev libdvbpsi-dev
    • option 1: from git
      • cd /usr/include; ln -s libxml2/libxml
      • git clone git://git.videolan.org/vlc.git
      • [git pull]
    • option 2: from tarball
      • wget http://download.videolan.org/pub/videolan/vlc/2.1.4/vlc-2.1.4.tar.xz
      • tar xvJf vlc-2.1.4.tar.xz
    • cd vlc
    • ./bootstrap
    • ./configure [--disable-mkv]
      • when using your own ffmpeg compiled and installed in /usr/local/lib (needed for Mageia, not for Ubuntu):
    • make clean
    • make
    • make install
    • Problemes / Problems
      • blend.c not found
        • Solution:
          • cd modules/video_filter/
          • ln -s blender.cpp blender.c
  • Compilació/Compilation VLC amb/with MPEG-DASH plugin (build instructions):
    • IMPORTANT: "The DASH plugin is officially part of VLC and could be checked out through the GIT repository."
    • (?) urpmi gettext-devel
    • urpmi liblua-devel libxpm-devel libqt4-devel
    • cd /usr/include; ln -s libxml2/libxml
    • git clone git://git.videolan.org/vlc.git
    • git checkout 6cc89ae733784777ccad8cabd7786cc1c801089f
    • cd vlc
    • Apply patch:
      • wget http://www-itec.uni-klu.ac.at/dash/wp-content/dash/dash_stream_0_3_0_0.tar.gz
      • tar xvzf dash_stream_0_3_0_0.tar.gz
      • git apply 0001-Added-DASH-stream-filter.patch
      • Problem: "...patch does not apply"
        • Solution: get commit 6cc89ae733784777ccad8cabd7786cc1c801089f
          • git checkout 6cc89ae733784777ccad8cabd7786cc1c801089f
    • ./bootstrap
    • ./configure --disable-mkv
    • make
    • make install
    • Try it:
    • Problems:
      • "segmentation fault"
        • Solution:
          • rm -rf ~/.local/share/vlc/
      • dmesg: "vlc[13127]: segfault at ffffffa4 ip b75b506d sp bfafba94 error 4 in libpthread-2.12.1.so[b75ad000+15000]"
        • Solution:
          • ??
  • Compilació/Compilation VLMC (editor)
    • Dependències / Dependences
      • Mageia
        • urpmi cmake libvlc-devel libqt4-devel frei0r-plugins
    • git clone git://git.videolan.org/vlmc.git
    • mkdir build && cd build
    • cmake ..
    • make
    • make package

OpenSVC

  • mplayer compilation
    • RTSP/RTP streaming support for MPlayer (Live555)
    • dependencies
      • Mageia 1:
        • urpmi make libvdpau-devel live-devel live libdirac-devel libxv1-devel libopenjpeg-devel libjpeg-devel libSDL-devel libpulseaudio-devel liba52dec-devel
      • Mandriva
      • urpmi libvdpau-devel libfaac-devel live-devel live libdirac-devel libxv1-devel libopenjpeg-devel libjpeg-devel libSDL-devel libpulseaudio-devel liba52dec-devel
    • get the code
      • svn co https://opensvcdecoder.svn.sourceforge.net/svnroot/opensvcdecoder opensvcdecoder
      • [svn update]
    • compile
      • cd opensvcdecoder/Mplayer
      • ./configure --enable-svc --enable-menu
      • make
    • installation
    • with Eclipse:
      • ./configure --enable-svc --enable-menu --enable-debug
      • In C/C++ Perspective -> Make Target (second tab on right panel) -> select Mplayer -> New...
        • Target name: all
    • usage
  • compilació de només les biblioteques / only libraries compilation (per a ser utilitzades, per exemple, amb GPAC MP4Client)
    • dependencies
      • Mageia 1
        • urpmi cmake gcc-c++ libSDL-devel
    • compilation
      • cd opensvcdecoder/Libs
      • cmake CMakeLists.txt
      • make
    • installation
      • make install (it will install /usr/local/lib/libOpenSVCDec.so)
    • with Eclipse:
      • In C/C++ Perspective -> Make Target (second tab on right panel) -> select Libs -> New...
        • Target name: all
    • player usage
  • GPAC with OpenSVC

SVC reference software (JSVM)

  • Modules:
    • DownConvertStatic
    • H264AVCEncoderLibTestStatic
    • H264AVCDecoderLibTestStatic
    • AvcRewriter
    • BitStreamExtractorStatic
    • QualityLevelAssignerStatic
    • MCTFPreProcessor
    • PSNRStatic
    • FixedQPEncoderStatic
    • SIPAnalyser
    • YUVCompareStatic
  • Compilació / Compilation
    • dependencies
    • get the code
      • GitHub
        • floriandejonckheere/jsvm
      • cvs (outdated)
        • cvs -d :pserver:jvtuser:xxxxx@garcon.ient.rwth-aachen.de:/cvs/jvt login
        • cvs -d :pserver:jvtuser@garcon.ient.rwth-aachen.de:/cvs/jvt checkout jsvm
        • cvs update
    • compile
    • cd jsvm/JSVM/H264Extension/build/linux
    • make
  • Utilització / Usage
    • H264AVCEncoderLibTestStatic -pf encoder.cfg
    • example configuration files:
      • JSVM/H264Extension/data
      • JSVM0-config-samples
    • AVC / MVC:
      • encoder.cfg
        • AVCMode 1
        • InputFile toto.yuv
        • OutputFile toto_avc.264
        • ReconFIle toto_recon.yuv
        • SourceWidth win
        • SourceHeight hin
        • FrameRate fps
        • FramesToBeEncoded frames
        • SequenceFormatString (A: IDR intra; I: non-IDR intra; P: predicted: B: bidirectional) (upper case: to be used as reference; lower case: not to be used as reference):
          • A0*2{P2b0b1}
          • A0*1{P2P5P8b0b1b3b4b6b7b9b10}
          • ...
        • GOPSize, IntraPeriod, IDRPeriod not working? Only for SVC (AVCMode 0)?
    • SVC
      • Number of layers:
        • Spatial or CGS quality (D):
          • NumLayers
        • MGS quality (Q):
          • MgsVectorMode
          • MGSControl
        • Temporal (T)
          • log_2(GOPSize) + 1
      • Preparation:
        • DownConvertStatic win hin toto.yuv w1 h1 toto_w1xh1.yuv method t skip frames
        • DownConvertStatic win hin toto.yuv w2 h2 toto_w2xh2.yuv method t skip frames
      • encoder.cfg
        • [AVCMode 0]
        • OutputFile toto_svc.264
        • GOPSize
        • IntraPeriod
        • IDRPeriod
        • NumLayers
        • LayerCfg cfg/layer0.cfg
        • LayerCfg cfg/layer1.cfg
        • ...
      • cfg/layer0.cfg
        • InputFile orig/toto_w1xh1.yuv
        • IntraPeriod
        • IDRPeriod
      • cfg/layer1.cfg
        • InputFile orig/toto_w2xh2.yuv
        • IntraPeriod
        • IDRPeriod
      • ...
  • info about an SVC file (DTQ)
    • jsvm/bin/BitStreamExtractorStatic toto.264
  • IDR (to be able to switch layers more often):
    • layer cfg file (section INPUT/OUTPUT):
      • IDRPeriod     8

Butterflow

  • Motion interpolated videos
  • Instal·lació / Installation
    • Dependències / Dependencies
      • Mageia
        • urpmi task-c++-devel lib64ffmpeg-devel python-numpy-devel
    • git clone https://github.com/dthpham/sminterpolate.git
    • cd sminterpolate
    • setup.py
      • np_includes = '/usr/lib64/python2.7/site-packages/numpy/core/include'
    • virtualenv env; source env/bin/activate
    • python setup.py develop

libdash

  • How to use (libdash README.md)
  • Dependencies
    • Mageia
      • urpmi cmake lib64curl-devel
  • Download
    • git clone git://github.com/bitmovin/libdash.git libdash
  • Compilation(libdash)
    • cd libdash/libdash
    • mkdir build
    • cd build
    • cmake ..
    • make
    • cd bin
    • ./libdash_networpart_test
  • sampleclient compilation
    • Dependencies
      • Mageia
        • urpmi lib64SDL-devel
    • Problems
      • error: ‘UINT64_C’ was not declared in this scope
        • Solution
        • mv sdl sdl_old
        • Renderer/SDLRenderer.h
          • #include <SDL/SDL.h>
            #include <SDL/SDL_thread.h>
        • Renderer/IVideoObserver.h
          • #ifdef __cplusplus
            #define __STDC_CONSTANT_MACROS
            #ifdef _STDINT_H
            #undef _STDINT_H
            #endif
            # include <stdint.h>
            #endif

            #ifndef UINT64_C
            #define UINT64_C(c) (c ## ULL)
            #endif
      • error : Sleep was not declared in this scope
        • Solution
          • Decoder/LibavDecoder.cpp
            • #include <unistd.h>
              ...
              sleep...
    • cd libdash/libdash
    • CMakeLists.txt
      • add_subdirectory(sampleplayer)
    • cd build
    • cmake ..
    • make
  • qtsampleplayer compilation
    • Dependencies
      • Mageia
        • urpmi lib64qt5widgets-devel lib64qt5multimedia-devel lib64qt5network-devel lib64qt5multimediawidgets-devel lib64qt5opengl-devel
    • cd libdash/qtsampleclient
      • CMakeLists.txt
        • set(CMAKE_PREFIX_PATH /usr/lib64/qt5/lib/cmake/)
    • cd libdash/libdash
    • CMakeLists.txt
      • add_subdirectory(qtsampleplayer)
    • cd build
    • cmake ..
    • make
    • Problems
      • error: ‘usleep’ was not declared in this scope
        • Solution
          • libdashframework/Portable/MultiThreading.h
            • #include <unistd.h>
  • Usage
    • ..

Bento4

  • Get the source (choose one of the following methods)
  • Prerequisites
    • urpmi gcc-c++ scons
  • Compile
    • cd ~/src/Bento4
    • scons
  • Binaries
    • ~/src/Bento4/Build/Targets/x86_64-unknown-linux/Debug/
  • Installation
    • cd /usr/local/bin
    • su; ln -s ~/src/Bento4/Build/Targets/x86_64-unknown-linux/Debug/* .
  • Documentation
    • ~/src/Bento4/Documents/SDK/Bento4_SDK_documentation.pdf
    • unzip ~/src/Bento4/Documents/Doxygen/Bento4-HTML.zip
    • ~/src/Bento4/Documents/Doxygen/Bento4-HTML/index.html

LASeR reference software

  1. Install eclipse
  2. Download ref_software_2007-01-26.zip (w8869) from MPEG site (access needed)
    1. mv LASeRCodec1206 LASeRJPlayer1206 ~/workspace
  3. Download and install Sun's J2ME Wireless Toolkit (WTK)
  4. Download and install eclipseme, a J2ME plugin from eclipse. On the web site, there are detailed instructions for setting up the plugin and for linking it with the WTK.
  5. From Eclipse, create a new Java Project, and give it the name of the directory you put into the workspace (eg. LaserJPlayer, J2ME_Renderer). Eclipse will import the project (the source files and the libraries). It is recommended to have different source/output directories (see "Window/Preferences/Java/Build path" before creating the project)
  6. Convert the newly created project into a J2ME project (right click on the project, J2ME/Convert to J2ME Midlet Suite). Select the MIDP 2.0 Platform
  7. Change the build settings as following. Right click on the project, Properties, Java Build Path, Order and Export - check library.jar.
  8. Add some .lsr input files. For doing that, create a new source directory - eg res (right click on your project, New Source Folder). Put inside the .lsr files, and rebuild
     (if you have automatic build turned on - which is the case by default - right click on the directory, and click Refresh)
  9. In the file iso.mpeg.streamezzo.player.tool.SceneLoader, you should change the INIT_LASER_URL attribute according to the input file you wish to play.
  10. For executing / debugging, right click on iso.mpeg.streamezzo.player.tool.LASeRPlayer, Run as / Debug as Emulated J2ME Midlet

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ó: 16 d'abril de 2024 / Last update: 16th April 2024

Valid HTML 4.01!

Cap a casa / Back home.