bilibili / ijkplayer

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.
GNU General Public License v2.0
32.54k stars 8.13k forks source link

Get Live Stream Metadata #2357

Open w7virtual opened 7 years ago

w7virtual commented 7 years ago

Is it possible to read the metadata from the stream?

If I call the IjkMediaPlayer player I see this:

11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: max_frame_duration: 10.000
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Input #0, mp3, from 'http://live.radio.fm/live':
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Metadata:
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-br :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: 128
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-genre :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Top40 Hits House Dance Various Rock Alternative 80s Pop
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-name :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: RADIO.FM -=[: The Hitz Channel :]=-
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-notice1 :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: 
This stream requires Winamp

11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-notice2 :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: SHOUTcast DNAS/posix(linux x64) v2.4.7.256

11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-pub :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: 1
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: icy-url :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: http://radio.fm
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: StreamTitle :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Fifth Harmony - All In My Head (feat. Fetty Wap)
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Duration:
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: N/A
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: , start:
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: 0.000000
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: , bitrate:
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: 128 kb/s
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Stream #0:0
11-27 12:12:36.810 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: : Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s

How do i get this to a string? I want to get the data to process StreamTitle later:

11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: StreamTitle :
11-27 12:12:36.809 6292-6358/tv.danmaku.ijk.media:ijkplayer I/IJKMEDIA: Fifth Harmony - All In My Head (feat. Fetty Wap)
xinzhengzhang commented 7 years ago

av_dump_format in ff_ffplay.c

w7virtual commented 7 years ago

I've tried this:

parseMetadata(mMediaPlayer.getMediaMeta().toString());

    protected void parseMetadata( String s ) {
        String[] kvs = s.split( ";" );

        for (String kv : kvs) {
            int n = kv.indexOf( '=' );
            if (n < 1) continue;

            boolean isString = n + 1 < kv.length()
                    && kv.charAt( kv.length() - 1) == '\''
                    && kv.charAt( n + 1 ) == '\'';

            String key = kv.substring( 0, n );
            String val = isString ?
                    kv.substring( n+2, kv.length()-1) :
                    n + 1 < kv.length() ?
                            kv.substring( n+1 ) : "";

            // yes - we should detect this earlier, but it will not be null in most cases:
            Log.i("METADATA", key + val );
        }
    }

But it returns only this:

11-29 10:09:09.834 1865-1865/tv.danmaku.ijk.media:ijkplayer I/METADATA: Bundle[{streams[Bundle[{codec_level=-99, channel_layout=3, codec_name=aac, type=audio, codec_pixel_format=gray, sample_rate=44100, codec_profile_id=4}]], format=flv, audio=0, video=-1, start_us=0}]

Does not return StreamTitle

xinzhengzhang commented 7 years ago

@w7virtual av_dump_format is a C api of ffmpeg, and for now you can not access it from java.

If you need this data you have to write some jni code for accessing to the ff_ffplay.c and refer from av_dump_format in libavformat/dump.c to get what you want.

w7virtual commented 7 years ago

Considering that I have no knowledge in this language and little experience with ffmpeg, I see no other option but to abandon the project. Thank you...