cannot encode raw audio data to mpeg 4

narcisse doudieu siewe wambenarcisse at yahoo.fr
Sat Oct 5 08:32:38 PDT 2013


my code here for Gstreamer 1.0 :


#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>

typedef struct _UserData UserData;


struct _userData
{
    GstElement* encode;
    GstElement* decode;
    guint video_pad_num;
    guint audio_pad_num;
};




void pad_added_on_decode(GstElement* decode, GstPad* new_pad, gpointer data)
{
UserData *priv = (UserData *)data;

GstCaps* caps = gst_pad_query_caps(new_pad, NULL);
    GstPad* pad = NULL;

if(g_str_has_prefix(caps_repr, "video"))
{
    gchar* encode_video_sink_pad_name = g_strdup_printf("video_%"G_GUINT64_FORMAT, priv->video_pad_num);

        GstStaticPadTemplate static_tmpl = GST_STATIC_PAD_TEMPLATE("video_%u",
                                                                   GST_PAD_SINK,
                                                                   GST_PAD_REQUEST,
                                                                   GST_STATIC_CAPS_ANY);
        GstPadTemplate* video_tmpl = gst_static_pad_template_get(&static_tmpl);
        pad = gst_element_request_pad( priv->encode,
                                       video_tmpl,
                                       encode_video_sink_pad_name,
                                       NULL);
        g_free(encode_video_sink_pad_name);
        if(pad == NULL) goto not_handled;
        priv->video_pad_num++;
}

if(g_str_has_prefix(caps_repr, "audio"))
{
    gchar* encode_audio_sink_pad_name = g_strdup_printf("audio_%"G_GUINT64_FORMAT, priv->audio_pad_num);

        GstStaticPadTemplate static_tmpl = GST_STATIC_PAD_TEMPLATE("audio_%u",
                                                                   GST_PAD_SINK,
                                                                   GST_PAD_REQUEST,
                                                                   GST_STATIC_CAPS_ANY);

        GstPadTemplate* audio_tmpl = gst_static_pad_template_get(&static_tmpl);
        pad = gst_element_request_pad( priv->encode,
                                       audio_tmpl,
                                       encode_audio_sink_pad_name,
                                       NULL);
        g_free(encode_audio_sink_pad_name);
        if(pad == NULL) goto not_handled;
        priv->audio_pad_num++;
}

    if(gst_pad_can_link (new_pad, pad) && !gst_pad_is_linked(pad))
    {
      gst_pad_link(new_pad, pad);
      priv->pad_list = g_slist_append(priv->pad_list, (gpointer)pad);
    }
    else goto not_handled;

gst_caps_unref(caps);

return;

not_handled:;
{
        gst_element_release_request_pad(priv->encode, pad);
    }
}

void watch_on_bus(GstBus *bus, GstMessage* msg, gpointer data)
{
if(GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS)
{
    gst_element_set_state (GST_ELEMENT(priv->pipe), GST_STATE_NULL);
    gst_element_get_state (GST_ELEMENT(priv->pipe), NULL, NULL, GST_CLOCK_TIME_NONE);
}
}

int main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);
    gst_init(&argc, &argv);

    GFile* file;
    UserData  *p ,  user_data;

    if(argc < 2)
    {
      printf("Gives a file name to encode in AVI container and Mpeg audio and video datas\n\n");
      return -1;
    }
    else
    {
       file = g_file_new_for_path(argv[1]);
       if(!g_file_query_exists(file, NULL))
       {
          printf("Gives one  valid file name\n\n");
          return -1;
       }
    }
    // define a conatiner profile for encodebin

    GstCaps* caps = gst_caps_from_string("video/x-msvideo");
GstEncodingContainerProfile* container = gst_encoding_container_profile_new ("AVI_CONVERTER",
                                                                             "AVI_PROFILE", caps, NULL);
    gst_caps_unref(caps);
    g_object_ref(container);

    //create an audio profile

