[FFmpeg-devel] [PATCH] ffprobe: Add bits_per_component to stream output
Tobias Rapp
t.rapp at noa-audio.com
Thu Sep 4 14:39:51 CEST 2014
Attached patch adds bits_per_component (bit depth) output for video streams.
-------------- next part --------------
>From ea0e6884d42d3fe9e16565920b2c06c89015ff09 Mon Sep 17 00:00:00 2001
From: Tobias Rapp <t.rapp at noa-audio.com>
Date: Thu, 4 Sep 2014 14:16:29 +0200
Subject: [PATCH] ffprobe: Add bits_per_component to stream output
Adds bits_per_component (bit depth) output for video streams.
---
ffprobe.c | 6 ++++++
libavutil/pixdesc.c | 16 ++++++++++++++++
libavutil/pixdesc.h | 7 +++++++
tests/ref/fate/ffprobe_compact | 4 ++--
tests/ref/fate/ffprobe_csv | 4 ++--
tests/ref/fate/ffprobe_default | 2 ++
tests/ref/fate/ffprobe_flat | 2 ++
tests/ref/fate/ffprobe_ini | 2 ++
tests/ref/fate/ffprobe_json | 2 ++
tests/ref/fate/ffprobe_xml | 4 ++--
10 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/ffprobe.c b/ffprobe.c
index 2d48070..9b0a87d 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -2031,6 +2031,7 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id
AVRational sar, dar;
AVBPrint pbuf;
const AVCodecDescriptor *cd;
+ const AVPixFmtDescriptor *pix_desc;
int ret = 0;
av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
@@ -2096,6 +2097,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id
s = av_get_pix_fmt_name(dec_ctx->pix_fmt);
if (s) print_str ("pix_fmt", s);
else print_str_opt("pix_fmt", "unknown");
+ pix_desc = av_pix_fmt_desc_get(dec_ctx->pix_fmt);
+ if (pix_desc)
+ print_int ("bits_per_component", av_get_bits_per_component(pix_desc));
+ else
+ print_str_opt("bits_per_component", "N/A");
print_int("level", dec_ctx->level);
if (dec_ctx->color_range != AVCOL_RANGE_UNSPECIFIED)
print_str ("color_range", dec_ctx->color_range == AVCOL_RANGE_MPEG ? "tv": "pc");
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 154392a..5ecb53a 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -1980,6 +1980,22 @@ int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
return bits >> log2_pixels;
}
+int av_get_bits_per_component(const AVPixFmtDescriptor *pixdesc)
+{
+ int c, bits, first_bits = 0;
+ int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
+
+ for (c = 0; c < pixdesc->nb_components; c++) {
+ bits = pixdesc->comp[c].depth_minus1 + 1;
+ if (c == 0)
+ first_bits = bits;
+ else if (bits != first_bits)
+ return 0;
+ }
+
+ return first_bits;
+}
+
char *av_get_pix_fmt_string(char *buf, int buf_size,
enum AVPixelFormat pix_fmt)
{
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index 41e81db..f8af18f 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -251,6 +251,13 @@ int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
/**
+ * Return the number of bits per component (bit depth) for the pixel format
+ * described by pixdesc or 0 if the pixel format has unknown or non-uniform
+ * bit depth.
+ */
+int av_get_bits_per_component(const AVPixFmtDescriptor *pixdesc);
+
+/**
* @return a pixel format descriptor for provided pixel format or NULL if
* this pixel format is unknown.
*/
diff --git a/tests/ref/fate/ffprobe_compact b/tests/ref/fate/ffprobe_compact
index ad646af..0863b6f 100644
--- a/tests/ref/fate/ffprobe_compact
+++ b/tests/ref/fate/ffprobe_compact
@@ -27,6 +27,6 @@ frame|media_type=video|key_frame=1|pkt_pts=6144|pkt_pts_time=0.120000|pkt_dts=61
packet|codec_type=video|stream_index=2|pts=6144|pts_time=0.120000|dts=6144|dts_time=0.120000|duration=2048|duration_time=0.040000|convergence_duration=N/A|convergence_duration_time=N/A|size=30000|pos=1024801|flags=K
frame|media_type=video|key_frame=1|pkt_pts=6144|pkt_pts_time=0.120000|pkt_dts=6144|pkt_dts_time=0.120000|best_effort_timestamp=6144|best_effort_timestamp_time=0.120000|pkt_duration=2048|pkt_duration_time=0.040000|pkt_pos=1024801|pkt_size=30000|width=100|height=100|pix_fmt=rgb24|sample_aspect_ratio=1:1|pict_type=I|coded_picture_number=0|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0
stream|index=0|codec_name=pcm_s16le|profile=unknown|codec_type=audio|codec_time_base=1/44100|codec_tag_string=PSD[16]|codec_tag=0x10445350|sample_fmt=s16|sample_rate=44100|channels=1|channel_layout=unknown|bits_per_sample=16|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=N/A|duration=N/A|bit_rate=705600|max_bit_rate=N/A|nb_frames=N/A|nb_read_frames=6|nb_read_packets=6|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:E=mc²|tag:encoder=Lavc pcm_s16le
-stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|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:title=foobar|tag:duration_ts=field-and-tags-conflict-attempt|tag:encoder=Lavc rawvideo
-stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|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:encoder=Lavc rawvideo
+stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|bits_per_component=8|level=-99|color_range=N/A|color_space=unknown|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|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:title=foobar|tag:duration_ts=field-and-tags-conflict-attempt|tag:encoder=Lavc rawvideo
+stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|bits_per_component=8|level=-99|color_range=N/A|color_space=unknown|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|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:encoder=Lavc rawvideo
format|filename=tests/data/ffprobe-test.nut|nb_streams=3|nb_programs=0|format_name=nut|start_time=0.000000|duration=0.120000|size=1054882|bit_rate=70325466|probe_score=100|tag:title=ffprobe test file|tag:comment='A comment with CSV, XML & JSON special chars': <tag value="x">|tag:comment2=I � �ñîçød�
diff --git a/tests/ref/fate/ffprobe_csv b/tests/ref/fate/ffprobe_csv
index 219e571..14f5f4c 100644
--- a/tests/ref/fate/ffprobe_csv
+++ b/tests/ref/fate/ffprobe_csv
@@ -27,6 +27,6 @@ frame,video,1,6144,0.120000,6144,0.120000,6144,0.120000,2048,0.040000,794377,230
packet,video,2,6144,0.120000,6144,0.120000,2048,0.040000,N/A,N/A,30000,1024801,K
frame,video,1,6144,0.120000,6144,0.120000,6144,0.120000,2048,0.040000,1024801,30000,100,100,rgb24,1:1,I,0,0,0,0,0
stream,0,pcm_s16le,unknown,audio,1/44100,PSD[16],0x10445350,s16,44100,1,unknown,16,N/A,0/0,0/0,1/44100,0,0.000000,N/A,N/A,705600,N/A,N/A,6,6,0,0,0,0,0,0,0,0,0,0,0,mc²,Lavc pcm_s16le
-stream,1,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,320,240,0,1:1,4:3,rgb24,-99,N/A,unknown,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,foobar,field-and-tags-conflict-attempt,Lavc rawvideo
-stream,2,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,100,100,0,1:1,1:1,rgb24,-99,N/A,unknown,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,Lavc rawvideo
+stream,1,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,320,240,0,1:1,4:3,rgb24,8,-99,N/A,unknown,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,foobar,field-and-tags-conflict-attempt,Lavc rawvideo
+stream,2,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,100,100,0,1:1,1:1,rgb24,8,-99,N/A,unknown,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,Lavc rawvideo
format,tests/data/ffprobe-test.nut,3,0,nut,0.000000,0.120000,1054882,70325466,100,ffprobe test file,"'A comment with CSV, XML & JSON special chars': <tag value=""x"">",I � �ñîçød�
diff --git a/tests/ref/fate/ffprobe_default b/tests/ref/fate/ffprobe_default
index fa0f031..6b7efc5 100644
--- a/tests/ref/fate/ffprobe_default
+++ b/tests/ref/fate/ffprobe_default
@@ -562,6 +562,7 @@ has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=4:3
pix_fmt=rgb24
+bits_per_component=8
level=-99
color_range=N/A
color_space=unknown
@@ -608,6 +609,7 @@ has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=1:1
pix_fmt=rgb24
+bits_per_component=8
level=-99
color_range=N/A
color_space=unknown
diff --git a/tests/ref/fate/ffprobe_flat b/tests/ref/fate/ffprobe_flat
index e5866d2..055e8d6 100644
--- a/tests/ref/fate/ffprobe_flat
+++ b/tests/ref/fate/ffprobe_flat
@@ -503,6 +503,7 @@ streams.stream.1.has_b_frames=0
streams.stream.1.sample_aspect_ratio="1:1"
streams.stream.1.display_aspect_ratio="4:3"
streams.stream.1.pix_fmt="rgb24"
+streams.stream.1.bits_per_component=8
streams.stream.1.level=-99
streams.stream.1.color_range="N/A"
streams.stream.1.color_space="unknown"
@@ -547,6 +548,7 @@ streams.stream.2.has_b_frames=0
streams.stream.2.sample_aspect_ratio="1:1"
streams.stream.2.display_aspect_ratio="1:1"
streams.stream.2.pix_fmt="rgb24"
+streams.stream.2.bits_per_component=8
streams.stream.2.level=-99
streams.stream.2.color_range="N/A"
streams.stream.2.color_space="unknown"
diff --git a/tests/ref/fate/ffprobe_ini b/tests/ref/fate/ffprobe_ini
index 541022c..84bda2f 100644
--- a/tests/ref/fate/ffprobe_ini
+++ b/tests/ref/fate/ffprobe_ini
@@ -568,6 +568,7 @@ has_b_frames=0
sample_aspect_ratio=1\:1
display_aspect_ratio=4\:3
pix_fmt=rgb24
+bits_per_component=8
level=-99
color_range=N/A
color_space=unknown
@@ -618,6 +619,7 @@ has_b_frames=0
sample_aspect_ratio=1\:1
display_aspect_ratio=1\:1
pix_fmt=rgb24
+bits_per_component=8
level=-99
color_range=N/A
color_space=unknown
diff --git a/tests/ref/fate/ffprobe_json b/tests/ref/fate/ffprobe_json
index 29e8fe0..1f8bf22 100644
--- a/tests/ref/fate/ffprobe_json
+++ b/tests/ref/fate/ffprobe_json
@@ -556,6 +556,7 @@
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "4:3",
"pix_fmt": "rgb24",
+ "bits_per_component": 8,
"level": -99,
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
@@ -596,6 +597,7 @@
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "1:1",
"pix_fmt": "rgb24",
+ "bits_per_component": 8,
"level": -99,
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index 90353c4..ad4a22f 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -37,13 +37,13 @@
<tag key="E" value="mc²"/>
<tag key="encoder" value="Lavc pcm_s16le"/>
</stream>
- <stream index="1" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="320" height="240" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="4:3" pix_fmt="rgb24" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
+ <stream index="1" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="320" height="240" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="4:3" pix_fmt="rgb24" bits_per_component="8" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
<tag key="title" value="foobar"/>
<tag key="duration_ts" value="field-and-tags-conflict-attempt"/>
<tag key="encoder" value="Lavc rawvideo"/>
</stream>
- <stream index="2" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="100" height="100" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="1:1" pix_fmt="rgb24" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
+ <stream index="2" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="100" height="100" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="1:1" pix_fmt="rgb24" bits_per_component="8" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
<tag key="encoder" value="Lavc rawvideo"/>
</stream>
--
1.9.1
More information about the ffmpeg-devel
mailing list