Skip to content

Commit

Permalink
ffprobe: extend disposition printing support
Browse files Browse the repository at this point in the history
This generalizes the previous work on disposition printing.

Disposition flags are shown in a dedicated section, which should improve
output intellegibility, extensibility and filtering operations.

This breaks output syntax with the recently introduced disposition
printing.
  • Loading branch information
saste committed Sep 30, 2012
1 parent 50efde6 commit 301f6da
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 53 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest.

version next:
- stream disposition information printing in ffprobe


version 1.0:
Expand Down
18 changes: 15 additions & 3 deletions doc/ffprobe.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,24 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="streamDispositionType">
<xsd:attribute name="default" type="xsd:int" use="required" />
<xsd:attribute name="dub" type="xsd:int" use="required" />
<xsd:attribute name="original" type="xsd:int" use="required" />
<xsd:attribute name="comment" type="xsd:int" use="required" />
<xsd:attribute name="lyrics" type="xsd:int" use="required" />
<xsd:attribute name="karaoke" type="xsd:int" use="required" />
<xsd:attribute name="forced" type="xsd:int" use="required" />
<xsd:attribute name="hearing_impaired" type="xsd:int" use="required" />
<xsd:attribute name="visual_impaired" type="xsd:int" use="required" />
<xsd:attribute name="clean_effects" type="xsd:int" use="required" />
<xsd:attribute name="attached_pic" type="xsd:int" use="required" />
</xsd:complexType>

<xsd:complexType name="streamType">
<xsd:sequence>
<xsd:element name="tag" type="ffprobe:tagType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="disposition" type="ffprobe:streamDispositionType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>

<xsd:attribute name="index" type="xsd:int" use="required"/>
Expand All @@ -100,8 +115,6 @@
<xsd:attribute name="codec_tag" type="xsd:string" use="required"/>
<xsd:attribute name="codec_tag_string" type="xsd:string" use="required"/>
<xsd:attribute name="extradata" type="xsd:string" />
<xsd:attribute name="default" type="xsd:int" use="required"/>
<xsd:attribute name="forced" type="xsd:int" use="required"/>

<!-- video attributes -->
<xsd:attribute name="width" type="xsd:int"/>
Expand All @@ -112,7 +125,6 @@
<xsd:attribute name="pix_fmt" type="xsd:string"/>
<xsd:attribute name="level" type="xsd:int"/>
<xsd:attribute name="timecode" type="xsd:string"/>
<xsd:attribute name="attached_pic" type="xsd:int"/>

<!-- audio attributes -->
<xsd:attribute name="sample_fmt" type="xsd:string"/>
Expand Down
28 changes: 22 additions & 6 deletions ffprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef enum {
SECTION_ID_PROGRAM_VERSION,
SECTION_ID_ROOT,
SECTION_ID_STREAM,
SECTION_ID_STREAM_DISPOSITION,
SECTION_ID_STREAMS,
SECTION_ID_STREAM_TAGS
} SectionID;
Expand All @@ -119,6 +120,7 @@ static const struct section sections[] = {
[SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version" },
[SECTION_ID_ROOT] = { SECTION_ID_ROOT, "root", SECTION_FLAG_IS_WRAPPER },
[SECTION_ID_STREAM] = { SECTION_ID_STREAM, "stream" },
[SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition" },
[SECTION_ID_STREAMS] = { SECTION_ID_STREAMS, "streams", SECTION_FLAG_IS_ARRAY },
[SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, .element_name = "tag" },
};
Expand Down Expand Up @@ -1682,10 +1684,6 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
print_str("codec_tag_string", val_str);
print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag);

/* Print useful disposition */
print_int("default", !!(stream->disposition & AV_DISPOSITION_DEFAULT));
print_int("forced", !!(stream->disposition & AV_DISPOSITION_FORCED));

switch (dec_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
print_int("width", dec_ctx->width);
Expand Down Expand Up @@ -1714,8 +1712,6 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
} else {
print_str_opt("timecode", "N/A");
}
print_int("attached_pic",
!!(stream->disposition & AV_DISPOSITION_ATTACHED_PIC));
break;

case AVMEDIA_TYPE_AUDIO:
Expand Down Expand Up @@ -1762,6 +1758,26 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
if (do_show_data)
writer_print_data(w, "extradata", dec_ctx->extradata,
dec_ctx->extradata_size);

/* Print disposition information */
#define PRINT_DISPOSITION(flagname, name) do { \
print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
} while (0)

