I am trying to use mux h264 and aac created using MediaCodec using FFMPEG, and also use FMPMPEG RTMP support to send to youtube. I created two pipes and I am writing from java (android) via WriteableByteChannels. I can send one tube just fine (accepting a zero sound) as follows:
./ffmpeg -f lavfi -i aevalsrc=0 -i "files/camera-test.h264" -acodec aac -vcodec copy -bufsize 512k -f flv "rtmp://a.rtmp.youtube.com/live2/XXXX"
YouTube streaming works fine (but I have no sound). Using two pipes, this is my command:
./ffmpeg \ -i "files/camera-test.h264" \ -i "files/audio-test.aac" \ -vcodec copy \ -acodec copy \ -map 0:v:0 -map 1:a:0 \ -f flv "rtmp://a.rtmp.youtube.com/live2/XXXX""
Pipes are created using mkfifo and opened from java as follows:
pipeWriterVideo = Channels.newChannel(new FileOutputStream(outputFileVideo.toString()));
The execution order (now at the testing stage) is creating files, launching ffmpeg (through the adb shell), and then starting a recording that opens channels. ffmpeg will immediately open the h264 stream and then wait, as it reads the first open channel from the channel (for video). When it comes to trying to open the sound in the same way, it fails because ffmpeg did not actually start reading from the pipe. I can open the second window of the terminal and the cat of the audio file, and my application spits out, which I hope is aac encoded, but ffmpeg does not work, usually just sits there, waiting. Here is the detailed output:
ffmpeg version N-78385-g855d9d2 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --prefix=/home/dev/svn/android-ffmpeg-with-rtmp/src/ffmpeg/android/arm --enable-shared --disable-static --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-symver --cross-prefix=/home/dev/dev/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi- --target-os=linux --arch=arm --enable-cross-compile --enable-librtmp --enable-pic --enable-decoder=h264 --sysroot=/home/dev/dev/android-ndk-r10e/platforms/android-19/arch-arm --extra-cflags='-Os -fpic -marm' --extra-ldflags='-L/home/dev/svn/android-ffmpeg-with-rtmp/src/openssl-android/libs/armeabi ' --extra-ldexeflags=-pie --pkg-config=/usr/bin/pkg-config libavutil 55. 17.100 / 55. 17.100 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 matched as AVOption 'debug' with argument 'verbose'. Trailing options were found on the commandline. Finished splitting the commandline. Parsing a group of options: global . Applying option async (audio sync method) with argument 1. Successfully parsed a group of options. Parsing a group of options: input file files/camera-test.h264. Successfully parsed a group of options. Opening an input file: files/camera-test.h264. [file @ 0xb503b100] Setting default whitelist 'file'
I think if I could just get ffmpeg to start listening to both pipes, the rest would work!
Thank you for your time.
EDIT: I made progress by decoupling the connection of the audio channels and coding, but now, once the video stream has been transmitted, these are errors on the audio. I created a separate stream to create a WriteableByteChannel for audio, and it is never transmitted with the creation of a FileOutputStream.
matched as AVOption 'debug' with argument 'verbose'. Trailing options were found on the commandline. Finished splitting the commandline. Parsing a group of options: global . Successfully parsed a group of options. Parsing a group of options: input file files/camera-test.h264. Successfully parsed a group of options. Opening an input file: files/camera-test.h264. [file @ 0xb503b100] Setting default whitelist 'file' [h264 @ 0xb503c400] Format h264 probed with size=2048 and score=51 [h264 @ 0xb503c400] Before avformat_find_stream_info() pos: 0 bytes read:15719 seeks:0 [h264 @ 0xb5027400] Current profile doesn't provide more RBSP data in PPS, skipping [h264 @ 0xb503c400] max_analyze_duration 5000000 reached at 5000000 microseconds st:0 [h264 @ 0xb503c400] After avformat_find_stream_info() pos: 545242 bytes read:546928 seeks:0 frames:127 Input #0, h264, from 'files/camera-test.h264': Duration: N/A, bitrate: N/A Stream #0:0, 127, 1/1200000: Video: h264 (Baseline), 1 reference frame, yuv420p(left), 854x480 (864x480), 1/50, 25 fps, 25 tbr, 1200k tbn, 50 tbc Successfully opened the file. Parsing a group of options: input file files/audio-test.aac. Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy. Successfully parsed a group of options. Opening an input file: files/audio-test.aac. Unknown decoder 'copy' [AVIOContext @ 0xb5054020] Statistics: 546928 bytes read, 0 seeks
Here I try to open the sound channel.
new Thread(){ public void run(){ Log.d("Audio", "pre thread"); FileOutputStream fs = null; try { fs = new FileOutputStream("/data/data/android.com.android.grafika/files/audio-test.aac"); } catch (FileNotFoundException e) { e.printStackTrace(); } Log.d("Audio", "made fileoutputstream");
Thanks.