相关疑难解决方法(0)

如何使用FFmpeg C API剪切视频

如何使用FFmpeg C API剪切视频?例如从00:10:00到00:20:00.我需要使用哪些功能?

我使用此功能转换视频:

int convert(char *file) {
    AVFrame *frame;
    AVPacket inPacket, outPacket;

    if(avio_open(&outFormatContext->pb, file, AVIO_FLAG_WRITE) < 0) {
        fprintf(stderr, "convert(): cannot open out file\n");
        return 0;
    }

    avformat_write_header(outFormatContext, NULL);
    frame = avcodec_alloc_frame();
    av_init_packet(&inPacket);

    while(av_read_frame(inFormatContext, &inPacket) >= 0) {
        if(inPacket.stream_index == inVideoStreamIndex) {
            avcodec_decode_video2(inCodecContext, frame, &frameFinished, &inPacket);
            if(frameFinished) {
                av_init_packet(&outPacket);
                avcodec_encode_video2(outCodecContext, &outPacket, frame, &outputed);
                if(outputed) {
                    if (av_write_frame(outFormatContext, &outPacket) != 0) {
                        fprintf(stderr, "convert(): error while writing video frame\n");
                        return 0;
                    }
                }
                av_free_packet(&outPacket);
            }
        }
    }

    av_write_trailer(outFormatContext);
    av_free_packet(&inPacket);
    return …
Run Code Online (Sandbox Code Playgroud)

c api ffmpeg

5
推荐指数
2
解决办法
4421
查看次数

使用ffmpeg创建视频

我有100张图像(PNG),我想用这些图像创建一个视频.我正在使用ffmpeg库.使用命令行我可以轻松创建视频.但是我如何通过编码来做到这一点?

任何帮助将不胜感激.

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef HAVE_AV_CONFIG_H
#undef HAVE_AV_CONFIG_H
#endif

extern "C"
{
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
#include "libavutil/samplefmt.h"
}

#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096




static void video_encode_example(const char *filename, int codec_id)
{
   AVCodec *codec;
   AVCodecContext *c= NULL;
   int i, out_size, size, x, y, outbuf_size;
   FILE *f;
   AVFrame *picture;
   uint8_t *outbuf;
   int nrOfFramesPerSecond  =25;
   int nrOfSeconds =1;


   printf("Video encoding\n");

//    find the mpeg1 video …
Run Code Online (Sandbox Code Playgroud)

c++ ffmpeg

4
推荐指数
1
解决办法
5574
查看次数

标签 统计

ffmpeg ×2

api ×1

c ×1

c++ ×1