如何使用ffmpeg库转置视频?

时间:2012-09-19 11:36:05

标签: c ffmpeg

我正在尝试在Android中开发录像机和播放应用。所以,我正在使用ffmpeg库,我已经编译了要在项目中使用的库。

我录制视频,当我播放时,在某些设备中无法识别方向矩阵,所以我想用ffmpeg库开发一个C方法来执行此命令:

ffmpeg -i f.mp4 -vf“transpose = 1”-r 24 -sameq f2.mp4“

我找到了这个文档,但没有帮助我,因为不要使用AVFilter和AVFilterContext类。

http://dranger.com/ffmpeg/tutorial01.html

http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/structAVFilterContext.html

http://ffmpeg.org/doxygen/trunk/api-example_8c-source.html

现在我只有开始和结束的视频文件

这是我的代码:

/*open the video file*/
if ((lError = av_open_input_file(&gFormatCtx, gFileName, NULL, 0, NULL)) !=0 ) {
    LOGE(1, "Error open video file: %d", lError);
    return; //open file failed
}
/*retrieve stream information*/
if ((lError = av_find_stream_info(gFormatCtx)) < 0) {
    LOGE(1, "Error find stream information: %d", lError);
    return;
} 
/*find the video stream and its decoder*/
gVideoStreamIndex = av_find_best_stream(gFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &lVideoCodec, 0);
if (gVideoStreamIndex == AVERROR_STREAM_NOT_FOUND) {
    LOGE(1, "Error: cannot find a video stream");
    return;
} else {
LOGI(10, "video codec: %s", lVideoCodec->name);
}
if (gVideoStreamIndex == AVERROR_DECODER_NOT_FOUND) {
    LOGE(1, "Error: video stream found, but no decoder is found!");
    return;
}   
/*open the codec*/
gVideoCodecCtx = gFormatCtx->streams[gVideoStreamIndex]->codec;
LOGI(10, "open codec: (%d, %d)", gVideoCodecCtx->height, gVideoCodecCtx->width);
#ifdef SELECTIVE_DECODING
gVideoCodecCtx->allow_selective_decoding = 1;
#endif
if (avcodec_open(gVideoCodecCtx, lVideoCodec) < 0) {
LOGE(1, "Error: cannot open the video codec!");
    return;
}
LOGI(10, "get video info ends");

如何使用ffmpeg库转置视频?

1 个答案:

答案 0 :(得分:0)

如何使用FFmpeg解码客户I / O

AVCodec *pCodec;
avcodec_register_all();
// Register all formats and codecs
av_register_all();

//av_init_packet(&packet);
if(avformat_network_init()!=0){
    goto initError; // Couldn't init new work
}
// Open video file

pFormatCtx = avformat_alloc_context();
printf("==========>>%p %lu\n", buff,sizeof(buff));
pFormatCtx->pb=av_malloc(buff_size);//pFormatCtx->pb=av_alloc_put_byte(buff,buff_size,0,NULL,NULL,NULL,NULL);
pFormatCtx->pb=avio_alloc_context(buff,buff_size,0,NULL,NULL,NULL,NULL);

pFormatCtx->iformat=av_find_input_format("h264");
pFormatCtx->flags = AVFMT_FLAG_CUSTOM_IO;
pFormatCtx->iformat->flags=AVFMT_NOFILE;

// Retrieve stream information
 if(avformat_find_stream_info(pFormatCtx,NULL)<0){
        goto initError; // Couldn't find stream information
}
 streamNo=-1;
// Find the first video stream
if ((streamNo =  av_find_best_stream(pFormatCtx,AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0)) < 0)
{
    av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file %d\n",streamNo);
    goto initError;
}

虽然我无法从我的缓冲区中找到流,但是streamNo总是-1381258232 我的缓冲区是void * buff int buff_size