caps = gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT , 4, "layer", G_TYPE_INT , 3,
                           "rate", G_TYPE_INT, 8000, NULL);
GstEncodingAudio audio_profile =  gst_encoding_audio_profile_new(caps,
                                                      NULL, NULL, 0);
    gst_caps_unref(caps);

//create video profile
caps = gst_caps_new_simple("video/mpeg", "mpegversion", G_TYPE_INT, 4, "width", G_TYPE_INT, 1024,
                           "height", G_TYPE_INT, 576, "framerate", GST_TYPE_FRACTION, 25, 1, NULL);
video_profile =  gst_encoding_video_profile_new(caps,
                                                    NULL, NULL, 0);
    gst_caps_unref(caps);

    //add audio and vido profile to container profile

gst_encoding_container_profile_add_profile(priv->container, (GstEncodingProfile *)priv->video_profile);
gst_encoding_container_profile_add_profile(priv->container, (GstEncodingProfile *)priv->audio_profile);

//define elements for the pipeline

GstPipeline* pipe = GST_PIPELINE(gst_pipeline_new("pipe"));
g_object_ref(priv->pipe);
encode = gst_element_factory_make("encodebin", "encode");
decode = gst_element_factory_make("decodebin", "decode");
sink = gst_element_factory_make("filesink", "sink");
src = gst_element_factory_make("filesrc", "src");
gst_bin_add_many(GST_BIN(pipe), src, decode, encode, sink, NULL);

//set the defined profile on encode

g_object_set(G_OBJECT(priv->encode), "profile", priv->container, NULL);

//link elements together

gst_element_link(src, decode);
gst_element_link(encode, sink);
bus = gst_pipeline_get_bus (pipe);

//set a watch on bus a define some handler on it

gst_bus_add_signal_watch (bus);
g_signal_connect(G_OBJECT(priv->bus), "message", G_CALLBACK(watch_on_bus), NULL);

//sets a callback to handle the "pad-added" signal on decode

   //set user data to past to the handler
    user_data.encode = encode;
    user_data.decode = decode;
    user_data.video_pad_num = 0;
    user_data.audio_pad_num = 0;
    p = &user_data;

g_signal_connect(G_OBJECT(priv->decode), "pad-added", G_CALLBACK(padd_added_on_decode), (gpointer)p);

//place pipeline in a playing state

gst_element_set_state (GST_ELEMENT(priv->pipe), GST_STATE_PLAYING);
    gst_element_get_state (GST_ELEMENT(priv->pipe), NULL, NULL, GST_CLOCK_TIME_NONE);


    return 0;
}




________________________________
 De : narcisse doudieu siewe <wambenarcisse at yahoo.fr>
À : Discussion of the development of and with GStreamer <gstreamer-devel at lists.freedesktop.org> 
Envoyé le : Samedi 5 octobre 2013 11h52
Objet : Re: cannot encode raw audio data to mpeg 4
 


some codes in attachement


________________________________
 De : Tim-Philipp Müller <t.i.m at zen.co.uk>
À : gstreamer-devel at lists.freedesktop.org 
Envoyé le : Samedi 5 octobre 2013 8h42
Objet : Re: cannot encode raw audio data to mpeg 4
 

On Fri, 2013-10-04 at 21:31 +0100, narcisse doudieu siewe wrote:

Hi,

> I don't know but it seems that you cannot encode raw audio data to
> mpeg4 using encodebin
> 
> 
> another point:  you cannot request encodebin to convert change your
> audio sample rate to another sample rate say: 48000 samples/s to
> 8000samples/s
> Can some body test it??

Maybe you could make available a minimal test application that
demonstrates what doesn't work. That way people don't have to write
their own code to verify your claims.

It would also be good to mention your GStreamer version, and how things
fail.

Cheers
-Tim



_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel




_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20131005/b7a45d61/attachment-0003.html>


More information about the gstreamer-devel mailing list