Skip to content

Commit

Permalink
Fix segfault and invalid video resolution for H.264 codec in videoplugin
Browse files Browse the repository at this point in the history
As mentioned in #140 the video
resolution for H.264 videos should be a multiple of 4.
  • Loading branch information
danielkaiser committed Aug 11, 2021
1 parent 8639d49 commit 9e99b73
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/gks/plugin/vc.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ movie_t vc_movie_create(const char *path, int framerate, int bitrate, int width,
}
movie->out_fmt = movie->fmt_ctx->oformat;
codec = avcodec_find_encoder(movie->out_fmt->video_codec);
if (!codec && movie->out_fmt->video_codec == 12)
if (!codec && movie->out_fmt->video_codec == AV_CODEC_ID_MPEG4)
{
codec = avcodec_find_encoder_by_name("libopenh264");
}
Expand All @@ -134,6 +134,11 @@ movie_t vc_movie_create(const char *path, int framerate, int bitrate, int width,
gks_free(movie);
return NULL;
}
if (movie->out_fmt->video_codec == AV_CODEC_ID_H264)
{
width += (4 - width % 4) % 4;
height += (4 - height % 4) % 4;
}

movie->video_st = avformat_new_stream(movie->fmt_ctx, codec);
if (!movie->video_st)
Expand Down Expand Up @@ -256,6 +261,7 @@ void vc_movie_finish(movie_t movie)
av_frame_free(&movie->frame);
movie->frame = NULL;
encode_frame(movie);
av_write_trailer(movie->fmt_ctx);
}

if (movie->sws_ctx)
Expand All @@ -270,7 +276,6 @@ void vc_movie_finish(movie_t movie)

if (movie->fmt_ctx && movie->cdc_ctx)
{
av_write_trailer(movie->fmt_ctx);
avcodec_close(movie->cdc_ctx);

if (!(movie->out_fmt->flags & AVFMT_NOFILE))
Expand Down

0 comments on commit 9e99b73

Please sign in to comment.