如何使用 Gstreamer 从 PNG 图像创建 mp4 视频文件

How to create a mp4 video file from PNG images using Gstreamer

我正在玩 gstreamer 命令行界面,但在从 PNG 图像创建 mp4 视频文件时卡住了。各位大侠能帮忙解决一下吗

我使用以下命令从摄像机创建了 PNG 图像:

gst-launch-1.0.exe -v ksvideosrc ! queue ! decodebin ! videoconvert ! pngenc ! multifilesink location="frame%05d.png"

我能够使用以下命令播放 pPNG 图像:

gst-launch-1.0 -v multifilesrc location="frame%05d.png" index=0 ! pngdec ! glimagesink

但是在从 PNG 图像创建 mp4 视频时,我从管道收到了 EOS:

Setting pipeline to PAUSED ... Pipeline is PREROLLING ... /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstTypeFindElement:typefind.GstPad:src: caps = image/png /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstPngParse:pngparse0.GstPad:sink: caps = image/png /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstPngDec:pngdec0.GstPad:sink: caps = image/png, width=(int)640, height=(int)480 /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstPngParse:pngparse0.GstPad:src: caps = image/png, width=(int)640, height=(int)480 /GstPipeline:pipeline0/GstDecodeBin:decodebin0/GstPngDec:pngdec0.GstPad:src: caps = video/x-raw, format=(string)RGB, width=(int)640, height=(int)480, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)sRGB, framerate=(fraction)0/1 /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = video/x-raw, width=(int)640, height=(int)480, framerate=(fraction)0/1, format=(string)Y444, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1 /GstPipeline:pipeline0/GstVideoRate:videorate0.GstPad:src: caps = video/x-raw, width=(int)640, height=(int)480, framerate=(fraction)0/1, format=(string)Y444, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1 Redistribute latency... /GstPipeline:pipeline0/GstX264Enc:x264enc0.GstPad:sink: caps = video/x-raw, width=(int)640, height=(int)480, framerate=(fraction)0/1, format=(string)Y444, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1 /GstPipeline:pipeline0/GstVideoRate:videorate0.GstPad:sink: caps = video/x-raw, width=(int)640, height=(int)480, framerate=(fraction)0/1, format=(string)Y444, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1 /GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:sink: caps = video/x-raw, format=(string)RGB, width=(int)640, height=(int)480, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)sRGB, framerate=(fraction)0/1 /GstPipeline:pipeline0/GstDecodeBin:decodebin0.GstDecodePad:src_0.GstProxyPad:proxypad1: caps = video/x-raw, format=(string)RGB, width=(int)640, height=(int)480, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)sRGB, framerate=(fraction)0/1 /GstPipeline:pipeline0/GstX264Enc:x264enc0.GstPad:src: caps = video/x-h264, codec_data=(buffer)01f4001effe1001c67f4001e919b281407b602d41804150000030001773594000f162d9601000668ebec448440, stream-format=(string)avc, alignment=(string)au, level=(string)3, profile=(string)high-4:4:4, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)0/1, interlace-mode=(string)progressive, colorimetry=(string)bt601, chroma-site=(string)jpeg, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono /GstPipeline:pipeline0/GstMP4Mux:mp4mux0.GstQTMuxPad:video_0: caps = video/x-h264, codec_data=(buffer)01f4001effe1001c67f4001e919b281407b602d41804150000030001773594000f162d9601000668ebec448440, stream-format=(string)avc, alignment=(string)au, level=(string)3, profile=(string)high-4:4:4, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)0/1, interlace-mode=(string)progressive, colorimetry=(string)bt601, chroma-site=(string)jpeg, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono /GstPipeline:pipeline0/GstMP4Mux:mp4mux0.GstPad:src: caps = video/quicktime, variant=(string)iso /GstPipeline:pipeline0/GstFileSink:filesink0.GstPad:sink: caps = video/quicktime, variant=(string)iso Pipeline is PREROLLED ... Setting pipeline to PLAYING ... New clock: GstSystemClock /GstPipeline:pipeline0/GstMP4Mux:mp4mux0.GstPad:src: caps = video/quicktime, variant=(string)iso, streamheader=(buffer)< 000003796d6f6f760000006c6d76686400000000d8ec7eeed8ec7eef00002710000000000001000001000000000000000000000000010000000000000000000000000000000100000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002000002c87472616b0000005c746b686400000007d8ec7eeed8ec7eef000000010000000000000000000000000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000400000000280000001e0000000000024656474730000001c656c73740000000000000001000000000000000000010000000001e76d646961000000206d64686400000000d8ec7eeed8ec7eef000027100000000055c400000000002d68646c72000000000000000076696465000000000000000000000000566964656f48616e646c657200000001926d696e6600000014766d68640000000100000000000000000000002464696e660000001c6472656600000000000000010000000c75726c2000000001000001527374626c000000d2737473640000000000000001000000c261766331000000000000000100000000000000000000000000000000028001e0004800000048000000000000000100000000000000000000000000000000000000000000000000000000000000000018ffff000000356176634301f4001effe1001c67f4001e919b281407b602d41804150000030001773594000f162d9601000668ebec448440000000146274727400000000002000000000000000000013636f6c726e636c78000600010006000000001070617370000000010000000100000018737474730000000000000001000000020000000000000014737473730000000000000001000000010000001c7374736300000000000000010000000100000002000000010000001c7374737a00000000000000000000000200002fc000000037000000147374636f0000000000000001000000300000005975647461000000516d657461000000000000002168646c72000000006d686c726d6469720000000000000000000000000000000024696c73740000001ca9746f6f00000014646174610000000100000000783236340000003d75647461000000356d657461000000000000002168646c72000000006d686c726d6469720000000000000000000000000000000008696c7374 > /GstPipeline:pipeline0/GstFileSink:filesink0.GstPad:sink: caps = video/quicktime, variant=(string)iso, streamheader=(buffer)< 000003796d6f6f760000006c6d76686400000000d8ec7eeed8ec7eef00002710000000000001000001000000000000000000000000010000000000000000000000000000000100000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002000002c87472616b0000005c746b686400000007d8ec7eeed8ec7eef000000010000000000000000000000000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000400000000280000001e0000000000024656474730000001c656c73740000000000000001000000000000000000010000000001e76d646961000000206d64686400000000d8ec7eeed8ec7eef000027100000000055c400000000002d68646c72000000000000000076696465000000000000000000000000566964656f48616e646c657200000001926d696e6600000014766d68640000000100000000000000000000002464696e660000001c6472656600000000000000010000000c75726c2000000001000001527374626c000000d2737473640000000000000001000000c261766331000000000000000100000000000000000000000000000000028001e0004800000048000000000000000100000000000000000000000000000000000000000000000000000000000000000018ffff000000356176634301f4001effe1001c67f4001e919b281407b602d41804150000030001773594000f162d9601000668ebec448440000000146274727400000000002000000000000000000013636f6c726e636c78000600010006000000001070617370000000010000000100000018737474730000000000000001000000020000000000000014737473730000000000000001000000010000001c7374736300000000000000010000000100000002000000010000001c7374737a00000000000000000000000200002fc000000037000000147374636f0000000000000001000000300000005975647461000000516d657461000000000000002168646c72000000006d686c726d6469720000000000000000000000000000000024696c73740000001ca9746f6f00000014646174610000000100000000783236340000003d75647461000000356d657461000000000000002168646c72000000006d686c726d6469720000000000000000000000000000000008696c7374 > Got EOS from element "pipeline0". Execution ended after 0:00:00.814042926 Setting pipeline to PAUSED ... Setting pipeline to READY ... Setting pipeline to NULL ... Freeing pipeline …

要从 png 中创建 mp4,您可以使用以下管道:

gst-launch-1.0 -e multifilesrc location="frame%05d.png"
caps="image/png,framerate=30/1" ! pngdec ! videoconvert ! queue ! x264enc ! queue ! mp4mux ! filesink location=image.mp4

注意:

  1. 如果您需要 60fps 的视频,以上内容将创建一个 30fps 的 mp4 将 multifilesrc 中的 caps 更改为 caps="image/png,framerate=60/1" 对于 60fps 视频。
  2. 如果你有任何特定的硬件,你也可以改变编码器 编码器。