此代码有什么问题?我正在尝试向子进程发送SIGINT
,以允许gst-launch-1.0
在录制完成后正常退出:
@pid = fork {
exec("gst-launch-1.0 -e v4l2src device=/dev/video0 ! videoconvert ! vaapih264enc rate-control=vbr bitrate=10000 quality-level=4 keyframe-period=30 num-slices=1 refs=1 max-bframes=2 ! queue ! mux. alsasrc ! audio/x-raw,width=16,depth=16,rate=44100,channel=1 ! audioconvert ! audioresample ! voaacenc ! aacparse ! queue ! mp4mux name=mux ! filesink location='/tmp/test-010.mp4' sync=false")
}
sleep 5
puts 'Killing child process and waiting...'
Process.kill 'INT', @pid
Process.wait
如您所见,我发出了Process.kill 'INT', @pid
,据我所知,它应该与运行ctrl+c
命令(或任何CLI命令)时按gst-launch-1.0
相同。直接。
但是Ruby脚本的输出是:
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'vaapiencodeh264-0': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)"\(GstVaapiDisplayGLX\)\ vaapidisplayglx0";
Setting pipeline to PLAYING ...
New clock: GstAudioSrcClock
Redistribute latency...
Killing child process and waiting...
该脚本刚刚挂起。基本上,看来Process.kill
调用没有执行任何操作,或者至少信号没有到达子进程。我的代码有什么问题?
作为参考,当我确实直接从CLI运行gst-launch-1.0
命令并过一会儿按ctrl+c
时,会发生以下情况:
gst-launch-1.0 -e v4l2src device=/dev/video0 ! videoconvert ! vaapih264enc rate-control=vbr bitrate=10000 quality-level=4 keyframe-period=30 num-slices=1 refs=1 max-bframes=2 ! mp4mux name=mux ! filesink location=test-006.mp4 sync=false
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'vaapiencodeh264-0': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)"\(GstVaapiDisplayGLX\)\ vaapidisplayglx0";
Setting pipeline to PLAYING ...
New clock: GstSystemClock
捕获正在进行中。
准备结束捕获时,我按ctrl+c
,输出如下:
^Chandling interrupt.
Interrupt: Stopping pipeline ...
EOS on shutdown enabled -- Forcing EOS on the pipeline
Waiting for EOS...
Got EOS from element "pipeline0".
EOS received - stopping pipeline...
Execution ended after 0:00:08.524849001
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...