我正在通过RTSP从IP摄像头捕获JPEG图像.我使用live555 + libavcodec来流式传输和解码MJPEG图像.流可以很好地工作到图像分辨率2048 x 1920.但是当我将图像宽度增加到2048以上时,我得到一个宽度非常小的条形矩形图像(即544x1920).图像被正确捕获并保存在相机上.仅当我通过RTSP将图像流式传输到PC时才会出现此问题.对于高分辨率MJPEG,RTP中是否存在任何有效载荷限制?
我正在尝试AV_PIX_FMT_YUV420P使用 ffmpeglibavformat和将 YUV420P 图像()转换为 JPEG libavcodec。到目前为止,这是我的代码:
AVFormatContext* pFormatCtx;
AVOutputFormat* fmt;
AVStream* video_st;
AVCodecContext* pCodecCtx;
AVCodec* pCodec;
uint8_t* picture_buf;
AVFrame* picture;
AVPacket pkt;
int y_size;
int got_picture=0;
int size;
int ret=0;
FILE *in_file = NULL; //YUV source
int in_w = 720, in_h = 576; //YUV's width and height
const char* out_file = "encoded_pic.jpg"; //Output file
in_file = fopen(argv[1], "rb");
av_register_all();
pFormatCtx = avformat_alloc_context();
fmt = NULL;
fmt = av_guess_format("mjpeg", NULL, NULL);
pFormatCtx->oformat = fmt;
//Output URL …Run Code Online (Sandbox Code Playgroud) 我正在开发一个需要打开.mp4文件格式的项目,逐个读取它的帧,解码它们并用更好的无损压缩类型对它们进行编码并将它们保存到文件中.
如果我对做事的顺序错了,请纠正我,因为我不是100%确定应该怎么做这件事.根据我的理解,它应该是这样的:
1. Open input .mp4 file
2. Find stream info -> find video stream index
3. Copy codec pointer of found video stream index into AVCodecContext type pointer
4. Find decoder -> allocate codec context -> open codec
5. Read frame by frame -> decode the frame -> encode the frame -> save it into a file
Run Code Online (Sandbox Code Playgroud)
到目前为止,我遇到了几个问题.例如,如果我想使用av_interleaved_write_frame()函数保存框架,我无法打开输入.mp4文件,avformat_open_input()因为它将使用输入文件名填充结构的filename一部分,AVFormatContext因此我无法"写入"该文件.我尝试过不同的解决方案,av_guess_format()但是当我使用i转储格式时,我dump_format()什么都没得到,所以我找不到关于它使用哪种编解码器的流信息.
所以如果有人有任何建议,我会非常感激他们.先感谢您.
我知道它复制了一些东西,但除此之外它做了什么(它会影响输出文件的范围)?是开关还是选项?为什么它在单词本身之前没有连字符?
我从其他问题中看到它可以在没有转码的情况下复制流,但是我可以操纵它的其他可能性是什么?
我已经完成ffmpeg --help但我没有看到任何关于它的文档.有网站我可以阅读更多关于它的内容吗?
我正在编写一个程序来从视频流中提取图像。到目前为止,我已经弄清楚如何寻找正确的帧,解码视频流,并将相关数据收集到 AVFrame 结构中。我现在试图将数据写成 JPEG 图像,但我的代码不起作用。我得到的代码来自这里:https : //gist.github.com/RLovelett/67856c5bfdf5739944ed
int save_frame_as_jpeg(AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo) {
AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000);
if (!jpegCodec) {
return -1;
}
AVCodecContext *jpegContext = avcodec_alloc_context3(jpegCodec);
if (!jpegContext) {
return -1;
}
jpegContext->pix_fmt = pCodecCtx->pix_fmt;
jpegContext->height = pFrame->height;
jpegContext->width = pFrame->width;
if (avcodec_open2(jpegContext, jpegCodec, NULL) < 0) {
return -1;
}
FILE *JPEGFile;
char JPEGFName[256];
AVPacket packet = {.data = NULL, .size = 0};
av_init_packet(&packet);
int gotFrame;
if (avcodec_encode_video2(jpegContext, &packet, pFrame, &gotFrame) < 0) {
return …Run Code Online (Sandbox Code Playgroud) 主要区别是什么?假设我有一个.flv格式的视频,我想使用avcodec.dll将其转换为格式.h264.我会编码还是解码它?我真的很困惑.任何明确的答案将不胜感激.
人们,祝你有美好的一天!
我正在编写一个Windows应用程序,它将捕获屏幕并通过rtmp(用于广播)将流发送到Wowza服务器.我的应用程序使用ffmpeg和Qt.我使用WinApi捕获屏幕,将缓冲区转换为YUV444(因为它最简单)并按照文件decode_encoding.c(来自FFmpeg示例)中的描述对帧进行编码:
///////////////////////////
//Encoder initialization
///////////////////////////
avcodec_register_all();
codec=avcodec_find_encoder(AV_CODEC_ID_H264);
c = avcodec_alloc_context3(codec);
c->width=scr_width;
c->height=scr_height;
c->bit_rate = 400000;
int base_num=1;
int base_den=1;//for one frame per second
c->time_base= (AVRational){base_num,base_den};
c->gop_size = 10;
c->max_b_frames=1;
c->pix_fmt = AV_PIX_FMT_YUV444P;
av_opt_set(c->priv_data, "preset", "slow", 0);
frame = avcodec_alloc_frame();
frame->format = c->pix_fmt;
frame->width = c->width;
frame->height = c->height;
for(int counter=0;counter<10;counter++)
{
///////////////////////////
//Capturing Screen
///////////////////////////
GetCapScr(shotbuf,scr_width,scr_height);//result: shotbuf is filled by screendata from HBITMAP
///////////////////////////
//Convert buffer to YUV444 (standard formula)
//It's handmade function because of problems with prepare buffer …Run Code Online (Sandbox Code Playgroud) 我试图在ffmpeg/libav中将RGB帧转换为YUV420P格式.以下是转换代码以及转换前后的图像.转换后的图像会丢失所有颜色信息,并且尺度也会发生显着变化.有谁知道如何处理这个?我是ffmpeg/libav的新手!
// Did we get a video frame?
if(frameFinished)
{
i++;
sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame->data,
pFrame->linesize, 0, pCodecCtx->height,
pFrameRGB->data, pFrameRGB->linesize);
//==============================================================
AVFrame *pFrameYUV = avcodec_alloc_frame();
// Determine required buffer size and allocate buffer
int numBytes2 = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
pCodecCtx->height);
uint8_t *buffer = (uint8_t *)av_malloc(numBytes2*sizeof(uint8_t));
avpicture_fill((AVPicture *)pFrameYUV, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
rgb_to_yuv_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
PIX_FMT_RGB24,
pCodecCtx->width,pCodecCtx->height,
PIX_FMT_RGB24,
SWS_BICUBIC, NULL,NULL,NULL);
sws_scale(rgb_to_yuv_ctx, pFrameRGB->data, pFrameRGB->linesize, 0,
pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
sws_freeContext(rgb_to_yuv_ctx);
SaveFrame(pFrameYUV, pCodecCtx->width, pCodecCtx->height, i);
av_free(buffer);
av_free(pFrameYUV);
}
Run Code Online (Sandbox Code Playgroud)


我正在尝试编译 libavcodec 示例。我收到以下错误:
\n\nlol@foldingmachine:~/p/avtest$ g++ main.cpp -o main -lavcodec\nmain.cpp: In function \xe2\x80\x98void audio_decode_example(const char*, const char*)\xe2\x80\x99:\nmain.cpp:57:15: warning: \xe2\x80\x98int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)\xe2\x80\x99 is deprecated [-Wdeprecated-declarations]\n len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);\n ^~~~~~~~~~~~~~~~~~~~~\nIn file included from main.cpp:1:0:\n/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here\n int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,\n ^~~~~~~~~~~~~~~~~~~~~\nmain.cpp:57:73: warning: \xe2\x80\x98int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)\xe2\x80\x99 is deprecated [-Wdeprecated-declarations]\n len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);\n ^\nIn file included from main.cpp:1:0:\n/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here\n int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,\n ^~~~~~~~~~~~~~~~~~~~~\n/tmp/ccbXVtbs.o: In function `audio_decode_example(char …Run Code Online (Sandbox Code Playgroud) 我正在研究ffmpeg将其核心功能用作其一部分的python项目。从本质上讲ffmpeg,我使用的功能归结为以下两个命令:
ffmpeg -i udp://<address:port> -qscale:v 2 -vf "fps=30" sttest%04d.jpg
ffmpeg -i udp://<address:port> -map data-re -codec copy -f data out.bin
Run Code Online (Sandbox Code Playgroud)
很简单的东西。
我正在尝试创建一个自包含的程序(使用上述ffmpeg功能),可以轻松地将其安装在任何特定系统上,而无需依赖具有必要依赖项的系统,因为我希望将这些依赖项与程序本身打包在一起。
考虑到这一点,最好在程序中使用这些libav*库来执行此功能吗?还是ffmpy使用ffmpeg命令行工具的包装器()更好?我目前对每种弊端的想法是,使用库可能是最佳实践,但是要学会使用它们似乎很复杂(并且可能会学习C,这是我从未学过的C)。做我上面提到的两个基本的事情。总体而言,这些库对我来说有点黑匣子,并且没有太多的文档。但是,使用包装器的问题ffmpeg在于它本质上依赖于调用子进程,这似乎有些草率。尽管我不确定为什么我会如此强烈地反对子流程。