H264 ByteStream到图像文件 [英] H264 ByteStream to Image Files
问题描述
第一次来这里要保持柔和.
first time here so be gentle.
我已经在给定的H.264字节流上工作了几周:
I've been working for a few weeks on a given H.264 byte stream:
一般说明:
- 字节流不是来自文件,而是从外部来源实时馈给我的.
- 字节流使用Android的媒体编解码器进行编码.
- 将流写入扩展名为.H264的文件时,VLC可以正常播放.
我要实现的目标是什么?以下之一:
-
将H264流的帧转换为可保存的图片文件(png/jpeg等)
Converting the frames of the H264 stream to a saveable picture file (png/jpeg etc')
将H264原始字节转换为可被浏览器播放为源的MP4流.
Converting the H264 raw bytes into a MP4 stream that can be played as source by a browser.
我已经尝试过使用JavaCV(FFmpegFrameGrabber)没有成功,我的主要问题是我不知道如何解析字节流或每个数据包"的含义
I tried already using JavaCV (FFmpegFrameGrabber) without any success, my main problem is that i have no idea how to parse the byte stream or what each "packet" means
因此,我已经附加了一个文本文件,其中包含我从流中获取的一些数据包 H264数据包
推荐答案
将H264流的帧转换为可保存的图片文件(png/jpeg等)
Converting the frames of the H264 stream to a saveable picture file (png/jpeg etc')
假设您正在使用ffmpeg
cli工具.
Assuming you are using the ffmpeg
cli tool.
单张图片:
ffmpeg -framerate 25 -i input.h264 -frames:v 1 output.png
时间戳为01:23:45的单个图像:
Single image at 01:23:45 timestamp:
ffmpeg -framerate 24 -i input.h264 -ss 01:23:45 -frames:v 1 output.png
所有图像.将被命名为output_0001.png
,output_0002.png
,output_0003.png
等.在这种情况下,无需设置-framerate
或-frames:v
.
All images. Will be named output_0001.png
, output_0002.png
, output_0003.png
, etc. No need to set -framerate
or -frames:v
in this case.
ffmpeg -i input.h264 output_%04d.png
有关更多信息,请参见 FFmpeg图片混合器.
See FFmpeg image muxer for more info.
将H264原始字节转换为可被浏览器播放为源的MP4流.
Converting the H264 raw bytes into a MP4 stream that can be played as source by a browser.
ffmpeg -framerate 24000/1001 -i input.h264 -c copy -movflags +faststart output.mp4
这篇关于H264 ByteStream到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!