gpt4 book ai didi

java - H264 字节流到图像文件

转载 作者:行者123 更新时间:2023-12-01 18:32:18 25 4
gpt4 key购买 nike

第一次来这里,所以要温柔。

我已经在给定的 H.264 字节流上工作了几个星期:

一般说明:

  1. 字节流不是来自文件,而是从外部源实时提供给我的。
  2. 字节流使用 Android 的媒体编解码器进行编码。
  3. 将流写入扩展名为 .H264 的文件时,VLC 能够正常播放。

我想要实现什么目标?以下之一:

  1. 将 H264 流的帧转换为可保存的图片文件(png/jpeg 等)

  2. 将 H264 原始字节转换为可由浏览器作为源播放的 MP4 流。

我已经尝试使用JavaCV(FFmpegFrameGrabber)但没有成功,我的主要问题是我不知道如何解析字节流或每个“数据包”的含义

所以,我附加了一个文本文件,其中包含我从流中获取的一些数据包 H264 Packets

最佳答案

Converting the frames of the H264 stream to a saveable picture file (png/jpeg etc')

假设您使用 ffmpeg cli 工具。

单张图像:

ffmpeg -framerate 25 -i input.h264 -frames:v 1 output.png

时间戳为 01:23:45 的单张图像:

ffmpeg -framerate 24 -i input.h264 -ss 01:23:45 -frames:v 1 output.png

所有图像。会被命名为output_0001.pngoutput_0002.pngoutput_0003.png等。无需设置-framerate 或在本例中为 -frames:v

ffmpeg -i input.h264 output_%04d.png

参见FFmpeg image muxer了解更多信息。

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

关于java - H264 字节流到图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60139561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com