Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fps and duration to GetCodecInfo #376

Closed
wants to merge 5 commits into from

Conversation

ad-astra-video
Copy link

Add FPS and Duration data to GetCodecInfo.

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tested it and it worked fine for every video I tried! 🎉

Added two comments just for me to understand the changes.

ffmpeg/extras.c Outdated
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do? Why isn't it just this?

out->fps = frame_rate.num;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frame rates are in AVRational types that are similar to Rats in Go with a numerator and denominator. I think this is overly conservative after researching a bit more and changing to avg_frame_rate in the AVStream

ffmpeg/extras.c Outdated
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, did you check the performance of this call? Won't it slow down the input file analysis?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated to use avg_frame_rate in the AVStream from the avformat_find_stream_info call already being done. Duration is in the AVFormatContext as well so don't need to calculate. Want to note that the nb_frames was not populated on webm files I think this is a container spec driven difference compared to mp4 files.

@ad-astra-video
Copy link
Author

ad-astra-video commented Nov 3, 2023

Performance stats indicate it performs more or less the same as not getting the FPS and Duration data. Was tested on my O node so not entirely unused test environment.

Most test files from https://test-videos.co.uk

perf_test.txt

test function was:

func main() {
	p := "/home/brad/test-videos"
	items, _ := os.ReadDir(p)
	w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', tabwriter.Debug)

	fmt.Fprintln(w, "File\tTook (ms)\tFPS\tDur")
	for _, item := range items {
		vid_path := p + "/" + item.Name()
		//fmt.Println(item.Name())
		start := time.Now()
		_, mfi, err := ffmpeg.GetCodecInfo(vid_path)
		if err == nil {
			took := time.Since(start).Milliseconds()
			line := fmt.Sprintf("%v\t%v\t%v\t%v", item.Name(), took, mfi.FPS, mfi.Dur)
			fmt.Fprintln(w, line)
		} else {
			fmt.Printf("error getting codec info: %w\n", err)
		}
	}

	w.Flush()
}

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. @ad-astra-video ping me when the PR is ready to merge, then I'll merge it.

@leszko
Copy link
Contributor

leszko commented Dec 22, 2023

@ad-astra-video Is this PR ready to merge?

@ad-astra-video
Copy link
Author

I think the lpms part has no changes needed. go-livepeer does not consider getting the fps from the new fields yet though. Do you want to wait to merge until that gets added to go-livepeer?

@leszko
Copy link
Contributor

leszko commented Dec 22, 2023

I think the lpms part has no changes needed. go-livepeer does not consider getting the fps from the new fields yet though. Do you want to wait to merge until that gets added to go-livepeer?

Yeah, maybe let's wait and merge it all together

@ad-astra-video
Copy link
Author

Rebased this to current master. Testing this with AI workflows.

@j0sh
Copy link
Collaborator

j0sh commented Jul 25, 2024

Is this PR still needed now that #407 is merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants