Changed metadata print option to accept general urls
This is an - once again - updated patch, that uses avio_write instead of avio_puts to stream clean text output without null characters. Works now for me as intended. Changes metadata filter to accept general urls as file argument without breaking former behaviour. As a byproduct, it also allows for writing to file "-" if specified as "file:-". Example: ffmpeg -i test.wav -filter_complex "silencedetect=n=-40dB:d=0.1,ametadata=mode=print:file='pipe\:4'" -f null Signed-off-by: Sami Hult <sami.hult@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
e98ab799be
commit
d4c8e93190
@@ -49,6 +49,7 @@ version 3.1:
|
|||||||
- libutvideo wrapper removed
|
- libutvideo wrapper removed
|
||||||
- YUY2 Lossless Codec decoder
|
- YUY2 Lossless Codec decoder
|
||||||
- VideoToolbox H.264 encoder
|
- VideoToolbox H.264 encoder
|
||||||
|
- Changed metadata print option to accept general urls
|
||||||
|
|
||||||
|
|
||||||
version 3.0:
|
version 3.0:
|
||||||
|
@@ -9390,13 +9390,14 @@ Float representation of @code{value} from metadata key.
|
|||||||
|
|
||||||
@item VALUE2
|
@item VALUE2
|
||||||
Float representation of @code{value} as supplied by user in @code{value} option.
|
Float representation of @code{value} as supplied by user in @code{value} option.
|
||||||
@end table
|
|
||||||
|
|
||||||
@item file
|
@item file
|
||||||
If specified in @code{print} mode, output is written to the named file. When
|
If specified in @code{print} mode, output is written to the named file. Instead of
|
||||||
filename equals "-" data is written to standard output.
|
plain filename any writable url can be specified. Filename ``-'' is a shorthand
|
||||||
If @code{file} option is not set, output is written to the log with AV_LOG_INFO
|
for standard output. If @code{file} option is not set, output is written to the log
|
||||||
loglevel.
|
with AV_LOG_INFO loglevel.
|
||||||
|
@end table
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@subsection Examples
|
@subsection Examples
|
||||||
@@ -9406,8 +9407,18 @@ loglevel.
|
|||||||
Print all metadata values for frames with key @code{lavfi.singnalstats.YDIF} with values
|
Print all metadata values for frames with key @code{lavfi.singnalstats.YDIF} with values
|
||||||
between 0 and 1.
|
between 0 and 1.
|
||||||
@example
|
@example
|
||||||
@end example
|
|
||||||
signalstats,metadata=print:key=lavfi.signalstats.YDIF:value=0:function=expr:expr='between(VALUE1,0,1)'
|
signalstats,metadata=print:key=lavfi.signalstats.YDIF:value=0:function=expr:expr='between(VALUE1,0,1)'
|
||||||
|
@end example
|
||||||
|
@item
|
||||||
|
Print silencedetect output to file @file{metadata.txt}.
|
||||||
|
@example
|
||||||
|
silencedetect,ametadata=mode=print:file=metadata.txt
|
||||||
|
@end example
|
||||||
|
@item
|
||||||
|
Direct all metadata to a pipe with file descriptor 4.
|
||||||
|
@example
|
||||||
|
metadata=mode=print:file='pipe\:4'
|
||||||
|
@end example
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
@section mpdecimate
|
@section mpdecimate
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "libavutil/internal.h"
|
#include "libavutil/internal.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
#include "libavutil/timestamp.h"
|
#include "libavutil/timestamp.h"
|
||||||
|
#include "libavformat/avio.h"
|
||||||
#include "avfilter.h"
|
#include "avfilter.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "formats.h"
|
#include "formats.h"
|
||||||
@@ -80,7 +81,7 @@ typedef struct MetadataContext {
|
|||||||
AVExpr *expr;
|
AVExpr *expr;
|
||||||
double var_values[VAR_VARS_NB];
|
double var_values[VAR_VARS_NB];
|
||||||
|
|
||||||
FILE *file;
|
AVIOContext* avio_context;
|
||||||
char *file_str;
|
char *file_str;
|
||||||
|
|
||||||
int (*compare)(struct MetadataContext *s,
|
int (*compare)(struct MetadataContext *s,
|
||||||
@@ -180,8 +181,11 @@ static void print_file(AVFilterContext *ctx, const char *msg, ...)
|
|||||||
va_list argument_list;
|
va_list argument_list;
|
||||||
|
|
||||||
va_start(argument_list, msg);
|
va_start(argument_list, msg);
|
||||||
if (msg)
|
if (msg) {
|
||||||
vfprintf(s->file, msg, argument_list);
|
char buf[128];
|
||||||
|
vsnprintf(buf, sizeof(buf), msg, argument_list);
|
||||||
|
avio_write(s->avio_context, buf, av_strnlen(buf, sizeof(buf)));
|
||||||
|
}
|
||||||
va_end(argument_list);
|
va_end(argument_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,25 +240,29 @@ static av_cold int init(AVFilterContext *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->file_str) {
|
if (s->mode == METADATA_PRINT && s->file_str) {
|
||||||
if (!strcmp(s->file_str, "-")) {
|
|
||||||
s->file = stdout;
|
|
||||||
} else {
|
|
||||||
s->file = fopen(s->file_str, "w");
|
|
||||||
if (!s->file) {
|
|
||||||
int err = AVERROR(errno);
|
|
||||||
char buf[128];
|
|
||||||
av_strerror(err, buf, sizeof(buf));
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Could not open file %s: %s\n",
|
|
||||||
s->file_str, buf);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s->print = print_file;
|
s->print = print_file;
|
||||||
} else {
|
} else {
|
||||||
s->print = print_log;
|
s->print = print_log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->avio_context = NULL;
|
||||||
|
if (s->file_str) {
|
||||||
|
if (!strcmp("-", s->file_str)) {
|
||||||
|
ret = avio_open(&s->avio_context, "pipe:1", AVIO_FLAG_WRITE);
|
||||||
|
} else {
|
||||||
|
ret = avio_open(&s->avio_context, s->file_str, AVIO_FLAG_WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
char buf[128];
|
||||||
|
av_strerror(ret, buf, sizeof(buf));
|
||||||
|
av_log(ctx, AV_LOG_ERROR, "Could not open %s: %s\n",
|
||||||
|
s->file_str, buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,9 +270,9 @@ static av_cold void uninit(AVFilterContext *ctx)
|
|||||||
{
|
{
|
||||||
MetadataContext *s = ctx->priv;
|
MetadataContext *s = ctx->priv;
|
||||||
|
|
||||||
if (s->file && s->file != stdout)
|
if (s->avio_context) {
|
||||||
fclose(s->file);
|
avio_closep(&s->avio_context);
|
||||||
s->file = NULL;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
||||||
|
Reference in New Issue
Block a user