vansante / go-ffprobe

Library to easily get the ffprobe output of a given file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ProbeReader does not work for some files

dineshgowda24 opened this issue · comments

Download this audio file.

https://easyupload.io/43dsf4

ff, _:=os.Open("/Users/dinesh/Downloads/o0apgjpm494n.oga")
data, err := ffprobe.ProbeReader(ctx,ff)
if err != nil {
	log.Println("Error getting data", err)
}
b, _:=json.Marshal(data)
fmt.Println(string(b))

StdOut
2021/02/18 15:05:21 Error getting data error running ffprobe [] exit status 1

If I run the ffprobe command with file path in works in the terminal.

❯ ffprobe -loglevel fatal  -print_format json -show_format -show_streams -show_private_data ~/Downloads/o0apgjpm494n.oga
{
    "streams": [
        {
            "index": 0,
            "codec_name": "opus",
            "codec_long_name": "Opus (Opus Interactive Audio Codec)",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 1,
            "channel_layout": "mono",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 104,
            "start_time": "0.002167",
            "duration_ts": 157544,
            "duration": "3.282167",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0
            }
        }
    ],
    "format": {
        "filename": "/Users/dinesh/Downloads/o0apgjpm494n.oga",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "ogg",
        "format_long_name": "Ogg",
        "start_time": "0.002167",
        "duration": "3.282167",
        "size": "7323",
        "bit_rate": "17849",
        "probe_score": 100
    }
}

I am thinking of adding a function that would take filepath as argument and execute the ffprobe command similarly how you have done for URL.

Lemme know if I can raise a PR or if there is any other fix for this issue.

commented

I just tried your file with a temporary test I added:

func Test_ProbeURL2(t *testing.T) {
	ctx, cancelFn := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancelFn()

	ff, err := os.Open("assets/test.ogx")
	if err != nil {
		t.Fatal(err)
	}
        defer ff.Close()

	data, err := ProbeReader(ctx, ff)
	if err != nil {
		t.Fatal(err)
	}
	b, err := json.Marshal(data)
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println(string(b))
}

and the results were just fine:

/usr/local/go/bin/go tool test2json -t /tmp/___Test_ProbeURL2_in_gopkg_in_vansante_go_ffprobe_v2 -test.v -test.run ^\QTest_ProbeURL2\E$
=== RUN   Test_ProbeURL2
{"streams":[{"index":0,"id":"","codec_name":"opus","codec_long_name":"Opus (Opus Interactive Audio Codec)","codec_type":"audio","codec_time_base":"1/48000","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":104,"start_time":"0.002167","duration_ts":0,"duration":"","bit_rate":"","bits_per_raw_sample":"","nb_frames":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0},"tags":{},"width":0,"height":0,"sample_fmt":"fltp","sample_rate":"48000","channels":1,"channel_layout":"mono"}],"format":{"filename":"pipe:","nb_streams":1,"nb_programs":0,"format_name":"ogg","format_long_name":"Ogg","start_time":"0.002167","duration":"0","size":"","bit_rate":"","probe_score":100,"tags":null}}
--- PASS: Test_ProbeURL2 (0.04s)
PASS

Perhaps try not to ignore errors and instead handle them, perhaps there is an error in your path or something like that.

ok lemme try. But why is the duration field 0
I am also interested in duration in my application.

Also do u think it might be due to file extension?
I am using oga and u are using ogx.

Can you try with oga once.

commented

It's not the file extension, since the package is not even aware of the filenames when using ProbeReader(). In this case, since you are scanning a local file, you might just want to use ProbeURL() (with the local filepath).

Now there does seem to be an issue with the duration not being detected properly when using ProbeReader(). But that does not seem to be related to my package, as it also does not work when using a pipe using the commandline:

cat ~/Downloads/o0apgjpm494n.ogx | ffprobe -loglevel fatal -print_format json -show_format -show_streams -show_private_data -
{
    "streams": [
        {
            "index": 0,
            "codec_name": "opus",
            "codec_long_name": "Opus (Opus Interactive Audio Codec)",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 1,
            "channel_layout": "mono",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 104,
            "start_time": "0.002167",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0
            }
        }
    ],
    "format": {
        "filename": "pipe:",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "ogg",
        "format_long_name": "Ogg",
        "start_time": "0.002167",
        "probe_score": 100
    }
}
commented

Closing this, please let me know if you experience further issues.