MP_AFHI(channels)
/** \endcond */
+/**
+ * Return the duration of the audio file from the afh info structure.
+ *
+ * \param ctx See \ref mp_path().
+ *
+ * The duration is computed by multiplying the number of chunks and the
+ * duration of one chunk.
+ *
+ * \return The approximate number of milliseconds.
+ */
+int64_t mp_duration(struct mp_context *ctx)
+{
+ struct timeval tmp;
+ int ret = get_afhi(ctx);
+
+ if (ret < 0)
+ return 0;
+ tv_scale(ctx->afhi.chunks_total, &ctx->afhi.chunk_tv, &tmp);
+ return tv2ms(&tmp);
+}
+
/**
* Define a function which extracts and returns the value of a meta tag.
*
char *mp_path(struct mp_context *ctx);
int64_t mp_year(struct mp_context *ctx);
int64_t mp_num_attributes_set(struct mp_context *ctx);
+int64_t mp_duration(struct mp_context *ctx);
/* Generated with MP_AFSI() */
/** \cond MP_AFSI */
`bitrate` | integer | The average bitrate
`frequency` | integer | The output sample rate
`channels` | integer | The number of channels
+`duration` | integer | The number of milliseconds
`is_set("foo")` | boolean | True if attribute "foo" is set.
[\*] For most audio formats, the year tag is stored as a string. It
bitrate {return BITRATE;}
frequency {return FREQUENCY;}
channels {return CHANNELS;}
+duration {return DURATION;}
true {return TRUE;}
false {return FALSE;}
case CHANNELS:
result->intval= mp_channels(ctx);
return ST_INTVAL;
+ case DURATION:
+ result->intval= mp_duration(ctx);
+ return ST_INTVAL;
/* bools */
case IS_SET:
arg = node->children[0]->sv.strval;
%token <node> BITRATE
%token <node> FREQUENCY
%token <node> CHANNELS
+%token <node> DURATION
%token <node> FALSE TRUE
/* keywords without semantic value */
| BITRATE {$$ = mp_new_ast_leaf_node(BITRATE);}
| FREQUENCY {$$ = mp_new_ast_leaf_node(FREQUENCY);}
| CHANNELS {$$ = mp_new_ast_leaf_node(CHANNELS);}
+ | DURATION {$$ = mp_new_ast_leaf_node(DURATION);}
;
boolexp: IS_SET '(' STRING_LITERAL ')' {$$ = ast_node_new_unary(IS_SET, $3);}