[
http://opencast.jira.com/browse/MH-6384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=24473#comment-24473
]
Robert Robere commented on MH-6384:
-----------------------------------
Better gstreamer implementation. I made this so that I can swap file sources on
and off in case
a Media Package has more than one track.
import org.gstreamer.*;
import org.gstreamer.elements.DecodeBin;
public class VideoSplitter {
private Element fileSrc;
private Element videoStreamDemuxer;
private final Element rightVideoMuxer;
private final Element leftVideoMuxer;
private Element leftVideoFileSink;
private Element rightVideoFileSink;
private final DecodeBin videoDecoder;
private final Element videoTee;
private final Element audioTee;
private final Element videoCropRight;
private final Element videoCropLeft;
private final Element videoEncoder;
private final Element videoEncoder2;
private final Element videoQueue1;
private final Element videoQueue2;
private final Element audioQueue;
private final Element audioQueue2;
private Bin bin = new Bin();
public VideoSplitter() {
fileSrc = ElementFactory.make("filesrc", "s1");
fileSrc.set("location", "tmp.mp4");
videoStreamDemuxer = ElementFactory.make("qtdemux", "demux");
rightVideoMuxer = ElementFactory.make("mp4mux", "mux0");
leftVideoMuxer = ElementFactory.make("mp4mux", "mux1");
leftVideoFileSink = ElementFactory.make("filesink", "s2");
leftVideoFileSink.set("location", "out.mp4");
rightVideoFileSink = ElementFactory.make("filesink", "sink2");
rightVideoFileSink.set("location", "out1.mp4");
videoDecoder = new DecodeBin("decoder");
videoTee = ElementFactory.make("tee", "videoTee");
audioTee = ElementFactory.make("tee", "audioTee");
videoCropRight = ElementFactory.make("videocrop", "cropRight");
videoCropLeft = ElementFactory.make("videocrop", "cropLeft");
videoCropLeft.set("left", 200);
videoCropRight.set("right", 480);
videoEncoder = ElementFactory.make("x264enc", "encode1");
videoEncoder2 = ElementFactory.make("x264enc", "encode2");
videoQueue1 = ElementFactory.make("queue", "videoQueue");
videoQueue1.set("max-size-buffers", 0);
videoQueue1.set("max-size-time", 0);
videoQueue1.set("max-size-bytes", 0);
videoQueue2 = ElementFactory.make("queue", "videoQueue2");
videoQueue2.set("max-size-buffers", 0);
videoQueue2.set("max-size-time", 0);
videoQueue2.set("max-size-bytes", 0);
audioQueue = ElementFactory.make("queue", "audioQueue");
audioQueue.set("max-size-buffers", 0);
audioQueue.set("max-size-time", 0);
audioQueue.set("max-size-bytes", 0);
audioQueue2 = ElementFactory.make("queue", "audioQueue1");
audioQueue2.set("max-size-buffers", 0);
audioQueue2.set("max-size-time", 0);
audioQueue2.set("max-size-bytes", 0);
}
private void addElementsToBin() {
bin.addMany(fileSrc, videoStreamDemuxer, rightVideoMuxer, leftVideoMuxer,
rightVideoFileSink, videoTee, audioTee,
videoDecoder, videoCropRight, videoCropLeft, videoEncoder,
videoEncoder2, videoQueue2, audioQueue, videoQueue1,
leftVideoFileSink,
audioQueue2);
}
private boolean createStaticLinks() {
boolean connected = true;
// filesrc ! demux
if (!fileSrc.link(videoStreamDemuxer)) {
connected = false;
}
// mp4mux ! filesink
if (!rightVideoMuxer.link(leftVideoFileSink)) {
connected = false;
}
if (!leftVideoMuxer.link(rightVideoFileSink)) {
connected = false;
}
return connected;
}
private void createDemuxLink() {
videoStreamDemuxer.connect(new Element.PAD_ADDED() {
public void padAdded(Element element, Pad pad) {
if (pad.getName().equals("video_00")) {
// demux.video_00 ! decodebin
pad.link(videoDecoder.getStaticPad("sink"));
} else if (pad.getName().equals("audio_00")) {
// demux.audio_00 ! queue
pad.link(audioTee.getStaticPad("sink"));
audioTee.getRequestPad("src0").link(audioQueue.getStaticPad("sink"));
audioTee.getRequestPad("src1").link(audioQueue2.getStaticPad("sink"));
// queue ! mp4mux
audioQueue.getStaticPad("src").link(rightVideoMuxer.getRequestPad("audio_0"));
audioQueue2.getStaticPad("src").link(leftVideoMuxer.getRequestPad("audio_0"));
}
}
});
}
private void createDecoderLink() {
videoDecoder.connect(new DecodeBin.NEW_DECODED_PAD() {
public void newDecodedPad(Element element, Pad pad, boolean last) {
// decodebin ! videocrop right=480
pad.link(videoTee.getStaticPad("sink"));
videoTee.getRequestPad("src0").link(videoCropRight.getStaticPad("sink"));
videoTee.getRequestPad("src1").link(videoCropLeft.getStaticPad("sink"));
// videocrop right=480 ! x264enc
videoCropRight.link(videoEncoder);
videoCropLeft.link(videoEncoder2);
// x264enc ! queue
videoEncoder.link(videoQueue1);
videoEncoder2.link(videoQueue2);
// queue ! mp4mux
videoQueue1.getStaticPad("src").link(rightVideoMuxer.getRequestPad("video_0"));
videoQueue2.getStaticPad("src").link(leftVideoMuxer.getRequestPad("video_0"));
}
});
}
public Bin getBin() {
return bin;
}
public static void main(String[] args){
Gst.init();
VideoSplitter splitter = new VideoSplitter();
splitter.addElementsToBin();
splitter.createStaticLinks();
splitter.createDemuxLink();
splitter.createDecoderLink();
Pipeline pipeline = new Pipeline();
Bus pipelineBus = pipeline.getBus();
pipelineBus.connect(new Bus.MESSAGE() {
public void busMessage(Bus bus, Message message) {
}
});
pipelineBus.connect(new Bus.ERROR() {
public void errorMessage(GstObject source, int code, String
message){
System.out.println(source);
System.out.println(message);
}
});
pipeline.add(splitter.getBin());
pipeline.pause();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("HEY");
e.printStackTrace();
}
pipeline.play();
Gst.main();
pipeline.setState(State.NULL);
Gst.deinit();
}
}
> Write a gstreamer cli to split a single video into multiple videos and encode
> in h264
> -------------------------------------------------------------------------------------
>
> Key: MH-6384
> URL: http://opencast.jira.com/browse/MH-6384
> Project: Matterhorn Project
> Issue Type: Sub-Task
> Components: Architecture & Services
> Affects Versions: 1.2
> Reporter: Christopher Brooks
> Assignee: Christopher Brooks
> Priority: Critical
> Fix For: 1.2
>
>
> post result to this ticket, just using testsrc is fine
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
Matterhorn mailing list
[email protected]
http://lists.opencastproject.org/mailman/listinfo/matterhorn
To unsubscribe please email
[email protected]
_______________________________________________