Hello

I want to write a programm to convert a video. (for example from .mpg to
.flv)
I started with analysing the libavformat/output-example.c file.
This programm creates his own video and saves it in the file from the
parameter.
But I want to convert a video.
Now I add a second parameter.
Something like that....
./output-example in.mpg out.flv
I saw a tutorial about a programm that reads a video (but this is old and
throws exceptions).
Now I changed the Code and I got an exception during the runtime (when i
open the stream).
This is the relevant code from the main-methode:
   const char *filenameOut;
    const char *filenameIn;
    AVOutputFormat *avOutputFmt;
    AVFormatContext *oc;
    AVFormatContext *avFmtCtxIn;
    AVStream *audio_st, *video_st;
    double audio_pts, video_pts;
    int i;
    int videoStream;
    AVCodecContext *avCodecCtx;
    AVCodec *avCodec;

    /* Initialize libavcodec, and register all codecs and formats. */
    av_register_all();

    if (argc != 3) {
        printf("usage: %s input_file output_file\n"
               "API example program to output a media file with
libavformat.\n"
               "The output format is automatically guessed according to the
file extension.\n"
               "Raw images can also be output by using '%%d' in the
filename\n"
               "\n", argv[0]);
        return 1;
    }
    filenameIn=argv[1];
    filenameOut = argv[2];
    // Open video file
    if(avformat_open_input(&avFmtCtxIn, filenameIn, NULL, NULL)!=0)
        fprintf(stderr, "Couldn't open file\n");// Couldn't open file
    // Retrieve stream information
    if(avformat_find_stream_info(avFmtCtxIn,NULL)<0)
        fprintf(stderr, "Couldn't find stream information\n"); // Couldn't
find stream information

    fprintf(stdout, "I found the file. Now I search for the stream\n");

    // Find the first video stream
    videoStream=-1;
    for(i=0; i<avFmtCtxIn->nb_streams; i++)
    {
        if(avFmtCtxIn->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
        {
            videoStream=i;
            break;
        }
    }
    if(videoStream==-1)
        fprintf(stderr, "Couldn't find a video stream\n"); // Didn't find a
video stream
    fprintf(stdout, "I find the stream\n");

    /* Autodetect the output format from the name. default is MPEG. */
    avOutputFmt = av_guess_format(NULL, filenameOut, NULL);
    if (!avOutputFmt) {
        printf("Could not deduce output format from file extension: using
MPEG.\n");
        avOutputFmt = av_guess_format("mpeg", NULL, NULL);
    }
    if (!avOutputFmt) {
        fprintf(stderr, "Could not find suitable output format\n");
        return 1;
    }

    /* Allocate the output media context. */
    oc = avformat_alloc_context();
    if (!oc) {
        fprintf(stderr, "Memory error\n");
        return 1;
    }
    oc->oformat = avOutputFmt;
    snprintf(oc->filename, sizeof(oc->filename), "%s", filenameOut);

    /* Add the audio and video streams using the default format codecs
     * and initialize the codecs. */
//here i set the video-stream (I hope this is a possible way)
    video_st = avFmtCtxIn->streams[videoStream];//NULL;
    fprintf(stdout, "I set the videostream\n");
    audio_st = NULL;
    /*if (avOutputFmt->video_codec != CODEC_ID_NONE) {
        video_st = add_video_stream(oc, avOutputFmt->video_codec);
    }
    if (avOutputFmt->audio_codec != CODEC_ID_NONE) {
        audio_st = add_audio_stream(oc, avOutputFmt->audio_codec);
    }*/

    /* Now that all the parameters are set, we can open the audio and
     * video codecs and allocate the necessary encode buffers. */
    if (video_st)
        open_video(oc, video_st);   //In this line the error occurs

The Error message is No codec provided to avcodec_open2().

I hope you understand my problem.
Please, help me.

Thanks Bernhard
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to