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

Publish video stream to RTMP server #136

Closed
zouyongdang opened this issue Apr 28, 2015 · 13 comments
Closed

Publish video stream to RTMP server #136

zouyongdang opened this issue Apr 28, 2015 · 13 comments
Labels

Comments

@zouyongdang
Copy link

Hi Samuel. I'm using your library and RecordActivity on Android and it works perfectly for recording video to local mp4 file. But I could not get it work for publishing the video stream to RTMP server. Is there anything else I should do except for changing the ffmpeg_link to a rtmp url?
I tried some other examples like this one and this one, and some others, but all of them are outdated since the upgrading of the JavaCV. Would you give me some tips?
I think the url I used is fine since I could publish video stream with the url through ffmpeg command line.

@Hey-Jobs
Copy link

I hava change the ffmpeg_link to a rtmp url,and success...but when i stop and start,app breakdowned
you'd put a rtmp url, let us try...

@saudet
Copy link
Member

saudet commented Apr 29, 2015

If it works on the command line with ffmpeg, you should try to use the same settings with FFmpegFrameRecorder. The culprit is usually the format. What happens if you try the "mp4" format instead of "flv", for example?

@zouyongdang
Copy link
Author

@saudet What do you mean by culprit? I checked the output of ffmpeg command line and did not see it. Anyway, this is the command I use in my terminal
ffmpeg -re -i ~/Downloads/417-foundation.m4v -acodec copy -vcodec copy -f flv rtmp_url.
417-foundation.m4v is just a video I downloaded to my disk. And here is the output:

ffmpeg version 2.4.3-tessus Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov  3 2014 23:01:10 with Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
  configuration: --cc=/usr/bin/clang --prefix=/Users/tessus/data/ext/ffmpeg/sw --as=yasm --extra-version=tessus --disable-shared --enable-static --disable-ffplay --enable-gpl --enable-pthreads --enable-postproc --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-libsoxr --enable-libwavpack --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx --enable-libgsm --enable-libopus --enable-libmodplug --enable-fontconfig --enable-libfreetype --enable-libass --enable-libbluray --enable-filters --disable-indev=qtkit --disable-indev=x11grab_xcb --enable-runtime-cpudetect
  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.100 /  5.  1.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/Chris/Downloads/417-foundation.m4v':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2013-06-17 04:22:22
    encoder         : HandBrake 0.9.5 2011010300
  Duration: 00:11:06.11, start: 0.000000, bitrate: 233 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x400, 132 kb/s, 9.86 fps, 25 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2013-06-17 04:22:22
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 98 kb/s (default)
    Metadata:
      creation_time   : 2013-06-17 04:22:22
Output #0, flv, to 'rtmp_url':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf56.4.101
    Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 640x400, q=2-31, 132 kb/s, 9.86 fps, 1k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2013-06-17 04:22:22
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, mono, 98 kb/s (default)
    Metadata:
      creation_time   : 2013-06-17 04:22:22
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help

Wish this would help.

@zouyongdang
Copy link
Author

@cranehovers I only have one url for testing and I'm not sure what will happen if several people push to the same url at the same time.

@saudet
Copy link
Member

saudet commented Apr 29, 2015

So it looks like your server needs H264 and AAC, and everything should work if you add these two lines before recorder.start():

        recorder.setFormat("flv");
        recorder.setVideoCodec(AV_CODEC_ID_H264);
        recorder.setAudioCodec(AV_CODEC_ID_AAC);

@saudet saudet closed this as completed Apr 29, 2015
@Hey-Jobs
Copy link

while add"recorder.setVideoCodec(AV_CODEC_ID_H264); " before recorder.start(),recorder.start() will breakout.

@zouyongdang
Copy link
Author

@saudet Tried that, still did not work. The url is "rtmp://pub.z1.glb.pili.qiniup.com/zhibodang/553e0ee9d409d2292f000038?key=5b4b103461a67053".
@cranehovers You are welcomed to have a try.
You can use ffplay 'rtmp://live.z1.glb.pili.qiniucdn.com/zhibodang/553e0ee9d409d2292f000038 live=1' to play the corresponding video stream.
Thank you guys in advance.

@Hey-Jobs
Copy link

That may be the transcoding fails,I tried that,The transcoding performance is very low.
then,you‘ld add like this:

    recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
    recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

@saudet
Copy link
Member

saudet commented Apr 30, 2015

Could you check the error message returned by FFmpeg on the console? You'd have to do it outside Android...

@zouyongdang
Copy link
Author

It maybe a little late, but for anyone who sees this, I found that I have to change the value of RECORD_LENGTH from 10 to 0, otherwise the recorder.record method will never get called in the onPreviewFrame method.

@zouyongdang
Copy link
Author

@saudet It seems in the terminal, it works quite fine. There is no error message.

@saudet
Copy link
Member

saudet commented May 30, 2015

Good to know it's working now. Thanks for letting us know what the problem was!

@saudet
Copy link
Member

saudet commented Mar 24, 2019

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

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

No branches or pull requests

3 participants