0

I'm using the FFmpeg library in Android.

I'm able to generate a .ts file which i can play later using VLC player. But now i want my app to overlay a .png image over the whole video.

The .ts file i want to overlay an image in is called "out.ts". The name might seem confusing, but it is called that way because it is the output of my camera.

This is the line i'm using:

ffmpeg -i /storage/emulated/0/out.ts -i /storage/emulated/0/mustache.png -filter_complex "overlay=10:10" /storage/emulated/0/newout.ts

This is the output i'm receiving:

    ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct  7 2014 15:08:46 with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
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, mpegts, from '/storage/emulated/0/out.ts':
Duration: 00:00:02.79, start: 0.000000, bitrate: 1118 kb/s
Program 1
Stream #0:0[0x1e1]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x480, 32 tbr, 90k tbn, 180k tbc
Input #1, png_pipe, from '/storage/emulated/0/mustache.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, ya8, 1848x580 [SAR 2835:2835 DAR 462:145], 25 tbr, 25 tbn, 25 tbc
[AVFilterGraph @ 0x2b411ec0] No such filter: '"overlay'
Error configuring filters.

Some explaination on how to tell ffmpeg where to position the .png image would be appreciated.

good-engineer
  • 250
  • 2
  • 8

1 Answers1

0

You can use something like this.

ffmpeg -i input_video -i input_image -filter_complex "[0:v][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[outv]" -c:v libx264 -map [outv] -map 0:a -c:a copy output_video

Here you can use filter_complex with map so that you can manipulate each input stream in the filter_complex and map the corresponding stream to the output file.0:v refers to the input video and 1:v refers to the input image. Above command will position the image to the centre of the video. Overlay will position the relevant source accordingly. -map [outv] will get the manipulated video stream and -map 0:a will get the original audio stream from the video and map it to the output.

If you need to change the image scale, then use scale against the input image in the filter_complex like [1:v]scale...

Hope this will help you!

Chamath
  • 2,016
  • 2
  • 21
  • 30
  • Works great! Had to remove "-map 0:a -c:a copy" because my .ts file doesn't have audio. The only problem is that it is taking way too long to overlay the image. Any ideas why this is happening? Here is some (maybe) useful info about my files: input.ts size = 600kb (6 seconds long). input.png size = 52kb. I'm using a Samsung Galaxy s4 mini. It takes 22 seconds to scale the image and to overlay it. Shouldn't it be done in like much less than that? Anyway, thanks a lot. You solved my original problem :D – good-engineer Jun 12 '15 at 15:36
  • Actually you can reduce the time taken for the process. But as a result, output video will be in low quality. `libx264` has a `-preset` tag which is associated with the duration of the process. [Here](https://trac.ffmpeg.org/wiki/Encode/H.264#a2.Chooseapreset) you can find more information about `preset`. In your case if you need to reduce the time, simply use `ultrafast`. Default value for `preset` is `medium`. – Chamath Jun 13 '15 at 12:36