Skip to content

Commit

Permalink
Remove scene detection code (#377)
Browse files Browse the repository at this point in the history
* Remove scene detection code

* Remove tensorflow from runner
  • Loading branch information
thomshutt authored Jan 15, 2024
1 parent 663c622 commit 98566e2
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 478 deletions.
5 changes: 0 additions & 5 deletions .github/runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ RUN cd /home/devops && mkdir actions-runner && cd actions-runner \
&& curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
&& tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz && chown -R devops ~devops

RUN LIBTENSORFLOW_VERSION=2.6.3 \
&& curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz \
&& sudo tar -C /usr/local -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz \
&& sudo ldconfig

# Add mime type for ts
RUN sudo echo '<?xml version="1.0" encoding="UTF-8"?><mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"><mime-type type="video/mp2t"><comment>ts</comment><glob pattern="*.ts"/></mime-type></mime-info>'>>/usr/share/mime/packages/custom_mime_type.xml
RUN sudo update-mime-database /usr/share/mime
Expand Down
111 changes: 0 additions & 111 deletions cmd/scenedetection/scenedetection.go

This file was deleted.

10 changes: 2 additions & 8 deletions cmd/transcoding/transcoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func main() {
o := ffmpeg.TranscodeOptions{
Oname: fmt.Sprintf("out_%s_%d_out.mp4", lbl, i),
Profile: profs[i],
// Uncomment the following to test scene classifier
// Detector: &ffmpeg.DSceneAdultSoccer,
Accel: accel,
Accel: accel,
}
o.From = *from
o.To = *to
Expand Down Expand Up @@ -99,11 +97,7 @@ func main() {
end := time.Now()
fmt.Printf("profile=input frames=%v pixels=%v\n", res.Decoded.Frames, res.Decoded.Pixels)
for i, r := range res.Encoded {
if r.DetectData != nil {
fmt.Printf("profile=%v frames=%v pixels=%v detectdata=%v\n", profiles[i].Name, r.Frames, r.Pixels, r.DetectData)
} else {
fmt.Printf("profile=%v frames=%v pixels=%v\n", profiles[i].Name, r.Frames, r.Pixels)
}
fmt.Printf("profile=%v frames=%v pixels=%v\n", profiles[i].Name, r.Frames, r.Pixels)
}
fmt.Printf("Transcoding time %0.4v\n", end.Sub(t).Seconds())
}
55 changes: 0 additions & 55 deletions ffmpeg/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,61 +1520,6 @@ func TestTranscoder_CompareVideo(t *testing.T) {
compareVideo(t, Software)
}

func detectionFreq(t *testing.T, accel Acceleration, deviceid string) {
run, dir := setupTest(t)
defer os.RemoveAll(dir)
cmd := `
# run segmenter and sanity check frame counts . Hardcode for now.
ffmpeg -loglevel warning -i "$1"/../transcoder/test.ts -c:a copy -c:v copy -f hls test.m3u8
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test0.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test1.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test2.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test3.ts | grep nb_read_frames=120
`
run(cmd)

InitFFmpeg()
tc, err := NewTranscoderWithDetector(&DSceneAdultSoccer, deviceid)
require.NotNil(t, tc, "look for `Failed to load native model` logs above")
if err != nil {
t.Error(err)
} else {
defer tc.StopTranscoder()
// Test encoding with only seg0 and seg2 under detection
prof := P144p30fps16x9
for i := 0; i < 4; i++ {
in := &TranscodeOptionsIn{
Fname: fmt.Sprintf("%s/test%d.ts", dir, i),
Accel: accel,
}
out := []TranscodeOptions{
{
Oname: fmt.Sprintf("%s/out%d.ts", dir, i),
Profile: prof,
Accel: accel,
},
}
if i%2 == 0 {
out = append(out, TranscodeOptions{
Detector: &DSceneAdultSoccer,
Accel: accel,
})
}
res, err := tc.Transcode(in, out)
if err != nil {
t.Error(err)
}
if i%2 == 0 && (len(res.Encoded) < 2 || res.Encoded[1].DetectData == nil) {
t.Error("No detect data returned for detection profile")
}
}
}
}

func TestTranscoder_DetectionFreq(t *testing.T) {
detectionFreq(t, Software, "-1")
}

func discontinuityAudioSegment(t *testing.T, accel Acceleration) {
run, dir := setupTest(t)
defer os.RemoveAll(dir)
Expand Down
69 changes: 0 additions & 69 deletions ffmpeg/detector.go

This file was deleted.

39 changes: 0 additions & 39 deletions ffmpeg/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ int open_output(struct output_ctx *octx, struct input_ctx *ictx)

// add video encoder if a decoder exists and this output requires one
if (ictx->vc && needs_decoder(octx->video->name)) {
if (octx->dnn_filtergraph && !ictx->vc->hw_frames_ctx) {
// swap filtergraph with the pre-initialized DNN filtergraph for SW
// for HW we handle it later during filter re-init
octx->vf.graph = *octx->dnn_filtergraph;
}
ret = init_video_filters(ictx, octx);
if (ret < 0) LPMS_ERR(open_output_err, "Unable to open video filter");

Expand Down Expand Up @@ -435,32 +430,6 @@ int mux(AVPacket *pkt, AVRational tb, struct output_ctx *octx, AVStream *ost)
return av_interleaved_write_frame(octx->oc, pkt);
}

static int getmetadatainf(AVFrame *inf, struct output_ctx *octx)
{
if(inf == NULL) return -1;
char classinfo[128] = {0,};
AVDictionaryEntry *element = NULL;
AVDictionary *metadata = inf->metadata;

if(metadata != NULL) {
element = av_dict_get(metadata, LVPDNN_FILTER_META, element, 0);
if(element != NULL) {
strcpy(classinfo, element->value);
if(strlen(classinfo) > 0) {
char * token = strtok(classinfo, ",");
int cid = 0;
while( token != NULL ) {
octx->res->probs[cid] += atof(token);
token = strtok(NULL, ",");
cid++;
}
octx->res->frames++;
}
}
}
return 0;
}

static int calc_signature(AVFrame *inf, struct output_ctx *octx)
{
int ret = 0;
Expand Down Expand Up @@ -552,19 +521,11 @@ int process_out(struct input_ctx *ictx, struct output_ctx *octx, AVCodecContext
octx->next_kf_pts = frame->pts + octx->gop_pts_len;
}

if(octx->is_dnn_profile) {
ret = getmetadatainf(frame, octx);
if(ret == -1 && frame == NULL) {
// Return EOF in case of flushing procedure
ret = AVERROR_EOF;
}
} else {
if(is_video && frame != NULL && octx->sfilters != NULL) {
ret = calc_signature(frame, octx);
if(ret < 0) LPMS_WARN("Could not calculate signature value for frame");
}
ret = encode(encoder, frame, octx, ost);
}
skip:
av_frame_unref(frame);
// For HW we keep the encoder open so will only get EAGAIN.
Expand Down
Loading

0 comments on commit 98566e2

Please sign in to comment.