Reputation: 10122
We've just started trying out gStreamer-Sharp, to see if we can create pipelines, with a view to writing a media player component for our .NET software. We're running on Windows/.NET, not Linux/Mono.
Some pipelines can be created, linked and run no problem, but others fail. There's a lack of documentation and support out there for this, so I'm hoping on the off-chance someone with some knowledge in this area will drive by my question and give me some hints.
Anyway, without further ado, I have a repro-case below that fails to link from an avidemux element into an mpeg4 element.
using System.Windows.Forms;
using Gst;
using Gst.Interfaces;
namespace gStreamerTest
{
public partial class MainForm : Form
{
// Pipeline.
private Gst.Pipeline MyPipeline;
// Elements.
private Gst.Element MyFileSource, MyDemux, MyMpeg4, MyDrawSink;
// Overlay adapter.
private XOverlayAdapter MySinkAdapter;
public MainForm()
{
InitializeComponent();
// Initialise gStreamer.
Gst.Application.Init();
// Create new pipeline.
MyPipeline = new Gst.Pipeline();
Pipeline pipeline = new Pipeline("pipeline");
// Construct pipeline filesrc -> avidemux -> mpeg4 -> directdrawsink
MyFileSource = ElementFactory.Make("filesrc", "filesrc");
MyFileSource["location"] = "c:\\test.mp4";
MyDemux = ElementFactory.Make("avidemux", "avidemux");
MyMpeg4 = ElementFactory.Make("ffdec_mpeg4", "ffdec_mpeg4");
MyDrawSink = ElementFactory.Make("directdrawsink", "directdrawsink");
// Output to our window.
MySinkAdapter = new XOverlayAdapter(MyDrawSink.Handle);
MySinkAdapter.XwindowId = (ulong)this.Handle;
// Add and link pipeline.
MyPipeline.Add(MyFileSource, MyDemux, MyMpeg4, MyDrawSink);
if (!MyFileSource.Link(MyDemux))
{
}
if (!MyDemux.Link(MyMpeg4))
{
// FAILS HERE
}
if (!MyMpeg4.Link(MyDrawSink))
{
}
// Play video.
MyPipeline.SetState(Gst.State.Playing);
}
}
}
Interestingly, the above pipeline works OK when we launch it from the command line. We have a vague feeling we might be doing something incorrectly here when setting up the pipeline. It seems to fail at linking the demux to the mpeg4 elements.
As I suggested, some pipelines do work. We can also play the test.mp4 in media player and load it no problem elsewhere (e.g. with gStreamer from the command line).
We're also not sure how to switch on logging for gStreamer-Sharp, or if it's even possible. If anyone can help me out here I would really appreciate it.
Thanks.
Upvotes: 2
Views: 1943
Reputation: 10122
After some hints from the project maintainer, I see there are a couple of mistakes in my code. The first is that the demux cannot be linked to the mpeg4 element yet, as the demux only gets its pads when the pipeline starts. This means that I simply need to handle the PadAdded event on the demux element and do the link to the mpeg4 component there.
The second problem is that I need to convert the colour space from YUV to RGB in order for the directdrawsink to accept the input. This will involve me adding an ffmpegcolorspace element in-between.
Finally, I couldn't get debug output at all. The solution to this is to redirect stderr to the output window in Visual Studio 2010. To do this I went to project properties -> debug and put the following command line argument in: "2 > ErrorLog.txt" (without the quotes). Now I can see gStreamer debug output, which is controlled with the GST_DEBUG environment variable.
Brilliant!
Upvotes: 2