pitivi / gst-editing-services

MIRROR of the GStreamer Editing Services repository for pull requests. The official git repository is at http://cgit.freedesktop.org/gstreamer/gst-editing-services/
Other
1 stars 1 forks source link

VP8 encoder negotiation problem when using different video source files #36

Closed lubosz closed 5 years ago

lubosz commented 11 years ago

I am trying to encode a timeline with 2 clips from different video files like this.

#!/usr/bin/python

from gi.repository import GES, Gst, Gtk, GstPbutils, GObject

import signal

videoFile1 = "file:///home/bmonkey/workspace/ges/data/trailer_480p.mov"
videoFile2 = "file:///home/bmonkey/workspace/ges/data/sintel_trailer-480p.mp4"

outputFile = 'file:///home/bmonkey/workspace/ges/data/GESEncode.webm'

def handle_sigint(sig, frame):
    Gtk.main_quit()

def busMessageCb(bus, message):
    if message.type == Gst.MessageType.EOS:
        print("eos")
        Gtk.main_quit()
    elif message.type == Gst.MessageType.ERROR:
        print (message.parse_error())
    else:
        pass

def duration_querier(pipeline):
    print(pipeline.query_position(Gst.Format.TIME)[1] / Gst.SECOND)
    return True

def simple():
  Gst.init(None)
  GES.init()

  timeline = GES.Timeline.new_audio_video()

  layer = GES.Layer()

  timeline.add_layer(layer)

  asset = GES.UriClipAsset.request_sync(videoFile1)
  asset2 = GES.UriClipAsset.request_sync(videoFile2)

  layer.add_asset(asset, 0 * Gst.SECOND, 0, 3 * Gst.SECOND, GES.TrackType.UNKNOWN)
  layer.add_asset(asset2, 3 * Gst.SECOND, 0, 3 * Gst.SECOND, GES.TrackType.UNKNOWN)

  timeline.commit()

  pipeline = GES.TimelinePipeline()
  pipeline.add_timeline(timeline)

  #encoding
  container_profile = GstPbutils.EncodingContainerProfile.new(
      "pitivi-profile",
      "Pitivi encoding profile",
      Gst.Caps.new_empty_simple("video/webm"),
      None)

  video_profile = GstPbutils.EncodingVideoProfile.new(
      Gst.Caps.new_empty_simple("video/x-vp8"),
      None,
      Gst.Caps.new_empty_simple("video/x-raw"),
      0)

  container_profile.add_profile(video_profile)

  audio_profile = GstPbutils.EncodingAudioProfile.new(
      Gst.Caps.new_empty_simple("audio/x-vorbis"),
      None,
      Gst.Caps.new_empty_simple("audio/x-raw"),
      0)

  container_profile.add_profile(audio_profile)

  pipeline.set_render_settings(outputFile, container_profile)
  pipeline.set_mode(GES.PipelineFlags.RENDER)
  pipeline.set_state(Gst.State.PLAYING)

  bus = pipeline.get_bus()
  bus.add_signal_watch()
  bus.connect("message", busMessageCb)
  GObject.timeout_add(1000, duration_querier, pipeline)

  signal.signal(signal.SIGINT, handle_sigint)
  Gtk.main()

simple()

It works when I use the same video file for both clips.

asset = GES.UriClipAsset.request_sync(videoFile2)
asset2 = GES.UriClipAsset.request_sync(videoFile2)

I get following output

1.185333333
1.803999999
2.230666667
2.635999999
3.929333333
4.590666667
5.102666667
5.507999999
eos

But when I use different video urls, I get an error and it only encodes the first clip.

asset = GES.UriClipAsset.request_sync(videoFile1)
asset2 = GES.UriClipAsset.request_sync(videoFile2)

I get following output

0.883999999
1.971999999
(GError('GStreamer error: negotiation problem.',), 'gstvideoencoder.c(1363): gst_video_encoder_chain (): /GESTimelinePipeline:gestimelinepipeline0/GstEncodeBin:internal-encodebin/GstVP8Enc:vp8enc0:\nencoder not initialized')
(GError('GStreamer encountered a general stream error.',), 'qtdemux.c(4317): gst_qtdemux_loop (): /GESTimelinePipeline:gestimelinepipeline0/GESTimeline:gestimeline0/GESVideoTrack:gesvideotrack0/GnlComposition:gnlcomposition1/GnlSource:gnlsource3/GstBin:video-src-bin/GstURIDecodeBin:uridecodebin2/GstDecodeBin:decodebin5/GstQTDemux:qtdemux4:\nstreaming stopped, reason not-negotiated')
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
etc
thiblahute commented 11 years ago

I bet this bug is fixed in master since:

Author: Sebastian Dröge <slomo@circular-chaos.org>
Date:   Sun Jun 30 18:17:15 2013 +0200

video(enc|dec)oder: Don't return not-negotiated if flushing

If the pad is flushing after a failed negotiation, return
GST_FLOW_FLUSHING instead from finish_frame().

https://bugzilla.gnome.org/show_bug.cgi?id=701763

is in. Do you have that patch?

lubosz commented 11 years ago

I have 85eac2c31ce7f7ed2aa0dbd4a9dc2ad42b734788 in gst-plugins-base-git, but same problem

0.969333333
2.057333333
(GError('GStreamer error: negotiation problem.',), 'gstvideoencoder.c(1363): gst_video_encoder_chain (): /GESTimelinePipeline:gestimelinepipeline0/GstEncodeBin:internal-encodebin/GstVP8Enc:vp8enc0:\nencoder not initialized')
(GError('GStreamer encountered a general stream error.',), 'qtdemux.c(4317): gst_qtdemux_loop (): /GESTimelinePipeline:gestimelinepipeline0/GESTimeline:gestimeline0/GESVideoTrack:gesvideotrack0/GnlComposition:gnlcomposition1/GnlSource:gnlsource3/GstBin:video-src-bin/GstURIDecodeBin:uridecodebin2/GstDecodeBin:decodebin5/GstQTDemux:qtdemux4:\nstreaming stopped, reason not-negotiated')
2.739999999
2.739999999
2.739999999
2.739999999
2.739999999
lubosz commented 11 years ago

this seems to be a vp8 issue. some encoding options work better, some worse.

in this test i was encoding a video with image, video and audio assets. 1 video layer and 1 audio layer.

# Firefox
# VERY slow encoding after first 20 secs, buggy video output http://i.imgur.com/mbkZ4kb.jpg
format = ["application/ogg", "video/x-theora", "audio/x-vorbis", "ogv"]

# Chrome
# first element / clips gets encoded, after that a negotiation error occurs
format = ["video/webm", "video/x-vp8", "audio/x-vorbis", "webm"]

# Safari
# does not start, without error, 0s in callback
format = ["video/quicktime", "video/x-h264", "audio/x-aac", "mp4"]

# MPEG
# does not start, without error, 0s in callback
format = ["video/mpeg", "video/mpeg", "audio/mpeg", "mpg"]

# MKV / h264 / vorbis
# works very fast, in real time, 1 min in 1min. the result is good but has bugs for image assets. 
format = ["video/x-matroska", "video/x-h264", "audio/x-vorbis", "mkv"]
thiblahute commented 5 years ago

Fixed now it seems