3d0c / gmf

Go Media Framework
MIT License
885 stars 170 forks source link

Specifying video4linux2 input_format option #119

Closed ccaum closed 4 years ago

ccaum commented 4 years ago

I'm trying to create an input context with the video4linux2 format. That format in libav has a "input_format" option where you can specify "mjpeg", "h264", and many other raw formats. I'm having trouble figuring out how to pass in that option with gmf. I tried using the SetOptions() function but it doesn't seem to apply.

Here's a successful ffmpeg command: ffmpeg -f video4linux2 -input_format h264 -i /dev/video0 -vcodec copy -an output.mp4

Which shows it using h264 as the input codec:

Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 517135.169376, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 1000k tbn, 2000k tbc

Here's what I've tried using gmf:

func main() {
  var inputOptions []*Option

  inputOptions = append([]*Option{ {Key: "input_format", Val: "h264"} })
  inputCtx, _ := NewInputCtxWithFormatName("/dev/video0", "video4linux2")
  defer inputCtx.Free()

  inputCtx.SetOptions(inputOptions)
   ...

However, when I run it, the libav output shows it's still using rawvideo (the default)

Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 513780.234774, bitrate: 331776 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 331776 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc

Is there any way to A) create an input codec to attach to the input format context? B) pass the "input_format" libav option to the input format context?

ccaum commented 4 years ago

After thinking through this a bit more, I'm making it more complex than it needs to be. I'll use the rawvideo to process the frames and use the h264_omx encoder to hardware accelerate the h264 encoding when streaming the video to disk.