Commit 1e488d43 authored by Thibault Saunier's avatar Thibault Saunier 🌵 Committed by Thibault Saunier

launcher: Use the output URI extension to set encoding format

And print a description of the encoding profile.
parent 5234885c
......@@ -504,8 +504,9 @@ _set_rendering_details (GESLauncher * self)
ParsedOptions *opts = &self->priv->parsed_options;
/* Setup profile/encoding if needed */
if (opts->smartrender || opts->outputuri) {
if (opts->outputuri) {
GstEncodingProfile *prof = NULL;
gchar *format = NULL;
if (!opts->format) {
GESProject *proj =
......@@ -525,15 +526,27 @@ _set_rendering_details (GESLauncher * self)
if (!prof) {
if (opts->format == NULL)
opts->format =
g_strdup ("application/ogg:video/x-theora:audio/x-vorbis");
opts->format = get_file_extension (opts->outputuri);
prof = parse_encoding_profile (opts->format);
}
if (!prof) {
warn ("No format specified and couldn't find one from output file extension, " "falling back to theora+vorbis in ogg.");
format = opts->format =
g_strdup ("application/ogg:video/x-theora:audio/x-vorbis");
prof = parse_encoding_profile (opts->format);
}
if (opts->outputuri)
opts->outputuri = ensure_uri (opts->outputuri);
g_free (format);
if (!prof) {
error ("Could not find any encoding format for %s\n", opts->format);
return FALSE;
}
g_print ("Encoding to:\n\n");
describe_encoding_profile (prof);
}
opts->outputuri = ensure_uri (opts->outputuri);
if (!prof
|| !ges_pipeline_set_render_settings (self->priv->pipeline,
opts->outputuri, prof)
......@@ -696,7 +709,9 @@ ges_launcher_get_rendering_option_group (GESLauncher * self)
GOptionEntry options[] = {
{"outputuri", 'o', 0, G_OPTION_ARG_STRING, &opts->outputuri,
"If set, ges-launch-1.0 will render the timeline instead of playing "
"it back. The default rendering format is ogv, containing theora and vorbis.",
"it back. If no format `--format` is specified, the outputuri extension"
" will be used to determine an encoding format, or default to theora+vorbis"
" in ogg if that doesn't work out.",
"<URI>"},
{"format", 'f', 0, G_OPTION_ARG_STRING, &opts->format,
"Set an encoding profile on the command line. "
......
......@@ -143,3 +143,146 @@ print_enum (GType enum_type)
g_type_class_unref (enum_class);
}
void
print (GstDebugColorFlags c, gboolean err, gboolean nline, const gchar * format,
va_list var_args)
{
GString *str = g_string_new (NULL);
GstDebugColorMode color_mode;
gchar *color = NULL;
const gchar *clear = NULL;
color_mode = gst_debug_get_color_mode ();
#ifdef G_OS_WIN32
if (color_mode == GST_DEBUG_COLOR_MODE_UNIX) {
#else
if (color_mode != GST_DEBUG_COLOR_MODE_OFF) {
#endif
clear = "\033[00m";
color = gst_debug_construct_term_color (c);
}
if (color) {
g_string_append (str, color);
g_free (color);
}
g_string_append_vprintf (str, format, var_args);
if (nline)
g_string_append_c (str, '\n');
if (clear)
g_string_append (str, clear);
if (err)
g_printerr ("%s", str->str);
else
g_print ("%s", str->str);
g_string_free (str, TRUE);
}
void
ok (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_GREEN, FALSE, TRUE, format, var_args);
va_end (var_args);
}
void
warn (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_YELLOW, TRUE, TRUE, format, var_args);
va_end (var_args);
}
void
error (const gchar * format, ...)
{
va_list var_args;
va_start (var_args, format);
print (GST_DEBUG_FG_RED, TRUE, TRUE, format, var_args);
va_end (var_args);
}
gchar *
get_file_extension (gchar * uri)
{
size_t len;
gint find;
len = strlen (uri);
find = len - 1;
while (find >= 0) {
if (uri[find] == '.')
break;
find--;
}
if (find <= 0)
return NULL;
return &uri[find + 1];
}
static const gchar *
get_profile_type (GstEncodingProfile * profile)
{
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile))
return "Container";
else if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
return "Audio";
else if (GST_IS_ENCODING_VIDEO_PROFILE (profile))
return "Video";
else
return "Unkonwn";
}
static void
print_profile (GstEncodingProfile * profile, const gchar * prefix)
{
const gchar *name = gst_encoding_profile_get_name (profile);
const gchar *desc = gst_encoding_profile_get_description (profile);
GstCaps *format = gst_encoding_profile_get_format (profile);
gchar *capsdesc;
if (gst_caps_is_fixed (format))
capsdesc = gst_pb_utils_get_codec_description (format);
else
capsdesc = gst_caps_to_string (format);
g_print ("%s%s: %s%s%s%s%s%s\n", prefix, get_profile_type (profile),
name ? name : capsdesc, desc ? ": " : "", desc ? desc : "",
name ? " (" : "", name ? capsdesc : "", name ? ")" : "");
gst_caps_unref (format);
g_free (capsdesc);
}
void
describe_encoding_profile (GstEncodingProfile * profile)
{
g_return_if_fail (GST_IS_ENCODING_PROFILE (profile));
print_profile (profile, " ");
if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
const GList *tmp;
for (tmp =
gst_encoding_container_profile_get_profiles
(GST_ENCODING_CONTAINER_PROFILE (profile)); tmp; tmp = tmp->next)
print_profile (tmp->data, " - ");
}
}
......@@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <gst/pbutils/pbutils.h>
#include <gst/pbutils/encoding-profile.h>
gchar * sanitize_timeline_description (int argc, char **argv);
......@@ -24,3 +25,11 @@ gboolean get_flags_from_string (GType type, const gchar * str_flags, guint *val)
gchar * ensure_uri (const gchar * location);
GstEncodingProfile * parse_encoding_profile (const gchar * format);
void print_enum (GType enum_type);
void print (GstDebugColorFlags c, gboolean err, gboolean nline, const gchar * format, va_list var_args);
void ok (const gchar * format, ...);
void warn (const gchar * format, ...);
void error (const gchar * format, ...);
gchar * get_file_extension (gchar * uri);
void describe_encoding_profile (GstEncodingProfile *profile);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment