Friday, August 1, 2014

Place two (remote)videos side by side

I wanted to achieve something similar to this (at 30 seconds) while pulling from 2 video sources and 1 audio source

https://www.youtube.com/watch?v=0AJWmt5A62Y

Source:
http://stackoverflow.com/questions/9293265/ffmpeg-2-videos-transcoded-and-side-by-side-in-1-frame

video filter:
http://www.oodlestechnologies.com/blogs/PICTURE-IN-PICTURE-effect-using-FFMPEG

Important:

The overlay docs states:

  Be aware that frames are taken from each input video in timestamp
  order, hence, if their initial timestamps differ, it is a a good
  idea to pass the two inputs through a setpts=PTS-STARTPTS filter to
  have them begin in the same zero timestamp, as it does the example
  for the movie filter. 
 
 
http://ffmpeg.org/pipermail/ffmpeg-user/2013-June/015662.html

Half size:

ffmpeg -i http://192.168.1.123:8099/right.flv -i http://192.168.1.123:8099/left.flv
-filter_complex "[0:v]setpts=PTS-STARTPTS, scale=iw/2:ih/2, pad=2*iw:ih [left]; [1:v]setpts=PTS-STARTPTS, scale=iw/2:ih/2 [right]; [left][right] overlay=main_w/2:0" -i http://192.168.1.123:8099/audio.opus -c:v libx264 -c:a libfaac -tune zerolatency -preset ultrafast -crf 26 -maxrate 1000k -bufsize 1600k -f flv rtmp://107.170.84.207:1935/xorg/movie -y out$(date).mp4
True size:
ffmpeg -i http://192.168.1.14:8090/right.flv -i http://192.168.1.14:8090/left.flv
-filter_complex "[0:v]setpts=PTS-STARTPTS, scale=iw:ih, pad=2*iw:ih [left]; [1:v]setpts=PTS-STARTPTS, scale=iw:ih [right]; [left][right] overlay=main_w/2:0" -i http://192.168.1.14:8090/audio.mp3 -vcodec h264 -acodec libvo_aacenc -tune zerolatency -preset ultrafast -y out.mp4

Buffers kind-of-break the audio/video timing.
The videos start on a keyframe (ffserver's setting) so they usually start with up to a few seconds of delay.
It also takes a few seconds to start the 'join' process because it needs to wait for 2 keyframes

ATTENTION: The FPS will be determined by the first video setting, for example, -r 25 -vsync 1 will duplicate frames until 25 FPS is reached but each of the videos' framerate will be from the first video (which means that if the second video has more fps than the first one, it'll drop frames to match


Watermark:
http://stackoverflow.com/questions/10934420/ffmpeg-how-to-scale-a-video-then-apply-a-watermark
 
 
ffserver.conf

audio (https://ffmpeg.org/sample.html)

# MP3 audio
<Stream test.mp3>
Feed feed1.ffm
Format mp2
AudioCodec mp3
AudioBitRate 64
AudioChannels 1
AudioSampleRate 44100
NoVideo
</Stream>
 

rtmp push delay:
http://superuser.com/questions/769721/how-to-determine-stream-delay-in-ffmpeg