【发布时间】:2016-02-20 19:29:25
【问题描述】:
我正在使用以下代码将avcodec_decode_video2()输出的图像帧提取到BMP文件中:
// Convert the image from its native format to RGB
int height = sws_scale(state.sws_ctx,
(uint8_t const * const *)state.frame->data,
state.frame->linesize,
0,
state.video_codec_ctx->height,
state.picture.data,
state.picture.linesize);
// ..... here BMP header initialization goes ...
// Extract pixels
{
int y = 0;
size_t frame_line_size = state.picture.linesize[0];
uint8_t* bmp_data = &bmp->data[0];
uint8_t* picture_data = state.picture.data[0];
while(y < height)
{
memcpy(bmp_data, picture_data, image_line_size);
bmp_data += image_line_size_with_padding;
picture_data += frame_line_size;
++y;
}
}
但它会导致图像翻转:
谁能帮我理解,我在这里做错了什么?
视频流信息:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'testdata/video3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
title : video3.mp4
encoder : Lavf52.78.3
Duration: 00:00:07.93, start: 0.000000, bitrate: 1467 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 640x320 [PAR 1:1 DAR 2:1], 1331 kb/s, 29.73 fps, 29.73 tbr, 29734 tbn, 59.47 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1(und): Audio: aac, 48000 Hz, stereo, fltp, 127 kb/s
Metadata:
creation_time : 1970-01-01 00:00:00
Video file 'testdata/video3.mp4' has 236 frames.
我有使用 libopencv 的替代代码,它从同一个视频文件中提供正确的图像,但我需要直接使用 ffmpeg 库来达到正确的效果。
【问题讨论】:
-
不幸的是,BMP 认为第 0 行是最底行。
-
谢谢,我不知道。所以只需要重新排序行。
标签: c ffmpeg libavcodec libavformat