Permalink
Browse files

Added debug, metadata and pipeline parameters to %gstreamer.

  • Loading branch information...
1 parent 118d685 commit 9b89ee24f0145af091c3bc6c4d06a419ca4b2d90 @toots toots committed Nov 30, 2012
Showing with 85 additions and 51 deletions.
  1. +14 −6 src/encoder/encoder.ml
  2. +51 −39 src/encoder/gstreamer_encoder.ml
  3. +20 −6 src/lang/lang_encoders.ml
@@ -425,10 +425,14 @@ end
module GStreamer =
struct
type t = {
- channels : int;
- audio : string option;
- video : string option;
- muxer : string option
+ channels : int;
+ audio : string option;
+ has_video : bool;
+ video : string option;
+ muxer : string option;
+ metadata : string;
+ pipeline : string option;
+ debug : bool
}
let audio_channels m =
@@ -438,7 +442,7 @@ struct
m.channels
let video_channels m =
- if m.video = None then
+ if m.video = None || not m.has_video then
0
else
1
@@ -450,14 +454,18 @@ struct
(fun value -> (Printf.sprintf "%s=%S" name value)::l)
value)
in
- Printf.sprintf "%%gstreamer(%s)"
+ Printf.sprintf "%%gstreamer(%s,metadata=%S,has_video=%b,%sdebug=%b)"
(String.concat ","
(pipeline
(pipeline
(pipeline [Printf.sprintf "channels=%d" m.channels]
"audio" m.audio)
"video" m.video)
"muxer" m.muxer))
+ m.metadata
+ m.has_video
+ (Utils.some_or "" (Utils.maybe (Printf.sprintf "pipeline=%S,") m.pipeline))
+ m.debug
end
module Theora =
@@ -27,6 +27,8 @@ open Encoder.GStreamer
module GU = Gstreamer_utils
module Img = Image.RGBA32
+let log = Dtools.Log.make ["encoder"; "gstreamer"]
+
type gst =
{
bin : Gstreamer.Pipeline.t;
@@ -55,50 +57,59 @@ let encoder id ext =
in
let gst =
- let muxer =
- if ext.audio <> None && ext.video <> None then
- "muxer."
- else
- ""
- in
- let audio_pipeline =
- Utils.maybe (fun pipeline ->
- Printf.sprintf "%s ! queue ! %s ! %s ! %s"
- (GU.Pipeline.audio_src ~channels ~block:true "audio_src")
- (GU.Pipeline.convert_audio ())
- pipeline
- muxer) ext.audio
- in
- let video_pipeline =
- Utils.maybe (fun pipeline ->
- Printf.sprintf "%s ! queue ! %s ! %s ! %s"
- (GU.Pipeline.video_src ~block:true "video_src")
- (GU.Pipeline.convert_video ())
- pipeline
- muxer) ext.video
- in
- let muxer_pipeline = match ext.muxer with
- | Some muxer -> Printf.sprintf "%s name=muxer !" muxer
- | None -> ""
- in
let pipeline =
- Printf.sprintf "%s %s %s appsink name=sink sync=false emit-signals=true"
- (Utils.some_or "" audio_pipeline)
- (Utils.some_or "" video_pipeline)
- muxer_pipeline
+ match ext.pipeline with
+ | Some p -> p
+ | None ->
+ let muxer =
+ if ext.audio <> None && ext.video <> None then
+ "muxer."
+ else
+ ""
+ in
+ let audio_pipeline =
+ Utils.maybe (fun pipeline ->
+ Printf.sprintf "%s ! queue ! %s ! %s ! %s"
+ (GU.Pipeline.audio_src ~channels ~block:true "audio_src")
+ (GU.Pipeline.convert_audio ())
+ pipeline
+ muxer) ext.audio
+ in
+ let video_pipeline =
+ Utils.maybe (fun pipeline ->
+ Printf.sprintf "%s ! queue ! %s ! %s ! %s"
+ (GU.Pipeline.video_src ~block:true "video_src")
+ (GU.Pipeline.convert_video ())
+ pipeline
+ muxer) ext.video
+ in
+ let muxer_pipeline = match ext.muxer with
+ | Some muxer -> Printf.sprintf "%s name=muxer !" muxer
+ | None -> ""
+ in
+ Printf.sprintf "%s %s %s appsink name=sink sync=false emit-signals=true"
+ (Utils.some_or "" audio_pipeline)
+ (Utils.some_or "" video_pipeline)
+ muxer_pipeline
in
+ if ext.debug then
+ log#f 3 "Gstreamer encoder pipeline: %s" pipeline;
let bin = Gstreamer.Pipeline.parse_launch pipeline in
let audio_src =
- Utils.maybe (fun _ ->
- Gstreamer.App_src.of_element
- (Gstreamer.Bin.get_by_name bin "audio_src"))
- audio_pipeline
+ try
+ Some
+ (Gstreamer.App_src.of_element
+ (Gstreamer.Bin.get_by_name bin "audio_src"))
+ with
+ | Not_found -> None
in
let video_src =
- Utils.maybe (fun _ ->
- Gstreamer.App_src.of_element
- (Gstreamer.Bin.get_by_name bin "video_src"))
- video_pipeline
+ try
+ Some
+ (Gstreamer.App_src.of_element
+ (Gstreamer.Bin.get_by_name bin "video_src"))
+ with
+ | Not_found -> None
in
let sink = Gstreamer.App_sink.of_element (Gstreamer.Bin.get_by_name bin "sink") in
Gstreamer.App_sink.on_new_sample sink on_sample;
@@ -134,7 +145,8 @@ let encoder id ext =
let m = Encoder.Meta.to_metadata m in
try
let meta =
- Gstreamer.Tag_setter.of_element (Gstreamer.Bin.get_by_name gst.bin "metadata")
+ Gstreamer.Tag_setter.of_element
+ (Gstreamer.Bin.get_by_name gst.bin ext.metadata)
in
Hashtbl.iter
(Gstreamer.Tag_setter.add_tag meta Gstreamer.Tag_setter.Replace)
@@ -799,10 +799,14 @@ let mk_speex params =
let mk_gstreamer params =
let defaults =
{ Encoder.GStreamer.
- channels = 2;
- audio = Some "lamemp3enc";
- video = Some "x264enc";
- muxer = Some "mpegtsmux"
+ channels = 2;
+ audio = Some "lamemp3enc";
+ has_video = true;
+ video = Some "x264enc";
+ muxer = Some "mpegtsmux";
+ metadata = "metadata";
+ debug = false;
+ pipeline = None
}
in
let gstreamer =
@@ -817,21 +821,31 @@ let mk_gstreamer params =
{ f with Encoder.GStreamer.channels = i }
| ("audio",{ term = String s }) ->
{ f with Encoder.GStreamer.audio = perhaps s }
+ | ("has_video",{ term = Bool b }) ->
+ { f with Encoder.GStreamer.has_video = b }
| ("video",{ term = String s }) ->
{ f with Encoder.GStreamer.video = perhaps s }
| ("muxer",{ term = String s }) ->
{ f with Encoder.GStreamer.muxer = perhaps s }
+ | ("metadata",{ term = String s }) ->
+ { f with Encoder.GStreamer.metadata = s }
+ | ("debug",{ term = Bool b }) ->
+ { f with Encoder.GStreamer.debug = b }
+ | ("pipeline",{ term = String s }) ->
+ { f with Encoder.GStreamer.pipeline = perhaps s }
| (_,t) -> raise (generic_error t))
defaults params
in
let ret = mk (Encoder (Encoder.GStreamer gstreamer)) in
- if gstreamer.Encoder.GStreamer.audio <> None &&
+ if gstreamer.Encoder.GStreamer.pipeline = None &&
+ gstreamer.Encoder.GStreamer.audio <> None &&
gstreamer.Encoder.GStreamer.channels = 0
then
raise
(Error (ret, "Must have at least one audio channel when \
passing an audio pipeline!"));
- if gstreamer.Encoder.GStreamer.video <> None &&
+ if gstreamer.Encoder.GStreamer.pipeline = None &&
+ gstreamer.Encoder.GStreamer.video <> None &&
gstreamer.Encoder.GStreamer.audio <> None &&
gstreamer.Encoder.GStreamer.muxer = None
then

0 comments on commit 9b89ee2

Please sign in to comment.