0

我正在尝试在 Android 中开发一个录像机和播放应用程序。所以,我正在使用 ffmpeg 库,并且我已经编译了该库以在项目中使用。

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

ffmpeg -i f.mp4 -vf "转置=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 库转置视频?

4

1 回答 1

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

于 2013-12-12T08:35:41.547 回答