我正在使用CUDA Toolkit 4.0在我的Geforce 330M上尝试使用OpenCL-OpenGL互操作.
我想捕获一个帧,将该数据用作Image2DOpenCL内核的输入图像().内核应该操纵数据并将其写入一个Image2DGL具有附加OpenGL纹理的图像对象.基本上它看起来像这样:
_______________ RGB _______________
| | uint8* | | CL_RGBA / CL_UNORM_INT8
| Grabber | ------------> | Image2D | -------------------------.
| avcodec | | [input] | |
|_______________| |_______________| |
|
V
_______________ _______________ _______________
| | | | | |
| Texture | ------------> | Image2DGL | <-----------------> | Kernel |
|_______________| | [output] | |_______________|
|_______________|
Internal
Format: GL_RGBA
Format: GL_RGBA
Type: ?
Run Code Online (Sandbox Code Playgroud)
我正在初始化纹理:
GLuint tex = 0;
void initTexture( …Run Code Online (Sandbox Code Playgroud) 有没有办法在MPEG流中插入用户数据(起始码= 0X1B2)?我正在寻找的是一个简单的工具,脚本或使用和Hex编辑器的一些技巧...
或者你可能有一个ffmpeg(libavcodec和libavformat)补丁允许这样做?
我开始使用ffmpeg,我想将avi文件转换为mp4/h264文件.我已经阅读了很多帖子,包括这个,但我找不到任何好的例子如何将帧保存到mp4文件.下面的代码是简化的代码,它解码来自avi文件的帧并将其编码为H264/mp4文件,但是当我保存帧时,mp4文件无法播放.我想我在编码方面做了一些错误
如果你能告诉我什么是错的以及如何解决它,我将不胜感激.
const char* aviFileName = "aviFrom.avi";
const char* mp4FileName = "mp4To.mp4";
// Filling pFormatCtx by open video file and Retrieve stream information
// ...
// Retrieving codecCtxDecode and opening codecDecode
//...
// Get encoder
codecCtxEncode = avcodec_alloc_context();
codecCtxEncode->qmax = 69;
codecCtxEncode->max_qdiff = 4;
codecCtxEncode->bit_rate = 400000;
codecCtxEncode->width = codecCtxDecode->width;
codecCtxEncode->height = codecCtxDecode->height;
codecCtxEncode->pix_fmt = AV_PIX_FMT_YUV420P;
codecEncode = avcodec_find_encoder(CODEC_ID_H264);
if(codecEncode == NULL)
return -1;
if(avcodec_open2(codecCtxEncode, codecEncode, NULL))
return -1;
SwsContext *sws_ctx = sws_getContext(codecCtxDecode->width, codecCtxDecode->height, codecCtxDecode->pix_fmt,
codecCtxDecode->width, codecCtxDecode->height, AV_PIX_FMT_YUV420P, …Run Code Online (Sandbox Code Playgroud) 在标志中解码包含AV_PKT_FLAG_KEY的数据包之后,我期待获得I帧,但我获得了P帧:
致电后:
avcodec_decode_video2(codecCtx, frame, &frameFinished, &packet); // mpeg2 video
Run Code Online (Sandbox Code Playgroud)
我打印出以下内容作为完整性检查:
printf("packet flags: %d picture type: %c\n", packet.flags,
av_get_picture_type_char(frame->pict_type));
Run Code Online (Sandbox Code Playgroud)
返回输出:
packet flags: 1 picture type: P
Run Code Online (Sandbox Code Playgroud)
当我期待:
packet flags: 1 picture type: I
Run Code Online (Sandbox Code Playgroud)
'1'== AV_PKT_FLAG_KEY.和'我'指的是AV_PICTURE_TYPE_I,
这种行为是否正确?(我正在解码MPEG2视频).
我正在研究一个libavformat API包装器,它将带有H.264和AAC的MP4文件转换为适合流式传输的MPEG-TS段.我只是在没有重新编码的情况下进行简单的流复制,但我生成的文件以3600 fps而不是24 fps 播放视频.
以下是ffprobe https://gist.github.com/chrisballinger/6733678的一些输出,损坏的文件如下:
r_frame_rate=1/1
avg_frame_rate=0/0
time_base=1/90000
start_pts=0
start_time=0.000000
duration_ts=2999
duration=0.033322
Run Code Online (Sandbox Code Playgroud)
通过ffmpeg手动发送的相同输入文件具有正确的时间戳信息:
r_frame_rate=24/1
avg_frame_rate=0/0
time_base=1/90000
start_pts=126000
start_time=1.400000
duration_ts=449850
duration=4.998333
Run Code Online (Sandbox Code Playgroud)
我认为这个问题存在于我的libavformat设置中:https://github.com/OpenWatch/FFmpegWrapper/blob/master/FFmpegWrapper/FFmpegWrapper.m#L349我在那里重新利用了ffmpeg.c中的一堆代码,这是必需的用于直接流复制.
由于3600看起来像一个"神奇的数字"(60*60),它可能就像我没有正确设置时间尺度一样简单,但我无法弄清楚我的代码与ffmpeg/avconv本身的分歧.
类似的问题在这里,但我认为他们没有达到我的目的:使用libavformat与vcopy/acopy混合使用H.264附件B和AAC流
花了大约4小时现在仍然无法弄清楚这里有什么问题.
这是终端转储:
machine@machine:~$ sudo apt-get install vlc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
vlc : Depends: vlc-nox (= 3.0.0~~git20141116+r58673+31~ubuntu14.04.1) but it …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将VPX(VP8/VP9)视频转码为mpeg2视频,并使用mpegts通过UDP进行流式传输.
我已经初始化了所有上下文和流,只要我将其流式传输到ffplay它就可以工作,如果我将流发送到VLC或其他播放器,接收器只显示第一帧而不执行任何其他操作.如果我通过命令行执行相同的操作,它可以完美地工作 - ffmpeg -re -i video.webm -an -f mpegts udp://127.0.0.1:8080
我的输出背景:
this->output_codec_ctx_->codec_type = AVMEDIA_TYPE_VIDEO; // Set media type
this->output_codec_ctx_->pix_fmt = AV_PIX_FMT_YUV420P; // Set stream pixel format
this->output_codec_ctx_->time_base.den = ceil(av_q2d(input_stream->r_frame_rate)); // Add the real video framerate. Eg.: 29.9
this->output_codec_ctx_->time_base.num = 1; // Numerator of the framerate. Eg.: num/29.9
this->output_codec_ctx_->width = input_stream->codecpar->width; // Video width
this->output_codec_ctx_->height = input_stream->codecpar->height; // Video height
this->output_codec_ctx_->bit_rate = 400000; // Video quality
this->output_codec_ctx_->gop_size = 12;
this->output_codec_ctx_->max_b_frames = 2;
this->output_codec_ctx_->framerate = this->input_codec_ctx_->framerate;
this->output_codec_ctx_->sample_aspect_ratio = this->input_codec_ctx_->sample_aspect_ratio;
Run Code Online (Sandbox Code Playgroud)
我的av_dump:
Output …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用LibAV解码mpeg视频文件。我无法正确理解两个术语:Frames和Packets。
根据我目前的理解,帧是未压缩的视频帧,数据包是已压缩的帧。
问题:
我正在尝试按照演示代码使用 libav 解码视频:此处
我需要能够控制帧数据的pFrame->data[0]存储位置。我尝试设置pFrame->data自己的缓冲区,如下所示:
// Determine required buffer size and allocate buffer
int numBytes = av_image_get_buffer_size(pixFmt, width, height, 1);
(uint8_t*) dataBuff = (uint8_t*) malloc (numBytes * sizeof(uint8_t));
// Assign buffer to image planes in pFrame
av_image_fill_arrays(frame->data, frame->linesize, dataBuff, pixFmt, width,
height, 1);
Run Code Online (Sandbox Code Playgroud)
虽然这确实设置pFrame->data为dataBuff(如果我打印它们的地址,它们是相同的),但ret = avcodec_receive_frame(pCodecContext, pFrame)接收解码数据的调用总是将数据写入不同的地址。它似乎在底层 API 的某个地方管理自己的内存,并忽略我之前dataBuff分配的内存。pFrame
所以我陷入了困境 - 我如何才能知道libav将解码的帧数据写入我预先分配的内存?我看到人们在网上和 libav 论坛中提出类似的问题,但未能找到答案。
非常感谢~
我有一个原始 h264 文件,可以在 Mac 上使用 VLC 显示:
打开-a VLC文件.h264
我可以使用命令行将其转换为 mp4
ffmpeg -f h264 -i file.h264 -c:v copy file.mp4
但我真正想做的是:
猫文件.h264 | ffmpeg > 文件.mp4
原因是输入是通过套接字传输的,我想将其转换并即时发送到 html 文件中的视频标签。
另一种解决方案是在网页中显示原始 h264,而不先将其转换为 mp4。
输入是逐帧输入的,前四个字节是 0,0,0,1。我的理解是这个h264附件B格式。
我对视频格式一无所知,我很高兴能指出一个方向来看看。
我应该像这个问题一样考虑使用 libavcodec 编写代码还是有现成的解决方案?
使用 libavformat 混合到 MP4 的 H.264 无法播放
谢谢!
libavcodec ×10
ffmpeg ×7
libav ×4
libavformat ×4
h.264 ×3
c ×1
c++ ×1
codec ×1
installation ×1
mp4 ×1
mpeg ×1
opencl ×1
opengl ×1
texture2d ×1
ubuntu ×1
ubuntu-14.04 ×1
user-data ×1
video ×1
vlc ×1