writer_print_section_header(w, SECTION_ID_STREAM_DISPOSITION);
PRINT_DISPOSITION(DEFAULT, "default");
PRINT_DISPOSITION(DUB, "dub");
PRINT_DISPOSITION(ORIGINAL, "original");
PRINT_DISPOSITION(COMMENT, "comment");
PRINT_DISPOSITION(LYRICS, "lyrics");
PRINT_DISPOSITION(KARAOKE, "karaoke");
PRINT_DISPOSITION(FORCED, "forced");
PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
writer_print_section_footer(w);

show_tags(w, stream->metadata, SECTION_ID_STREAM_TAGS);

writer_print_section_footer(w);
Expand Down
6 changes: 3 additions & 3 deletions tests/ref/fate/ffprobe_compact
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packet|codec_type=video|stream_index=1|pts=3|pts_time=0.120000|dts=3|dts_time=0.
frame|media_type=video|key_frame=1|pkt_pts=3|pkt_pts_time=0.120000|pkt_dts=3|pkt_dts_time=0.120000|pkt_duration=1|pkt_duration_time=0.040000|pkt_pos=794128|width=320|height=240|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|reference=0
packet|codec_type=video|stream_index=2|pts=3|pts_time=0.120000|dts=3|dts_time=0.120000|duration=1|duration_time=0.040000|convergence_duration=N/A|convergence_duration_time=N/A|size=30000|pos=1024550|flags=K
frame|media_type=video|key_frame=1|pkt_pts=3|pkt_pts_time=0.120000|pkt_dts=3|pkt_dts_time=0.120000|pkt_duration=1|pkt_duration_time=0.040000|pkt_pos=1024550|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|reference=0
stream|index=0|codec_name=pcm_s16le|profile=unknown|codec_type=audio|codec_time_base=1/44100|codec_tag_string=[1][0][0][0]|codec_tag=0x0001|default=0|forced=0|sample_fmt=s16|sample_rate=44100|channels=1|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=527313|duration=11.957211|bit_rate=705600|nb_frames=N/A|nb_read_frames=6|nb_read_packets=6
stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|codec_tag_string=RGB[24]|codec_tag=0x18424752|default=0|forced=0|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|level=-99|timecode=N/A|attached_pic=0|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4
stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|codec_tag_string=RGB[24]|codec_tag=0x18424752|default=0|forced=0|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|level=-99|timecode=N/A|attached_pic=0|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4
stream|index=0|codec_name=pcm_s16le|profile=unknown|codec_type=audio|codec_time_base=1/44100|codec_tag_string=[1][0][0][0]|codec_tag=0x0001|sample_fmt=s16|sample_rate=44100|channels=1|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=527313|duration=11.957211|bit_rate=705600|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
stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|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|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|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
stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|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|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|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
format|filename=tests/data/ffprobe-test.nut|nb_streams=3|format_name=nut|start_time=0.000000|duration=11.960000|size=1054625|bit_rate=705434|tag:title=ffprobe test file|tag:comment='A comment with CSV, XML & JSON special chars': <tag value="x">|tag:comment2=I ♥ Üñîçød€
6 changes: 3 additions & 3 deletions tests/ref/fate/ffprobe_csv
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packet,video,1,3,0.120000,3,0.120000,1,0.040000,N/A,N/A,230400,794128,K
frame,video,1,3,0.120000,3,0.120000,1,0.040000,794128,320,240,rgb24,1:1,I,0,0,0,0,0,0
packet,video,2,3,0.120000,3,0.120000,1,0.040000,N/A,N/A,30000,1024550,K
frame,video,1,3,0.120000,3,0.120000,1,0.040000,1024550,100,100,rgb24,1:1,I,0,0,0,0,0,0
stream,0,pcm_s16le,unknown,audio,1/44100,[1][0][0][0],0x0001,0,0,s16,44100,1,16,N/A,0/0,0/0,1/44100,0,0.000000,527313,11.957211,705600,N/A,6,6
stream,1,rawvideo,unknown,video,1/25,RGB[24],0x18424752,0,0,320,240,0,1:1,4:3,rgb24,-99,N/A,0,N/A,25/1,0/0,1/25,0,0.000000,299,11.960000,N/A,N/A,4,4
stream,2,rawvideo,unknown,video,1/25,RGB[24],0x18424752,0,0,100,100,0,1:1,1:1,rgb24,-99,N/A,0,N/A,25/1,0/0,1/25,0,0.000000,299,11.960000,N/A,N/A,4,4
stream,0,pcm_s16le,unknown,audio,1/44100,[1][0][0][0],0x0001,s16,44100,1,16,N/A,0/0,0/0,1/44100,0,0.000000,527313,11.957211,705600,N/A,6,6,0,0,0,0,0,0,0,0,0,0,0
stream,1,rawvideo,unknown,video,1/25,RGB[24],0x18424752,320,240,0,1:1,4:3,rgb24,-99,N/A,N/A,25/1,0/0,1/25,0,0.000000,299,11.960000,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0
stream,2,rawvideo,unknown,video,1/25,RGB[24],0x18424752,100,100,0,1:1,1:1,rgb24,-99,N/A,N/A,25/1,0/0,1/25,0,0.000000,299,11.960000,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0
format,tests/data/ffprobe-test.nut,3,nut,0.000000,11.960000,1054625,705434,ffprobe test file,"'A comment with CSV, XML & JSON special chars': <tag value=""x"">",I ♥ Üñîçød€
41 changes: 33 additions & 8 deletions tests/ref/fate/ffprobe_default
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,6 @@ codec_type=audio
codec_time_base=1/44100
codec_tag_string=[1][0][0][0]
codec_tag=0x0001
default=0
forced=0
sample_fmt=s16
sample_rate=44100
channels=1
Expand All @@ -500,6 +498,17 @@ bit_rate=705600
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
[/STREAM]
[STREAM]
index=1
Expand All @@ -509,8 +518,6 @@ codec_type=video
codec_time_base=1/25
codec_tag_string=RGB[24]
codec_tag=0x18424752
default=0
forced=0
width=320
height=240
has_b_frames=0
Expand All @@ -519,7 +526,6 @@ display_aspect_ratio=4:3
pix_fmt=rgb24
level=-99
timecode=N/A
attached_pic=0
id=N/A
r_frame_rate=25/1
avg_frame_rate=0/0
Expand All @@ -532,6 +538,17 @@ 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
[/STREAM]
[STREAM]
index=2
Expand All @@ -541,8 +558,6 @@ codec_type=video
codec_time_base=1/25
codec_tag_string=RGB[24]
codec_tag=0x18424752
default=0
forced=0
width=100
height=100
has_b_frames=0
Expand All @@ -551,7 +566,6 @@ display_aspect_ratio=1:1
pix_fmt=rgb24
level=-99
timecode=N/A
attached_pic=0
id=N/A
r_frame_rate=25/1
avg_frame_rate=0/0
Expand All @@ -564,6 +578,17 @@ 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
[/STREAM]
[FORMAT]
filename=tests/data/ffprobe-test.nut
Expand Down
41 changes: 33 additions & 8 deletions tests/ref/fate/ffprobe_flat
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ streams.stream.0.codec_type="audio"
streams.stream.0.codec_time_base="1/44100"
streams.stream.0.codec_tag_string="[1][0][0][0]"
streams.stream.0.codec_tag="0x0001"
streams.stream.0.default=0
streams.stream.0.forced=0
streams.stream.0.sample_fmt="s16"
streams.stream.0.sample_rate="44100"
streams.stream.0.channels=1
Expand All @@ -443,15 +441,24 @@ streams.stream.0.bit_rate="705600"
streams.stream.0.nb_frames="N/A"
streams.stream.0.nb_read_frames="6"
streams.stream.0.nb_read_packets="6"
streams.stream.0.disposition.default=0
streams.stream.0.disposition.dub=0
streams.stream.0.disposition.original=0
streams.stream.0.disposition.comment=0
streams.stream.0.disposition.lyrics=0
streams.stream.0.disposition.karaoke=0
streams.stream.0.disposition.forced=0
streams.stream.0.disposition.hearing_impaired=0
streams.stream.0.disposition.visual_impaired=0
streams.stream.0.disposition.clean_effects=0
streams.stream.0.disposition.attached_pic=0
streams.stream.1.index=1
streams.stream.1.codec_name="rawvideo"
streams.stream.1.profile="unknown"
streams.stream.1.codec_type="video"
streams.stream.1.codec_time_base="1/25"
streams.stream.1.codec_tag_string="RGB[24]"
streams.stream.1.codec_tag="0x18424752"
streams.stream.1.default=0
streams.stream.1.forced=0
streams.stream.1.width=320
streams.stream.1.height=240
streams.stream.1.has_b_frames=0
Expand All @@ -460,7 +467,6 @@ streams.stream.1.display_aspect_ratio="4:3"
streams.stream.1.pix_fmt="rgb24"
streams.stream.1.level=-99
streams.stream.1.timecode="N/A"
streams.stream.1.attached_pic=0
streams.stream.1.id="N/A"
streams.stream.1.r_frame_rate="25/1"
streams.stream.1.avg_frame_rate="0/0"
Expand All @@ -473,15 +479,24 @@ streams.stream.1.bit_rate="N/A"
streams.stream.1.nb_frames="N/A"
streams.stream.1.nb_read_frames="4"
streams.stream.1.nb_read_packets="4"
streams.stream.1.disposition.default=0
streams.stream.1.disposition.dub=0
streams.stream.1.disposition.original=0
streams.stream.1.disposition.comment=0
streams.stream.1.disposition.lyrics=0
streams.stream.1.disposition.karaoke=0
streams.stream.1.disposition.forced=0
streams.stream.1.disposition.hearing_impaired=0
streams.stream.1.disposition.visual_impaired=0
streams.stream.1.disposition.clean_effects=0
streams.stream.1.disposition.attached_pic=0
streams.stream.2.index=2
streams.stream.2.codec_name="rawvideo"
streams.stream.2.profile="unknown"
streams.stream.2.codec_type="video"
streams.stream.2.codec_time_base="1/25"
streams.stream.2.codec_tag_string="RGB[24]"
streams.stream.2.codec_tag="0x18424752"
streams.stream.2.default=0
streams.stream.2.forced=0
streams.stream.2.width=100
streams.stream.2.height=100
streams.stream.2.has_b_frames=0
Expand All @@ -490,7 +505,6 @@ streams.stream.2.display_aspect_ratio="1:1"
streams.stream.2.pix_fmt="rgb24"
streams.stream.2.level=-99
streams.stream.2.timecode="N/A"
streams.stream.2.attached_pic=0
streams.stream.2.id="N/A"
streams.stream.2.r_frame_rate="25/1"
streams.stream.2.avg_frame_rate="0/0"
Expand All @@ -503,6 +517,17 @@ streams.stream.2.bit_rate="N/A"
streams.stream.2.nb_frames="N/A"
streams.stream.2.nb_read_frames="4"
streams.stream.2.nb_read_packets="4"
streams.stream.2.disposition.default=0
streams.stream.2.disposition.dub=0
streams.stream.2.disposition.original=0
streams.stream.2.disposition.comment=0
streams.stream.2.disposition.lyrics=0
streams.stream.2.disposition.karaoke=0
streams.stream.2.disposition.forced=0
streams.stream.2.disposition.hearing_impaired=0
streams.stream.2.disposition.visual_impaired=0
streams.stream.2.disposition.clean_effects=0
streams.stream.2.disposition.attached_pic=0
format.filename="tests/data/ffprobe-test.nut"
format.nb_streams=3
format.format_name="nut"
Expand Down
Loading

0 comments on commit 301f6da

Please sign in to comment.