.
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??
|
|
- 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
|
|
x |
|
|
DVB-FF
|
.dvb
|
|
video/vnd.dvb.file |
DVB
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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 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 |
|
|
|
|
|
|
|
MXF |
.mxf |
|
|
SMPTE |
|
|
|
|
|
|
|
OGG
(RFC 3533) |
|
|
|
Xiph |
|
|
|
|
x |
|
|
OGM (RFC
3534) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
- 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
-
- Info
- gspot
- Mediainfo
ffmpeg
-i toto.ts
analyzeduration
<microseconds>
- default: 5000000 (5 seconds)
probesize <bytes>
- tbn, tbc, tbr (frame-rate)
- Meaning
of
ffmpeg output (tbc, tbn, tbr) [closed]
- OpenCV
Reporting TBR instead of FPS when using
capture.get(CV_CAP_PROP_FPS)
- ff_rfps_calculate
- 4.4 libavformat/utils.c
- 5.0 libavformat/demux.c (avformat.h)
-
|
ffprobe
-show_streams
|
timebase from
|
units
|
stored in
|
set with |
tbn
|
time_base
= 1/tbn
|
container
|
|
AVStream.time_base |
-video_track_timescale
25000 (will give "time_base":
"1/25000") (*)
(e.g. when generating a video to be
used by concat demux) |
tbc
|
codec_time_base
= 1/tbc
|
codec
|
images/s
(doubled?)
|
AVCodecContext.time_base |
(usually not needed) -time_base
1/25 (will give "codec_time_base":
"1/50") |
tbr
|
r_frame_rate
= tbr
|
guessed
|
fields/s?
|
AVStream.r_frame_rate
(ff_rfps_calculate)
|
|
fps |
avg_frame_rate = fps |
|
|
|
|
- Exemples / Examples
Stream #0:0[0x100]: Video: h264
(Constrained Baseline) ([27][0][0][0]
/ 0x001B), yuv420p(tv, bt709,
progressive), 1920x1080 [SAR 1:1 DAR
16:9], 25 fps, 25 tbr,
90k tbn, 50 tbc
- video at 25 fps, with pts values
evenly distributed. All OK.
Stream #0:0[0x100]: Video: h264
(Constrained Baseline) ([27][0][0][0]
/ 0x001B), yuv420p(tv, bt709,
progressive), 1920x1080 [SAR 1:1 DAR
16:9], 25 fps, 30 tbr,
90k tbn, 50 tbc
- differences between fps and tbr
may come from a video at 25 fps,
with timestamps not evenly
distributed, probably from a 30fps
video that dropped 5 frames every
second, whose pts values have not
been recalculated. VLC may detect it
as 30fps.
- ...
ffprobe
toto.ts / avprobe toto.ts
midentify toto.mov
(mplayer
-identify ) (Transcoding
and
tagging video)
-
midentify "$file" | sed -e 's/^/export
/' > /tmp/midentify.sh
. /tmp/midentify.sh
- hachoir-metadata
urpmi python-hachoir-metadata
- kaa.metadata
(mminfo)
urpmi python-kaa-metadata
titol=`mminfo $1$2 | awk -F": " '$1 ~
/title$/ {print $2}'`
- MPEG-4
- H.264
- bento4
(formerly MPEG4IP)
- MPEG4IP
(
urpmi libmp4v2-utils ) (see bento4)
mp4info toto.mp4
/usr/bin/mp4art
/usr/bin/mp4chaps
/usr/bin/mp4extract
/usr/bin/mp4file
/usr/bin/mp4info
/usr/bin/mp4subtitle
/usr/bin/mp4tags
/usr/bin/mp4track
/usr/bin/mp4trackdump
(mp4videoinfo toto.mp4 )
( h264_parse toto.h264 )
( mpeg2video_parse
toto.m2v )
- GPAC
- Darwin
(
urpmi darwinstreamingserver-utils )
- JSVM
(SVC)
jsvm/bin/BitStreamExtractorStatic
toto.264
- AVInaptic
- 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 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
- libdvb
- MKVToolnix
(Matroska)
- extraction of ES (elementary streams):
-
- 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}"
|
- Llistes / Playlists
-
format
|
owner
|
used by
|
info
|
player
|
|
|
|
|
vlc
|
m3u8 |
|
HLS |
|
|
MPD
|
MPEG
|
|
|
|
MPL
MPLS
|
|
AVCHD / BD
|
|
|
XSPF |
xiph |
|
|
|
-
|
video
|
container
|
720
|
1080
|
4K
|
|
codec |
depth |
subsampling |
|
25p/30p
|
24p
|
25p
|
30p
|
50i/60i |
50p/60p
|
100p/120p
|
24p
|
25p
|
30p
|
AVCHD
|
|
|
|
|
|
- 17 Mb/s (FH)
- 24 Mb/s (FX)
|
|
- 17 Mb/s (FH)
- 24 Mb/s (FX)
|
28 Mb/s (PS) |
|
|
|
|
MP4
|
|
|
|
|
6Mb/s
|
|
16Mb/s |
|
28Mb/s
|
|
|
|
|
XAVC
|
H.264 L5.2
|
8, 10, 12 bits
|
4:2:0, 4:2:2,
4:4:4
|
MXF
|
|
|
|
|
|
|
|
|
|
|
XAVC
S HD
|
|
|
|
MP4
|
|
50
Mb/s
|
|
50
Mb/s
|
|
|
|
|
XAVC S 4K
|
|
|
|
|
|
|
|
|
|
|
|
|
HFR (Sony RX100 V)
- AVCHD
(BluRay Disc, camcorders)
- FLV
- SVI
- MXF
- YUV
- Conversió
/ Conversion
- Seqüències
de mostra / Sample sequences
- Packed YUV
formats (FourCC)
- YUV
Lab Reports (efg)
- UYVY
(sample image in the zip file)
- YUV
(wp)
- YCbCr
(wp)
-
original
|
gamma
corrected
|
luma,
chrominance
|
analogue
(continuous)
|
digital
(discrete)
|
R
|
R'
|
Y' =
0.229*R' + 0.587*G' + 0.114*B'
|
Y'
|
Y' =
219*Y' + 16 |
G
|
G'
|
B-Y'
|
Cb =
(B-Y')/1.772
|
Cb =
224*(B-Y') + 128 |
B
|
B'
|
R-Y'
|
Cr =
(R-Y')/1.402
|
Cr =
224*(R-Y') + 128 |
- SDI
/ ITU-R
BT:656
- Luma
(wp)
- Reproductors / Players
- Video
Tools
- video:
- single image:
- PYUV
(download)
- display a uyvy image:
- Resolution: SD576
- Color space: YCbCr
- Subsampling: 4:2:2
- Ordering: UYVY
- Interleaved
- if the image has a header (e.g.
.422 files):
- Extra settings -> Header
bytes: 32
- ffmpeg
ffplay -f rawvideo -pix_fmt
uyvy422 -s 720x576 -aspect 4:3 -i
toto.uyvy
- Image
Magick (formats)
- gnuplot
- full image:
- show Y':
set
cbrange [16:235]
set palette gray
plot "toto.uyvy" binary
array=(720,576) flipy
format="%uchar%uchar" using 2
with image
- show Cb:
set
cbrange [16:240]
plot "toto.uyvy" binary
array=(360,576) flipy
format="%uchar%uchar%uchar%uchar"
using 1 with image
- show Cr:
set
cbrange [16:240]
plot "toto.uyvy" binary
array=(360,576) flipy
format="%uchar%uchar%uchar%uchar"
using 2 with image
- first line:
- three components:
gnuplot -p <
grafica.plot
- grafica.plot:
set
terminal wxt size 640,240
set multiplot
unset key
set title "Y'"
set origin 0.0,0.0
set size 0.5,1
plot "toto.uyvy" binary
array=720 flipy
format="%*uchar%uchar"
with steps
set title "Cb"
set origin 0.5,0.0
set size 0.25,1
plot "toto.uyvy" binary
array=360 flipy
format="%uchar%uchar%uchar%uchar"
using 1 with steps
set title "Cr"
set origin 0.75,0.0
set size 0.25,1
plot "toto.uyvy" binary
array=360 flipy
format="%uchar%uchar%uchar%uchar"
using 3 with steps
unset multiplot
- show Y':
plot
"toto.uyvy" binary array=720
flipy format="%*uchar%uchar"
with impulses
plot
"toto.uyvy" binary array=720
flipy format="%uchar%uchar"
using 2 with impulses
plot
"toto.uyvy" binary array=720
flipy format="%uchar%uchar"
using 2 with steps
- show Cb:
plot
"toto.uyvy" binary array=360
flipy
format="%uchar%*uchar%*uchar%*uchar"
with steps
plot
"toto.uyvy" binary array=360
flipy
format="%uchar%uchar%uchar%uchar"
using 1 with steps
- show Cr:
plot
"toto.uyvy" binary array=360
flipy
format="%*uchar%*uchar%uchar%*uchar"
with steps
plot
"toto.uyvy" binary array=360
flipy
format="%uchar%uchar%uchar%uchar"
using 3 with steps
- WebM
Project
|
|
- Programari/software
- HOWTO
Convert
video files
- MTS
files (AVCHD: H.264 + AAC on
MPEG2-TS, from camera)
- Concatenació /
Concatenation
- cat (second step is necessary to avoid
discontinuities: "Continuity check failed for pid ...
expected ... got ...")
- cat 00650.MTS 00651.MTS 00652.MTS >
temporal.mts
- avconv -i
temporal.mts -c:v copy -c:a copy -f mpegts tots.mts
- avconv -i temporal.mts -c:v copy -c:a copy
tots.mp4
- find
all files between two dates (2013-08-9 to 2013-08-11)
- cat $(find . -newermt 2013-08-9 ! -newermt
2013-08-12 -printf "%T@ %p\n" | sort -n | awk
'{print $2}' | paste -s -d ' ') >
2013-08-09_11.mts
- avconv -i 2013-08-09_11.mts -c:a copy -c:v copy
2013-08-09_11.mp4
- melt
- libav:
Concatenació / Concatenation
- ffmpeg:
Concatenació / Concatenation
- aplicacions
d'edició / gui edition applications
- Howtos
- DLNA
- 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
- 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
- DVD -> /home/user/rip/vob
- tccat -i /home/user/rip/vob | tcextract -x ps1 -t vob
-a 0x22 > subs-en
- 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
- convert them to images:
- subtitle2pgm -o english -c 255,0,255,255 <
subs-en
- OCR:
- 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"
|
|
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
- 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:
- 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
- baixa
latència / low latency
- x264 presets:
- avconv presets
- /usr/local/share/avconv/libx264-*.avpreset
- /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
- "[libx264] lookaheadless mb-tree requires intra
refresh or infinite keyint"
- Using ffmpeg
- Info
- Docs
- Documentation
- All
documentation
- Filter
documentation
- Audio
sources
- abuffer, aevalsrc, afdelaysrc, afireqsrc,
afirsrc, anullsrc, flite, anoisesrc, hilbert,
sinc, sine
ffplay -f lavfi -i
"sine=frequency=5000:sample_rate=44100,
aformat=channel_layouts=stereo"
- ...
- Video
sources
- mandelbrot, allrgb, allyuv, color,
colorspectrum, haldclutsrc, nullsrc, pal75bars,
pal100bars, rgbtestsrc, smptebars, smptehdbars,
testsrc, testsrc2,
yuvtestsrc
ffplay
-f lavfi -i mandelbrot
ffmpeg -f lavfi -i testsrc=size=864x480
- ffmpeg
-lavfi 'testsrc2;sine' toto.mov
ffmpeg -f lavfi -i
"testsrc=duration=10:size=640x360,
format=pix_fmts=yuv420p" -f lavfi -i
anoisesrc=duration=10:colour=pink:amplitude=0.5
-ac 2 toto.mp4
- audio/video
sync
- openclsrc
- 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 |
- |
|
- 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
|
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
|
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
- NOTE: if -flags
+global_header is not specified and
one of the outputs is RTMP,
it will appear without video profile in
/stats (nginx-rtmp-module)
and HTML5
player with video.js
will not be able to start it
[tee @ 0x80cf20] Non-monotonous DTS
in output stream 0:0; previous: 566,
current: 561; changing to 567. This may
result in incorrect timestamps in the
output file.
- 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)
- Stream
selection
- 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
- list of available formats
- libswresample
(libav:
libavresample)
- conversion from s16p to s16:
- Start from time (-ss) hh:mm:ss[:ff],
during duration (-t):
- ffmpeg ... -ss hh:mm:ss[:ff] -t hh:mm:ss[.dd] ...
- specify -ss before -i to avoid anything but key
frames: much faster (*)
- "-ss seconds" for an entire number of seconds
- filtres / filtering
- FFmpeg
Filters Documentation
- Filtering
guide (wiki)
- chained filters
- simple
- complex
- -filter_complex
-filter_complex
"[input_label]filter_a.1_name=param1=value1:param2=value2,filter1.2_name=param1=value1:param2=value2[output_label];
[input_label]...[output_label]"
- igual: separa el nom del filtre dels
paràmetres; separa clau de valor
- dos punts: separa els paràmetres entre ells
- coma: separa dos filtres consecutius
- punt i coma: separa dos filtres paral·lels
- filtres:
- list of available 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
- ./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 , --enable-libharfbuzz ,
and, optionally, --enable-fontconfig
(to allow not specifying font)
... -filter_complex
"[0:v]drawtext=text=toto: x=(w-tw)/2: y=h/4:
box=1: boxcolor=black: fontsize=h/4:
fontcolor=white [v0]" -map '[v0]' ...
- 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
- 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
- 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)
- FFmpeg
and H.264 Encoding Guide
- FFmpeg
x264
encoding guide
- Acceleració
per maquinari / Hardware acceleration
- Linuxencoding
- X264
Encoding
Suggestions
- X264 settings
- x264
FFmpeg
Options Guide (options for x264 and ffmpeg)
- default gop size: 250
- -keyint_min ... (will be truncated to
gop_size/2 +1)
- -sc_threshold ... (scene cut detection)
- GOP
- X264
Settings (MeWiki)
- High level settings
- -profile:v
- baseline,
main,
high, high10, high422, high444
- -level:v
-
-level:v ... |
level |
level idc |
|
|
|
31
|
3.1 |
1f |
|
|
|
51
|
5.1 |
33 |
|
|
|
- -preset
(*)
(replaces
-vpre
for x264 from version ...)
- ultrafast, superfast, veryfast, faster,
fast, medium, slow, slower, veryslow,
placebo
- -tune
- film, animation, grain, stillimage, psnr,
ssim, fastdecode, zerolatency
- Low level settings
- ... -x264opts
"vbv-maxrate=2000:vbv-bufsize=200:slice-max-size=1500"
...
- Baixa
latència / Low latency
- Quality: CRF
Constant Rate Factor
-
crf
|
subjective
quality
|
0
|
lossless
|
23
|
good
|
35
|
acceptable
|
51
|
terrible
|
- H.264
bit-rate
control
- -vpre
(use "-preset"
(quality related) and "-profile:v"
(profile constraints) instead)
- /usr/share/ffmpeg/libx264-{ipod320,ipod640}.ffpreset
(git code) (those related to x264 have been replaced)
- libx264
(ffmpeg documentation)
- x264 ? FFmpeg Preset Choices (FFmpeg
x264
encoding guide) (FFmpeg
x264
encoding guide)
- -vpre quality_related
-vpre profile_constraints:
-
quality
related
|
profile
constraints
|
- ultrafast
- superfast
- veryfast
- faster
- fast
- medium
- slow
- slower
- veryslow
- placebo
|
- baseline
- main
- ipod320
- ipod640
|
- Problems
- "maybe incorrect parameters such as bit_rate,
rate, width or height"
- when using -vpre
ipodxxx, you must prepend a -vpre {slow...} option
- 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)
- 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
- ...
- 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:
- it is not present with:
- 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
- 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):
- 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
- B-frames
ffmpeg ... -bf
number ...
- No B-frames
- 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
- libwebp
- Compilació / Compilation
- Ús / Usage
- 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
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 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 ):
- 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
- 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
- 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
- Info
- Other tools, based on ffmpeg
- -t
<duration>
- -to <position>
- -accurate_seek
- 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
- trim
/ atrim
- select / aselect
- 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:
- 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
- Multilanguage
- HLS
- genera un fitxer amb dos àudios replicant un sol
àudio:
ffmpeg \
-f lavfi -i "testsrc=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"anoisesrc=duration=10.0:colour=pink:amplitude=0.5:sample_rate=48000"
\
-map 0:v \
-map 1:a -map 1:a \
multilang.mp4
- amb metadades (
-metadata )
de llengua (ISO
639-2: 3 caràcters) per als àudios:
ffmpeg \
-f lavfi -i "testsrc2=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"anoisesrc=duration=10.0:colour=pink:amplitude=0.5:sample_rate=48000 ,
aformat=channel_layouts=stereo
"
\
-map 0:v \
-map 1:a -map 1:a \
-metadata:s:a:0 language=cat -metadata:s:a:0
title="Primer àudio" \
-metadata:s:a:1 language=eng -metadata:s:a:1
title="Segon àudio" \
multilang.mp4
- àudios i subtítols
- create_multilang.sh
- #!/bin/bash
number_langs=$1;
function create_map_opts {
num=0;
for i in $(seq 0 25);
do second_char=$(printf
\\$(printf '%03o' $[97+$i]) | tr -d '\n');
for f in
$(seq 0 25);
do
third_char=$(printf \\$(printf '%03o'
$[97+$f]) | tr -d '\n');
map_opts+=(-map 1:a)
map_opts+=(-metadata:s:a:${num}
language=q${second_char}${third_char})
map_opts+=(-metadata:s:a:${num} title="Audio
number ${num}")
(( num+=1 ));
if ((
num>=number_langs ))
then
return;
fi;
done;
done;
}
map_opts=()
create_map_opts
ffmpeg \
-f lavfi -i
"testsrc2=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"anoisesrc=duration=10.0:colour=pink:amplitude=0.5:sample_rate=48000,
aformat=channel_layouts=stereo" \
-map 0:v \
"${map_opts[@]}" \
multilang.mp4
exit
- a partir de dos àudios diferents:
ffmpeg \
-f lavfi -i "testsrc2=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"anoisesrc=duration=10.0:colour=pink:amplitude=0.5:sample_rate=48000 ,
aformat=channel_layouts=stereo
"
\
-f lavfi -i "sine=
duration=10.0: frequency=500:sample_rate=480000,
aformat=channel_layouts=stereo" \
-map 0:v \
-map 1:a -map 2:a \
-metadata:s:a:0 language=cat -metadata:s:a:0
title="Primer àudio" \
-metadata:s:a:1 language=eng -metadata:s:a:1
title="Segon àudio" \
multilang.mp4
- redimensiona el vídeo d'un fitxer que conté un (o
més) vídeo, diversos àudios i diversos subtítols:
- ffmpeg
-i toto_2_4.mp4 -map 0 -vf scale=w=1280:h=720
-c:a copy -c:s copy multi_720p.mp4
- ffmpeg
-i toto_2_4.mp4 -map 0 -vf scale=w=1280:h=720
-c:a copy -c:s copy multi_720p.mp4 \
-map 0 -vf
scale=w=128:h=72 -c:a copy -c:s copy
multi_72p.mp4
- ffmpeg -i
toto_1_4.mp4 -filter_complex
"[0:v]scale=1280:720[v0]" -map '[v0]' -c:v h264
-map 0:a -c:a copy -map 0:s -c:s copy
toto_720.mp4
- genera un fitxer amb 2 vídeos (llengua de signes
catalana, llengua de signes valenciana) i 3 àudios
(replicant el mateix àudio: català, anglès, francès):
ffmpeg \
-f lavfi -i "testsrc=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"testsrc2=duration=10:size=640x360,
format=pix_fmts=yuv420p" \
-f lavfi -i
"anoisesrc=duration=10.0:colour=pink:amplitude=0.5:sample_rate=48000
,
aformat=channel_layouts=stereo
"
\
-map 0:v -map 1:v \
-map 2:a -map 2:a -map 2:a \
-metadata:s:v:0
language=csc -metadata:s:v:0
title="Primer vídeo" \
-metadata:s:v:1
language=vsv
-metadata:s:v:1
title="Segon vídeo"
\
-metadata:s:a:0 language=cat
-metadata:s:a:0 title="Primer àudio" \
-metadata:s:a:1 language=eng -metadata:s:a:1
title="Segon àudio" \
-metadata:s:a:2 language=fra
-metadata:s:a:2 title="Tercer àudio" \
multilang.mp4
- 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
- FFmpeg
Metadata
- get metadata
- ffprobe -i toto.mp4 -show_format -v quiet | grep
TAG
- get creation_time:
- creation_time=$(ffprobe -i toto.mp4
-show_format -v quiet | sed -n
's/TAG:creation_time=//p')
- midentify (mplayer)
- x from 0 to ID_CLIP_INFO_N:
- ID_CLIP_INFO_NAMEx = ID_CLIP_INFO_VALUEx
- Now
playing...
para mplayer (bash shell to extract
metadata, xosd)
- set metadata
- ffmpeg -i toto.mov -metadata
title="Title of videoclip" ... -acodec copy -vcodec
copy toto_metadata.mov
- copy metadata
- ffmpeg -i toto.mp4 -map_metadata 0 -c copy
toto_out.mp4
- Bug
- Supplying
FFmpeg
With Metadata
- Atomic
Parsley (MPEG-4)
- How
to
create and use Flash video metadata to add cue-points
with flvtool2
- Editing
video metadata
- Adobe XMP
metadata (wp)
-
mminfo
|
QT/MOV/MP4
|
AVI
|
Matroska
|
MP3
|
MP4
|
MPEG TS
|
NUT
|
Realmedia
|
SDP
|
title
|
title |
Title |
title |
title |
|
title |
title |
title |
s=
|
artist
|
author |
Artist
Author
|
|
author |
|
|
author |
author |
|
|
composer |
|
|
|
|
|
|
|
|
|
album |
Album |
|
album |
|
|
|
|
|
|
year |
|
|
year |
|
|
|
|
|
|
track |
Track |
|
track |
|
|
|
|
|
|
comment |
Comment |
|
comment |
|
|
|
comment |
|
|
|
|
language |
|
|
language |
|
|
|
|
genre |
Genre |
|
genre |
|
|
|
|
|
copyright |
copyright |
Copyright |
|
copyright |
|
|
copyright |
copyright |
|
|
description |
|
description |
|
|
|
|
|
|
|
synopsis |
|
|
|
|
|
|
|
|
|
show |
|
|
|
|
|
|
|
|
|
episode_id |
|
|
|
|
|
|
|
|
|
network |
|
|
|
|
|
|
|
|
|
|
|
|
|
major_brand |
|
|
|
|
|
|
|
|
|
minor_version |
|
|
|
|
|
|
|
|
|
compatible_brands
|
|
|
|
|
|
|
|
|
|
creation_time |
|
|
|
|
|
|
|
|
|
location |
|
|
|
|
|
|
|
|
|
location-eng |
|
|
|
|
- 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
|
|
- 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
- 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
- Info
- max delay reached. need to consume packet
RTP: missed xx packets
- Solució / Solution
- tune
buffers: buffer_size, fifo_size
- e.g.: if receiving buffer_size is
65536 (ffmpeg default, or specified
with buffer_size 65536)
- [udp @ 0x7f548c00e8c0] end
receive buffer size reported is
131072
- NALs
larger than 65536*2=131072 will
be truncated, and rtp packets
from this point will be dropped,
and kernel will mark them as
dropped (it can be seen by
running: dropwatch
-l
kas)
- maximum value for buffer_size
depends on Linux
kernel network parameter:
- check that net.core.rmem_max
is, at least, 212992 (default)
- ffmpeg -buffer_size=212992
- this will open an udp
buffer of 212992*2=425984
and NALs
could have up to 425984
bytes (416kB)
- En recepció / In reception
- [h264 @ 0x1795060] co located POCs
unavailable
- En transmuxació / Transmuxing
- No H.264
NAL units of type
7 (SPS), 8 (PPS)
when transmuxing from RTMP
(at RTMP: NAL units of type 7,8 are only
available at the beginning of the
connection, but they are needed by RTP
client)
- Solució / solution
ffmpeg
-protocol_whitelist
rtp,udp,file,http,https,tcp,tls,rtmp
-re -i rtmp://... -an -bsf:v
h264_mp4toannexb -c:v
copy -f rtp rtp://...
- Too many packets buffered for output
stream 0:1
- 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
- compile
with options:
--enable-demuxer=dash --enable-libxml2
- Reproducció / Play
- Selecció de qualitat / Quality selection
ffprobe toto.mpd
ffplay -map ... -map ... toto.mpd
- WebM
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
|
- Linux compilation
-
-
- 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):
-
cd ~/src/libav-9.8/
- if you want aac
encoding:
-
make install-libs
- 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
- 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:
- gpac / gpac
(GitHub)
git clone [-b master] [--depth 1]
https://github.com/gpac/gpac.git
- gpac
tar or CVS
- SVN
-
- first time:
-
- next times:
-
- head (latest):
-
- specific revision (e.g. r5382):
-
- patch some
Makefile files:
-
- gpac/applications/{mp4client,mp4box,mp4ts}/Makefile:
-
...
$(LINKLIBS)
$(JS_LIBS)
- 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'
-
- 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:
-
- make sure that extra_lib is not refrenced by
configure:
-
- 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:
-
- 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'
-
undefined reference to JS_ClearNewbornRoots
-
- solved in rev
3646
- solution: check that "ldd libgpac.so" points
to the correct libmozjs.so (libxulrunner-x.y.z)
-
- solution: disable js support
-
- 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
-
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:
-
- 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:
-
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:
-
- 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
-
- 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 :
-
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
-
- 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
cd /c/.../gpac_extra_libs/lib
- 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
- compile the rest of gpac_extra_libs with MS Visual:
- Open build\msvc6\BuildAll.dsw
- compile gpac with MSVisual 6.0
-
- Open gpac\build\msvc6\gpac.dsw
- set gpac_dll as active (StartUp) project
- 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
-
- Be sure you have VS2005 and WM
5.0
Developer Resource Kit installed
- From the VS2005 open the solution file for WM5
located at: <download folder>\build\wm5\wm5.sln
- Select the correct solution configuration and platform
(Debug/Release and Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)
- Connect you device using the USB cable and verify that you
can communicate with it (Explore from the ActiveSync)
- Compile and deploy as usual
|