View Full Version : Can I get ffmpeg to add more metadata? (average bitrate, stream size)
mzso
22nd February 2014, 19:46
Hello!
I was wondering if there is a way to add more useful metadata to the output files encoded with ffmpeg. Such as average bitrate and stream size.
I noticed on some files I have that have stream size available and bitrate. Granted they're all cbr streams. While I mostly use flac and x264/crf which are vbr.
Now I guess it would be possible for ffmpeg to calculate the average bitrate and surely it could determine the stream size while encoding. And then write it in the metadata.
Can I get it to do such things?
raffriff42
23rd February 2014, 03:46
It seems to me, average bitrate & stream size are not metadata, they are *data*.
In ffmpeg-speak, or video-speak in general, by my understanding, metadata are things you can edit without altering the streams; conversely, you can alter the streams without changing the metadata. Doing so might have consequences though, for example you could mislabel a French audio track as Swahili.
FFmpeg always gives you duration and kb/s. From that you can calculate approximate stream size. So kb/s and stream size are equivalent; they are just formatted or viewed differently.
Perhaps you could describe what you are trying to do, and what software you are using to do it.
mzso
23rd February 2014, 12:09
FFmpeg always gives you duration and kb/s. From that you can calculate approximate stream size. So kb/s and stream size are equivalent; they are just formatted or viewed differently.
Perhaps you could describe what you are trying to do, and what software you are using to do it.
Not as far as I can tell. Mediainfo doesn't show this information for VBR files.
Ffmpeg outputs a short summary on the command line about the stream sizes and libx264 a bit of data including bitrate (no such thing for audio), but that's it. The file doesn't have any information.
foxyshadis
25th February 2014, 00:44
What format? Nearly all of them allow you to insert a "comment" field (FLV and TS are notable exceptions), and some let you also make up your own field names.
See Multimedia Wiki (http://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata).
smok3
25th February 2014, 11:05
Not as far as I can tell. Mediainfo doesn't show this information for VBR files.
What exact command are you using? (It certainly does here)
mzso
25th February 2014, 13:50
FFmpeg always gives you duration and kb/s. From that you can calculate approximate stream size. So kb/s and stream size are equivalent; they are just formatted or viewed differently.
Only for the whole file A+V plus container overhead.
But I think now, that I may have been wrong in stream size being available for CBR streams maybe mediainfo just calculates it from length and bitrate, which are apparently both missing for VBR. (length I don't know why, bitrate could be average)
mzso
25th February 2014, 13:52
What exact command are you using? (It certainly does here)
Well I was using libx264 crf and flac into matroska. Doubt the exact CL is relevant, because I never get such data with mediainfo.
But here's one anyway:
E:\Videó Felvételek>ffmpeg -i "E:\Videó Felvételek\fegyver.avi" -acodec flac -compression_level 12 -vcodec libx264 -preset slower -crf 18 -pix_fmt yuvj444p fegyver.mkv
And I get this in mediainfo:
General
Unique ID : 280337380296208646619607613988431305268 (0xD2E703F96770F06F199FB4499B8D9A34)
Complete name : E:\Videó Felvételek\fegyver.mkv
Format : Matroska
Format version : Version 4 / Version 2
File size : 10.6 MiB
Duration : 23s 134ms
Overall bit rate mode : Variable
Overall bit rate : 3 832 Kbps
Writing application : Lavf55.33.100
Writing library : Lavf55.33.100
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High 4:4:4 Predictive@L5.0
Format settings, CABAC : Yes
Format settings, ReFrames : 8 frames
Codec ID : V_MPEG4/ISO/AVC
Width : 1 600 pixels
Height : 1 200 pixels
Display aspect ratio : 4:3
Frame rate mode : Variable
Color space : YUV
Chroma subsampling : 4:4:4
Bit depth : 8 bits
Scan type : Progressive
Writing library : x264 core 142 r2389 956c8d8
Encoding settings : cabac=1 / ref=8 / deblock=1:0:0 / analyse=0x3:0x133 / me=umh / subme=9 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=4 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=60 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Default : Yes
Forced : No
Audio
ID : 2
Format : FLAC
Format/Info : Free Lossless Audio Codec
Codec ID : A_FLAC
Duration : 23s 133ms
Bit rate mode : Variable
Channel(s) : 2 channels
Sampling rate : 44.1 KHz
Bit depth : 16 bits
Default : Yes
Forced : No
(Edit: Wow. The website handles the code tag really poorly...)
What format? Nearly all of them allow you to insert a "comment" field (FLV and TS are notable exceptions), and some let you also make up your own field names.
See Multimedia Wiki (http://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata).
I was thinking of something automatic. Such as the info ffmpeg outputs to the Command line when the encoding is finished:
video:9931kB audio:883kB subtitle:0 data:0 global headers:0kB muxing overhead 0.055807%
[libx264 @ 040bab40] kb/s:3754.65
mzso
2nd March 2014, 19:40
I happen to have an film encoded some years ago. Mediainfo shows bitrate, size and percentage for the streams. It would be nice to have this information for my encodes with ffmpeg.
General
Unique ID : 182242376286034021910681325023762233656 (0x891A9ADED378FCA69E7851D4AC86B938)
Complete name : [file path]
Format : Matroska
Format version : Version 1
File size : 7.68 GiB
Duration : 1h 39mn
Overall bit rate : 11.0 Mbps
Encoded date : UTC 2009-10-04 13:35:14
Writing application : mkvmerge v2.4.1 ('Use Me') built on Dec 5 2008 15:43:32
Writing library : libebml v0.7.7 + libmatroska v0.8.1
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings, CABAC : Yes
Format settings, ReFrames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 39mn
Bit rate : 9 318 Kbps
Width : 1 920 pixels
Height : 800 pixels
Display aspect ratio : 2.40:1
Frame rate mode : Constant
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.253
Stream size : 6.47 GiB (84%)
Title : [movie title]
Writing library : x264 core 68 r1183M f21daff
Encoding settings : cabac=1 / ref=4 / deblock=1:-3:-3 / analyse=0x3:0x113 / me=umh / subme=9 / psy_rd=1.0:0.0 / mixed_ref=1 / me_range=48 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=-2 / threads=12 / nr=0 / decimate=1 / mbaff=0 / bframes=8 / b_pyramid=1 / b_adapt=2 / b_bias=0 / direct=2 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=40 / rc=crf / crf=20.0 / qcomp=0.70 / qpmin=10 / qpmax=51 / qpstep=4 / vbv_maxrate=50000 / vbv_bufsize=50000 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:0.80
Language : English
Default : Yes
Forced : No
Audio
ID : 2
Format : DTS
Format/Info : Digital Theater Systems
Mode : 16
Format settings, Endianness : Big
Codec ID : A_DTS
Duration : 1h 39mn
Bit rate mode : Constant
Bit rate : 1 510 Kbps
Channel(s) : 6 channels
Channel positions : Front: L C R, Side: L R, LFE
Sampling rate : 48.0 KHz
Bit depth : 24 bits
Compression mode : Lossy
Stream size : 1.05 GiB (14%)
Title : DTS 1536 kbps
Language : English
Default : Yes
Forced : No
Text #1
ID : 3
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Language : English
Default : Yes
Forced : No
Text #2
ID : 4
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Language : Dutch
Default : No
Forced : No
Menu
00:00:00.000 : en:00:00:00.000
00:06:54.623 : en:00:06:54.623
00:17:00.436 : en:00:17:00.436
00:22:38.691 : en:00:22:38.691
00:27:58.886 : en:00:27:58.886
00:37:32.292 : en:00:37:32.292
00:44:22.577 : en:00:44:22.577
00:54:06.577 : en:00:54:06.577
01:01:01.825 : en:01:01:01.825
01:12:51.701 : en:01:12:51.701
01:21:52.616 : en:01:21:52.616
01:34:00.802 : en:01:34:00.802
On the other hand ffprobe can't provide any of the information
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=104271/5000000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=800
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=12:5
pix_fmt=yuv420p
level=41
timecode=N/A
id=N/A
r_frame_rate=13978/583
avg_frame_rate=13978/583
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
nb_frames=N/A
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
TAG:language=eng
TAG:title=[movie title]
index=1
codec_name=dca
codec_long_name=DCA (DTS Coherent Acoustics)
profile=DTS
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=6
channel_layout=5.1(side)
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=1536000
nb_frames=N/A
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
TAG:language=eng
TAG:title=DTS 1536 kbps
index=2
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=N/A
height=N/A
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=5969015
duration=5969.015000
bit_rate=N/A
nb_frames=N/A
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
TAG:language=eng
index=3
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=N/A
height=N/A
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=5969015
duration=5969.015000
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
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
TAG:language=dut
filename=[file name]
nb_streams=4
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=5969.015000
size=8242961864
bit_rate=11047667
probe_score=100
TAG:encoder=libebml v0.7.7 + libmatroska v0.8.1
TAG:creation_time=2009-10-04 13:35:14
ffprobe version N-60813-g44b22bb Copyright (c) 2007-2014 the FFmpeg developers
built on Feb 22 2014 03:11:45 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
[matroska,webm @ 03f13f40] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
st:1 removing common factor 1000000 from timebase
st:2 removing common factor 1000000 from timebase
st:3 removing common factor 1000000 from timebase
[matroska,webm @ 03f13f40] Before avformat_find_stream_info() pos: 6391 bytes read:32768 seeks:0
[h264 @ 03f25220] no picture
[dca @ 03f25820] Stream with high frequencies VQ coding
[matroska,webm @ 03f13f40] All info found
[matroska,webm @ 03f13f40] After avformat_find_stream_info() pos: 39749 bytes read:65536 seeks:0 frames:20
Input #0, matroska,webm, from '[file name]':
Metadata:
encoder : libebml v0.7.7 + libmatroska v0.8.1
creation_time : 2009-10-04 13:35:14
Duration: 01:39:29.02, start: 0.000000, bitrate: 11047 kb/s
Chapter #0.0: start 0.000000, end 414.623000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 414.623000, end 1020.436000
Metadata:
title : 00:06:54.623
Chapter #0.2: start 1020.436000, end 1358.691000
Metadata:
title : 00:17:00.436
Chapter #0.3: start 1358.691000, end 1678.886000
Metadata:
title : 00:22:38.691
Chapter #0.4: start 1678.886000, end 2252.292000
Metadata:
title : 00:27:58.886
Chapter #0.5: start 2252.292000, end 2662.577000
Metadata:
title : 00:37:32.292
Chapter #0.6: start 2662.577000, end 3246.577000
Metadata:
title : 00:44:22.577
Chapter #0.7: start 3246.577000, end 3661.825000
Metadata:
title : 00:54:06.577
Chapter #0.8: start 3661.825000, end 4371.701000
Metadata:
title : 01:01:01.825
Chapter #0.9: start 4371.701000, end 4912.616000
Metadata:
title : 01:12:51.701
Chapter #0.10: start 4912.616000, end 5640.802000
Metadata:
title : 01:21:52.616
Chapter #0.11: start 5640.802000, end 5969.015000
Metadata:
title : 01:34:00.802
Stream #0:0(eng), 4, 1/1000: Video: h264 (High), yuv420p, 1920x800, 104271/5000000, SAR 1:1 DAR 12:5, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
title : [movie title]
Stream #0:1(eng), 16, 1/1000: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
Metadata:
title : DTS 1536 kbps
Stream #0:2(eng), 0, 1/1000: Subtitle: subrip (default)
Stream #0:3(dut), 0, 1/1000: Subtitle: subrip
detected 2 logical cores
[AVIOContext @ 0276e6a0] Statistics: 65536 bytes read, 0 seeks
sneaker_ger
2nd March 2014, 19:52
I happen to have an film encoded some years ago. Mediainfo shows bitrate, size and percentage for the streams. It would be nice to have this information for my encodes with ffmpeg.
That information is not stored as metadata anywhere in that file, MediaInfo just deduces it from total file size minus audio streams (- maybe overhead). This works for files with CBR audio, not with VBR audio. For 2pass it can indeed read the bitrate metadata x264 stores, though.
raffriff42
2nd March 2014, 21:31
>Wow. The website handles the code tag really poorly...
{Enter}{Enter}{Enter}
mzso
2nd March 2014, 22:23
That information is not stored as metadata anywhere in that file, MediaInfo just deduces it from total file size minus audio streams (- maybe overhead). This works for files with CBR audio, not with VBR audio. For 2pass it can indeed read the bitrate metadata x264 stores, though.
Alright then. Can I get ffmpeg to calculate and add such data as metada/comment or whatever. At least the summary at the end would be nice. (Stream sizes, muxing overhead)
>Wow. The website handles the code tag really poorly...
{Enter}{Enter}{Enter}
So I'm supposed to work now because of poor forum configuration? :)
sneaker_ger
2nd March 2014, 23:43
Alright then. Can I get ffmpeg to calculate and add such data as metada/comment or whatever. At least the summary at the end would be nice. (Stream sizes, muxing overhead)
I don't think so.
foxyshadis
4th March 2014, 01:13
You'll have to make a request to the ffmpeg people, or make your own patch and compile it yourself. I don't think ffmpeg's Matroska muxer can add metadata after streaming the file, though, so the only option might be to make a custom MediaInfo template that only shows the info you want in the format you want, and set up a batch file to obtain and remux the file with that information. Of course you need double the space.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.