0

I want to record video from camera with subtitles using FFMPEG and C. I was used examples on main FFMPEG repository and had successfully recorded video from camera. But with subtitles I'm stuck and do not know how to make it works. I was also tried example where shows how to re-mux video with existing one - it works but I can't understand how to create my own.

I have as example one video from my DJI drone. There is 2 streams: one for video and second for subtitles. I can see that codec for video is h264 and codec for subtitles is mov_text. But once I try to open this codec in my code (codec id = AV_CODEC_ID_MOV_TEXT) every time it fails. I had installed FFMPEG from default ubuntu repository. In debug I was noticed(but may be wrong) that stream for subtitles present and have field codec_type = AVMEDIA_TYPE_SUBTITLE, codec_id = AV_CODEC_ID_MOV_TEXT but codec itself is NULL. Is it right for subtitles? Any FFMPEG manuals doesn't contain hints how to manage subtitles, so I will be happy if someone help my with that. Thanks in advance!

void open_instance_codec(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) {
    int ret;
    AVCodecContext *c = ost->encoder;
    AVDictionary *opt = NULL;

    av_dict_copy(&opt, opt_arg, 0);
    av_dict_set(&opt, "loglevel", "debug", 0);
    av_dict_set(&opt, "stats", "1", 0);


    ret = avcodec_open2(c, codec, &opt); // failed to open subtitle codec
    av_dict_free(&opt);
    if (ret < 0) {

        fprintf(stderr, "Could not open %s codec \n", codec->name);
        char str[AV_ERROR_MAX_STRING_SIZE];
        av_make_error_string(reinterpret_cast<char *>(str), AV_ERROR_MAX_STRING_SIZE, ret);
        fprintf(stderr, "This error means: '%s'\n", str); /// This error means: 'Invalid data found when processing input'

        exit(1);
    }


    ret = avcodec_parameters_from_context(ost->strm->codecpar, c);
    if (ret < 0) {
        fprintf(stderr, "Could not copy the stream parameters\n");
        exit(1);
    }
}
Serhii
  • 1
  • 1

0 Answers0