Skip to content

Commit

Permalink
add fps and duration to GetCodecInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-astra-video committed Jul 3, 2024
1 parent 343a3dd commit 4089421
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ffmpeg/extras.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ int lpms_get_codec_info(char *fname, pcodec_info out)
}
out->width = ic->streams[vstream]->codecpar->width;
out->height = ic->streams[vstream]->codecpar->height;

AVRational frame_rate = av_guess_frame_rate(ic,ic->streams[vstream],NULL);
out->fps = (frame_rate.num && frame_rate.den ? av_q2d(frame_rate) : 0);
out->dur = (double)ic->streams[vstream]->nb_frames / out->fps;
} else {
// Indicate failure to extract video codec from given container
out->video_codec[0] = 0;
Expand Down
2 changes: 2 additions & 0 deletions ffmpeg/extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ typedef struct s_codec_info {
int pixel_format;
int width;
int height;
double fps;
double dur;
} codec_info, *pcodec_info;

int lpms_rtmp2hls(char *listen, char *outf, char *ts_tmpl, char *seg_time, char *seg_start);
Expand Down
5 changes: 5 additions & 0 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ type MediaFormatInfo struct {
Acodec, Vcodec string
PixFormat PixelFormat
Width, Height int
FPS float32
Dur float32
}

func (f *MediaFormatInfo) ScaledHeight(width int) int {
Expand Down Expand Up @@ -276,6 +278,9 @@ func GetCodecInfo(fname string) (CodecStatus, MediaFormatInfo, error) {
format.PixFormat = PixelFormat{int(params_c.pixel_format)}
format.Width = int(params_c.width)
format.Height = int(params_c.height)
format.FPS = float32(params_c.fps)
format.Dur = float32(params_c.dur)

return status, format, nil
}

Expand Down

0 comments on commit 4089421

Please sign in to comment.