bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.61k stars 1.59k forks source link

FFMPEG + ICECAST Server with javacv #431

Open rpgomes opened 8 years ago

rpgomes commented 8 years ago

Hello,

I'm making some tests about live streaming in the web using webm (with VP8)

I'm using FFMPEG + ICECAST.

Now the command I'm performing with ffmpeg is:

F:\ffmpeg_2.8-20151011-git-f05ff05-win32-static\bin>

ffmpeg.exe -rtsp_transport tcp -i "rtsp://192.168.230.121/profile?token=media_profile1&SessionTimeout=60" -f webm -r 20 -c:v libvpx -b:v 3M -s 300x200 -acodec none -content_type video/webm -crf 63 -g 0 icecast://source:hackme@192.168.0.146:8001/test

How do I make this with FmpegFrameRecorder?

saudet commented 8 years ago

Could you explain what you tried and provide the results you got?

rpgomes commented 8 years ago

certainly.

My code is:

   FFmpegFrameRecorder ff = null;
    try {
    ff = new FFmpegFrameRecorder("icecast://source:hackme@192.168.0.146:8001/test.webm", 333,333,0);
    ff.setVideoCodec(avcodec.AV_CODEC_ID_VP8);
    ff.setAudioCodec(0);
    ff.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
    ff.setFormat("webm");
    ff.setGopSize(10);
    ff.setFrameRate(20);
    ff.setVideoBitrate(5000);
    ff.setOption("content_type","video/webm");

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        ff.start();
    } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Java2DFrameConverter converter1 = new Java2DFrameConverter();

    BufferedImage img = null;
    try {
        img = ImageIO.read(new File("c:/sdf.jpg") );
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    Frame fr = converter1.convert(img);

    while(true) {
        try {
            ff.setTimestamp(new Date().getTime());
            ff.record(fr);
        } catch (org.bytedeco.javacv.FrameRecorder.Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

I don't get any error in code, but in icecast administration window I see bytes arriving but the server type is still set to audio/mpeg and not video/webm

If I try to run the stream with ffplay i get an:

ffplay -probesize 30002 -sync ext -i "http://192.168.0.146:8001/test.webm" ffplay version N-75924-gd25c033 Copyright (c) 2003-2015 the FFmpeg developers built with gcc 5.2.0 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca -- enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --ena ble-decklink --enable-zlib libavutil 55. 3.100 / 55. 3.100 libavcodec 57. 5.100 / 57. 5.100 libavformat 57. 3.100 / 57. 3.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 11.100 / 6. 11.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.100 / 2. 0.100 libpostproc 54. 0.100 / 54. 0.100 http://192.168.0.146:8001/agora.webm: Invalid data found when processing input

rpgomes commented 8 years ago

If I try with ffplay the stream with ffmpeg commad the output (the desire output that i want with javacv) is

Input #0, matroska,webm, from 'http://192.168.0.146:8001/test_ffmpeg_direc': Metadata: title : Sony RTSP Server encoder : Lavf57.3.100 icy-pub : 0 icy-metadata : 1 Duration: N/A, start: 11.900000, bitrate: N/A Stream #0:0: Video: vp8, yuv420p, 300x200, SAR 89:75 DAR 89:50, 20 fps, 20 t br, 1k tbn, 1k tbc (default)

rpgomes commented 8 years ago

In icecast admin window I see the following data for the ffmpeg command stream:

genre   various
listener_peak   0
listeners   0
listenurl   http://192.168.0.146:8001/video
max_listeners   unlimited
public  0
server_description  Unspecified description
server_name Unspecified name
server_type video/webm
slow_listeners  0
source_ip   192.168.0.69
stream_start    Thu, 09 Jun 2016 14:25:48 +0100
stream_start_iso8601    2016-06-09T14:25:48+0100
total_bytes_read    0
total_bytes_sent    0
user_agent  Lavf/56.15.102

for the javacv Stream

genre   various
listener_peak   0
listeners   0
listenurl   http://192.168.0.146:8001/test
max_listeners   unlimited
public  0
server_description  Unspecified description
server_name Unspecified name
server_type audio/mpeg
slow_listeners  0
source_ip   192.168.0.69
stream_start    Thu, 09 Jun 2016 14:19:12 +0100
stream_start_iso8601    2016-06-09T14:19:12+0100
total_bytes_read    13619200
total_bytes_sent    0
user_agent  Lavf/56.40.101

there are differences in the user_agent (ffmpeg versions I supposed) and in server_type

saudet commented 8 years ago

What do you get on the console when using FFmpegFrameRecorder?

rpgomes commented 8 years ago

in the ffplay console I'm only receiving:

http://192.168.0.146:8001/test: Invalid data found when processing input

saudet commented 8 years ago

Yes but what do you get at the other end?

rpgomes commented 8 years ago

Sorry Saudet, I'm not understanding what you are asking, in java I don't get any exception and in icecast server console i'm seeing the server type as audio/mpeg and not as video/webm

tomerhatav commented 8 years ago

"Icecast is a streaming media server which currently supports Ogg (Vorbis and Theora), Opus, WebM and MP3 audio streams."

isn't "Icecast" is audio only server? for radio stations and stuff...

saudet commented 8 years ago

Even if you don't get exceptions in Java, FFmpeg will output log information to the Java console. So could you please copy/paste that information as well?

rpgomes commented 8 years ago

Hi Saudet,

sorry for the late reply, i had other issues in hand.

I'm not having any output log from ffmpeg, do i nned to activate some option? I think the code will work if the server type was set to video/webm

@tomerhatav icecast supports webm, vp8 video

saudet commented 8 years ago

You should be. Try to call FFmpegLogCallback.set() though and see if that makes a difference.

rpgomes commented 8 years ago

FFmpegLogCallback.set(), does the magic, at least i learned something new today :)

Output #0, webm, to 'icecast://source:hackme@192.168.0.146:8001/test.webm':

Stream #0:0

: Video: vp8 (libvpx), yuv420p, 336x333, q=-1--1, 5 kb/s

,

20 tbn,

20 tbc

[libvpx @ 0041dda0] v1.4.0

Warning: [icecast @ 05af7000] Streaming WebM but appropriate content type NOT set!

Warning: [icecast @ 05af7000] Set it with -content_type video/webm

Warning: [swscaler @ 05af7f80] Warning: data is not aligned! This can lead to a speedloss

saudet commented 8 years ago

So, maybe calling setOption("content_type", "video/webm") would make it happy?

rpgomes commented 8 years ago

in the code I post I already doing that:

ff.setOption("content_type","video/webm");
saudet commented 8 years ago

I see, so we'll need to take a look at the code inside ffmpeg.c and do the same in FFmpegFrameRecorder.java.

saudet commented 5 years ago

FYI, if the ffmpeg program is sufficient, with commit https://github.com/bytedeco/javacpp-presets/commit/13ffffd191fa48d9d9d1d8a64e0c4d64c9da1134 it now gets bundled and can be used easily from Java.