FFMPEG:如何将h264流包装到FLV容器中? [英] FFMPEG: how to wrap h264 stream into FLV container?

查看:798
本文介绍了FFMPEG:如何将h264流包装到FLV容器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的很简单:将H.264视频流包装到FLV容器中.但是, ffmpeg 只是解码输入流并将原始视频流打包到FLV中.详细信息如下:

What I want is straightforward: wrap H.264 video stream into a FLV container. However, ffmpeg just decode the input stream and pack raw video stream into FLV. The details are described below:

从硬件编码器摄像机捕获输入流,并将FLV发送到某些视频服务器.首先,我使用以下命令:

The input stream is captured from a hardware-encoder video camera, and the FLV will be sent to some video server. Firstly I used following command:

$ ffmpeg -framerate 15 -s 320x240 -i /dev/video1 -f flv "rtmp://some.website.com/receive/path"

但是,结果流是可疑的.看方没有收到任何H.264内容.然后我通过将输出写入本地文件进行了测试.

However, the resultant stream is suspicious. The watching side don't get any H.264 thing. Then I made a test by writing output to local files.

1:读取原始流,通过h264_omx编码,写入FLV文件:

1: Read raw stream, encode by h264_omx, write to FLV file:

$ ffmpeg -framerate 15 -s 320x240 -i /dev/video0 -codec h264_omx -f flv raw_input_h264_omx.flv

......
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 194017.870905, bitrate: 18432 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 320x240, 18432 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_omx))
......

2:读取H264流,写入FLV文件:

2: Read H264 stream, write to FLV file:

$ ffmpeg -framerate 15 -s 320x240 -i /dev/video1  -f flv h264_input.flv

......
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 194610.307096, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 320x240, 15 fps, 15 tbr, 1000k tbn, 2000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> flv1 (flv))
......

然后分别读取两个文件:

Then read the two files correspondingly:

$ ffmpeg -i raw_input_h264_omx.flv
......
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 320x240, 200 kb/s, 15 fps, 15 tbr, 1k tbn

$ ffmpeg -i h264_input.flv
......
    Stream #0:0: Video: flv1, yuv420p, 320x240, 200 kb/s, 15 fps, 15 tbr, 1k tbn

很明显,当我提供H.264流时, ffmpeg 首先对其进行解码,然后将原始视频打包到FLV中.如何避免这种情况发生,并直接打包H.264流?

It is clear when I give a H.264 stream, ffmpeg firstly decodes it, then pack the raw video into FLV. How to avoid that happen, and have the H.264 stream packed directly?

补充:我最终将推送多​​个视频流,所以不要要求我允许 ffmpeg 的无声解码,然后再次对流进行编码.

Supplement: I will eventually pushing multiple video streams, so don't ask me to allow ffmpeg's silent decoding, and encode the stream again.

推荐答案

除非另有说明,否则ffmpeg将对流进行转码.

Unless told otherwise, ffmpeg will transcode streams.

使用

ffmpeg -framerate 15 -s 320x240 -i /dev/video1 -c copy -f flv "rtmp://website/receive/path"

这篇关于FFMPEG:如何将h264流包装到FLV容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