【问题标题】:Add timestamps to H264-ES video stream gstreamer为 H264-ES 视频流 gstreamer 添加时间戳
【发布时间】:2017-05-12 18:31:33
【问题描述】:

我有一个带有(可能是mplayer -identify 所说的)H264-ES 流的文件。

可以使用以下gstreamer管道播放:

gst-launch-1.0 filesrc location=vid.H264 ! h264parse ! avdec_h264 ! autovideosink

(我在示例中使用autovideosink,但管道要复杂得多——这是“最小的工作示例”) 它的播放速度非常快,可能与我的 CPU 允许的一样快。如果我使用任何需要时间戳的元素,它就会失败,因为流的帧速率为 0/1

我认为流根本不包含任何帧率信息。

见:

$ mplayer -identify vid.H264 2>&1 | grep -i fps
FPS not specified in the header or invalid, use the -fps option.
ID_VIDEO_FPS=0.000

我知道正确的帧率应该是多少(假设是 25fps),并且我希望能够将正确的时间戳放入视频帧设置正确的流帧率强>。

我尝试了什么:

我认为我可以为此使用videorate

gst-launch-1.0 filesrc location=vid.H264 ! h264parse ! avdec_h264 \
               ! videorate ! video/x-raw,framerate=25/1 ! autovideosink

但我错了 - videorate 试图将传入流转换为固定帧率,有时它看起来像我想要的那样工作,但是当下游任何元素有最轻微的延迟时,它会产生“冻结帧”视频 - 许多重复的帧 - 所以我想我可以使用 drop-only=true 选项,但它根本不起作用:

$ GST_DEBUG=3 gst-launch-1.0 filesrc location=vid.H264 ! h264parse ! avdec_h264 \
        ! videorate drop-only=true ! video/x-raw,framerate=25/1 ! autovideosink

Setting pipeline to PAUSED ...
0:00:00.030550249 31831      0x2094e10 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<filesrc0> pad not activated yet
Pipeline is PREROLLING ...
0:00:00.044233138 31831      0x207d450 WARN                   libav gstavcodecmap.c:2408:gst_ffmpeg_caps_to_pixfmt: ignoring insane framerate 1/0
0:00:00.045314795 31831      0x207d450 WARN                GST_PADS gstpad.c:3742:gst_pad_peer_query:<avdec_h264-0:src> could not send sticky events
0:00:00.070760684 31831      0x207d450 WARN               baseparse gstbaseparse.c:3262:gst_base_parse_loop:<h264parse0> error: streaming stopped, reason not-negotiated
ERROR: from element /GstPipeline:pipeline0/GstH264Parse:h264parse0: GStreamer encountered a general stream error.
Additional debug info:
gstbaseparse.c(3262): gst_base_parse_loop (): /GstPipeline:pipeline0/GstH264Parse:h264parse0:
streaming stopped, reason not-negotiated
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

问题在 avdec_h264videorate 之间 - 它不会接受 framerate=0/1 大写。

我认为我需要的是(想象中的管道):

$ GST_DEBUG=3 gst-launch-1.0 filesrc location=vid.H264 ! h264parse ! avdec_h264 \
        ! force_timestamps framerate=25/1 ! autovideosink

恐怕我得自己写force_timestamps元素,但因为我之前确实写过一些元素,这是我做过的最困难和最不愉快的事情之一,我更愿意使用现有的元素,如果可能的话。

所以我的问题是这样的:

是否有某种方法(最好使用现有元素)以某些固定帧速率强制视频帧(或 gstreamer 缓冲区)上的时间戳?

【问题讨论】:

    标签: video gstreamer-1.0


    【解决方案1】:

    从技术上讲,这不是答案,因为这样,原始的 h264 流 丢失了。

    这是一个丑陋的黑客,但我需要视频,这给了我一些我想要的东西 可以使用质量还可以:

    fn="$1"
    
    mkdir images
    
    gst-launch-1.0 filesrc location=$fn ! h264parse ! avdec_h264 \
        ! videoconvert ! jpegenc \
        ! multifilesink location=images/img%06d.jpg
    
    gst-launch-1.0 multifilesrc location=images/img%06d.jpg \
        caps="image/jpeg,framerate=25/1,pixel-aspect-ratio=1/1" \
        ! jpegdec ! videoconvert ! video/x-raw \
        ! x264enc rc-lookahead=5 pass=quant quantizer=20 \
        ! avimux ! filesink location=${fn}.avi
    
    rm -rf images
    

    【讨论】:

      猜你喜欢
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 2011-01-27
      相关资源
      最近更新 更多