Can't play videos recorded with `membrane_camera_capture_plugin`

I’m trying to use Membrane.CameraCapture to record a video from my computer camera.

When I clone the package repo and run the tests mix test --include manual, I can play the video the test records. Everything seems to work as expected.

But when I try to use the child specification defined in the test in a standalone example, I can’t play the output video.

To reproduce the problem, save the following code into a file example.exs.

example.exs

Mix.install([
  {:membrane_camera_capture_plugin, "~> 0.4.0"},
  {:membrane_h264_ffmpeg_plugin, "~> 0.21"},
  {:membrane_file_plugin, "~> 0.10"},
  {:membrane_ffmpeg_swscale_plugin, "~> 0.10"}
])

defmodule VideoRecorder do
  use Membrane.Pipeline

  @impl true
  def handle_init(_ctx, _options) do
    structure =
      child(:source, Membrane.CameraCapture)
      |> child(:converter, %Membrane.FFmpeg.SWScale.PixelFormatConverter{format: :I420})
      |> child(:encoder, Membrane.H264.FFmpeg.Encoder)
      |> child(:sink, %Membrane.File.Sink{location: "output.h264"})

    {[spec: structure], %{}}
  end
end

{:ok, _supervisor_pid, pipeline_pid} = Membrane.Pipeline.start_link(__MODULE__, [], name: VideoRecorder)
Process.sleep(2000)
VideoRecorder.terminate(pipeline_pid)

Then run the above file with elixir example.exs, and open the outputted video with ffplay output.h264.

Instead of seeing a video, I get the following warning…

[h264 @ 0x15b00a190] Format h264 detected only with low score of 1, misdetection possible!
[h264 @ 0x15b00a190] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options

Any ideas what I’m missing?

I believe that you need to return the playback: :playing action from your handle_init after the spec action, like this:

{[spec: structure, playback: :playing], %{}}
1 Like

That was it! Thank you for your help.