Encode YUV420 buffer with appsrc
Antonio Ospite
ao2 at ao2.it
Tue Oct 10 21:46:14 UTC 2017
On Tue, 10 Oct 2017 11:25:58 -0700 (MST)
pchaurasia <pchaurasia at gameloreinc.com> wrote:
> Thanks Nicolas, for all the help.
>
> I wrote a small stand alone code to make simple encoder pipeline driven by
> appsrc. I think I followed all aforementioned suggestions from you.
>
With a test program it is easier to discuss.
If I may add a side note, it is possible to make the test program more
concise by using gst_parse_launch() to build the pipeline and retrieving
the app source with gst_bin_get_by_name(); something like:
data.pipeline = gst_parse_launch
("appsrc name=audio_source ! ... ! filesink location=test1.mp4",
NULL);
data.app_source =
gst_bin_get_by_name (GST_BIN (data.pipeline), "sound_source");
When asking for help try to provide the *minimum* program you can come
up with which still reproduces your problem.
> I am able to run it. I do get a compressed video file (test1.mp4), however,
> that file does not have much other than headers. I tried to play it using
> mplayer and it would not play. I think, I am missing something. Would be
> great if you could give a look to my code to spot the problem.
The problem seems to be about buffer timestamps, the buffers are created
successfully (you can verify that with this pipeline:
"appsrc name=audio_source ! fakesink dump=1"
but then they are discarded, presumably because they have invalid
timestamps.
The following patch is just a proof-of-concept which produces a valid
encoded video (note that I had to change some headers and use x264enc on
my system):
$ diff -pruN main.cpp.orig main.cpp
--- main.cpp.orig 2017-10-10 23:15:30.185947947 +0200
+++ main.cpp 2017-10-10 23:33:50.467881200 +0200
@@ -9,11 +9,9 @@
#include <string.h>
-#include "opencv2/imgcodecs.hpp"
-#include "opencv2/imgproc.hpp"
-#include "opencv2/videoio.hpp"
-#include <opencv2/highgui.hpp>
-#include <opencv2/video.hpp>
+#include "opencv2/imgproc/imgproc.hpp"
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/video/video.hpp>
#include <iostream>
@@ -158,6 +156,8 @@ static void start_feed (GstElement *sour
//ref buffer to give copy to appsrc
gst_buffer_ref(m_pgstBuffer);
+ GST_BUFFER_DTS (m_pgstBuffer) = 0;
+ GST_BUFFER_PTS (m_pgstBuffer) = 0;
g_print ("Signalling push-buffer with new buffer\n");
@@ -253,7 +253,7 @@ main (int argc, char * argv[])
data.app_source = gst_element_factory_make ("appsrc", "audio_source");
//data.app_sink = gst_element_factory_make ("appsink", "app_sink");
data.m_pvideoConvert = gst_element_factory_make("autovideoconvert", "aa-videoconvert");
- data.m_pencoder = gst_element_factory_make("omxh265enc", "aa-videoencoder");
+ data.m_pencoder = gst_element_factory_make("x264enc", "aa-videoencoder");
data.m_pmux = gst_element_factory_make("matroskamux", "aa-mux");
data.m_pfsink = gst_element_factory_make("filesink", "aa-filesink");
data.sourceid = 0;
@@ -285,6 +285,8 @@ main (int argc, char * argv[])
g_signal_connect (data.app_source, "need-data", G_CALLBACK (start_feed), &data);
g_signal_connect (data.app_source, "enough-data", G_CALLBACK (stop_feed), &data);
+ g_object_set (data.app_source, "format", GST_FORMAT_TIME, NULL);
+
/* Configure appsink */
//g_object_set (data.app_sink, "emit-signals", TRUE, "caps", caps, NULL);
The final result may still not be "correct", tho.
Ciao,
Antonio
--
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it
A: Because it messes up the order in which people normally read text.
See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
More information about the gstreamer-devel
mailing list