1

I have a video recorded from a gopro which is split into 3 parts as the maximum filesize is reached after about 17 minutes and the gopro automatically splits it into multiple parts. I also have a camstudio recording of my desktop.

I need to concatenate the 3 gopro videos, and also overlay the camstudio recording as a picture in picture sort of view.

I.e it would end up as below where the 9 is the overlay and 1,2,3 are the gopro videos

999999999999999

111111222222333

I have to perform this on a regular basis (and multiple videos), so looking to write a batch file to generate the desired output, in a format playable by windows media player with no downloaded codecs. Reducing the filesize to about 1gb/45min at a maximum would be useful as well.

Can anyone suggest a way to do this in FFmpeg or libav? I can do the concatenation OR the overlay in FFmpeg but cant seem to get both. Maybe I just need to perform the concatenation first to a temporary file then use that as the input for the overlay?

Currently I am using the following 2 commands in ffmpeg to achieve this, but the filesize is huge and the quality isnt great, plus it takes a long time. Currently the output is at about 1gb for 7 minutes but my videos can be up to 45 minutes, so I really need to cut the file size down preferably to around 1-2gb for 45 minutes

ffmpeg -i concat:1.mp4|2.mp4|3.mp4" -an -q:v 9 -preset veryslow -crf 28 -vcodec wmv2 temp.wmv
ffmpeg -i temp.wmv -an -vf"movie=overlay.avi, scale=iw:ih; [in][small] overlay =0:0 [out]" -q:v 9 -preset veryslow -crf 28 -vcodec wmv2 output.wmv

The output from ffmpeg concat is:

>ffmpeg -i "concat:GOPR0133.mp4|GP010133.mp4|GP020133.mp4" -an -q:v 9 -vcodec wm
v2 70-70KMtemp.wmv
ffmpeg version N-61191-gea9399f Copyright (c) 2000-2014 the FFmpeg developers
  built on Mar  8 2014 22:01:33 with gcc 4.8.2 (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-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib
  libavutil      52. 66.101 / 52. 66.101
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 34.100 / 55. 34.100
  libavdevice    55. 11.100 / 55. 11.100
  libavfilter     4.  3.100 /  4.  3.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 027c29c0] Found duplicated MOOV Atom. Skipped it
    Last message repeated 1 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:GOPR0133.mp4|GP010133.mp4|GP0201
33.mp4':
  Metadata:
    creation_time   : 2014-04-17 09:47:21
    minor_version   : 0
    major_brand     : avc1
    compatible_brands: avc1isom
  Duration: 00:17:24.30, start: 0.000000, bitrate: 71321 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709
), 1280x720 [SAR 1:1 DAR 16:9], 30002 kb/s, 100 fps, 100 tbr, 180k tbn, 200 tbc
(default)
    Metadata:
      creation_time   : 2014-04-17 09:47:21
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 12
8 kb/s (default)
    Metadata:
      creation_time   : 2014-04-17 09:47:21
      handler_name    :  GoPro AAC
[swscaler @ 036088a0] deprecated pixel format used, make sure you did set range
correctly
Output #0, asf, to '70-70KMtemp.wmv':
  Metadata:
    compatible_brands: avc1isom
    minor_version   : 0
    major_brand     : avc1
    WM/EncodingSettings: Lavf55.34.100
    Stream #0:0(eng): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 1280x720 [SAR 1:
1 DAR 16:9], q=2-31, 200 kb/s, 1k tbn, 100 tbc (default)
    Metadata:
      creation_time   : 2014-04-17 09:47:21
      handler_name    :  GoPro AVC
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> wmv2)
Press [q] to stop, [?] for help
frame=    6 fps=0.0 q=9.0 size=      60kB time=00:00:00.06 bitrate=8195.6kbits/s
frame=   15 fps= 14 q=9.0 size=     132kB time=00:00:00.15 bitrate=7203.6kbits/s
frame=   25 fps= 16 q=9.0 size=     207kB time=00:00:00.25 bitrate=6779.7kbits/s
frame=   33 fps= 16 q=9.0 size=     235kB time=00:00:00.33 bitrate=5834.4kbits/s
frame=   39 fps= 15 q=9.0 size=     294kB time=00:00:00.39 bitrate=6183.9kbits/s
frame=   47 fps= 15 q=9.0 Lsize=     326kB time=00:00:00.47 bitrate=5677.5kbits/
s
etc....

Then the output I get when doing the overlay

>ffmpeg -i GOPR0131.mp4 -an -vf "movie=20140417_0930_55.avi, scale=iw:ih [small]
; [in][small] overlay =0:0 [out]" -q:v 9 -preset veryslow -crf 28 37-38KM.wmv
ffmpeg version N-61191-gea9399f Copyright (c) 2000-2014 the FFmpeg developers
  built on Mar  8 2014 22:01:33 with gcc 4.8.2 (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-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib
  libavutil      52. 66.101 / 52. 66.101
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 34.100 / 55. 34.100
  libavdevice    55. 11.100 / 55. 11.100
  libavfilter     4.  3.100 /  4.  3.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GOPR0131.mp4':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 2014-04-17 09:29:13
  Duration: 00:11:59.29, start: 0.000000, bitrate: 30160 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709
), 1280x720 [SAR 1:1 DAR 16:9], 30005 kb/s, 100 fps, 100 tbr, 180k tbn, 200 tbc
(default)
    Metadata:
      creation_time   : 2014-04-17 09:29:13
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 12
8 kb/s (default)
    Metadata:
      creation_time   : 2014-04-17 09:29:13
      handler_name    :  GoPro AAC
Codec AVOption preset (Set the encoding preset (cf. x264 --fullhelp)) specified
for output file #0 (37-38KM.wmv) has not been used for any stream. The most like
ly reason is either wrong type (e.g. a video option with no video streams) or th
at it is a private option of some encoder which was not actually used for any st
ream.
Codec AVOption crf (Select the quality for constant quality mode) specified for
output file #0 (37-38KM.wmv) has not been used for any stream. The most likely r
eason is either wrong type (e.g. a video option with no video streams) or that i
t is a private option of some encoder which was not actually used for any stream
.
[swscaler @ 0401a560] deprecated pixel format used, make sure you did set range
correctly
Output #0, asf, to '37-38KM.wmv':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    WM/EncodingSettings: Lavf55.34.100
    Stream #0:0(eng): Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 1
280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 1k tbn, 100 tbc (default)
    Metadata:
      creation_time   : 2014-04-17 09:29:13
      handler_name    :  GoPro AVC
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> msmpeg4)
Press [q] to stop, [?] for help
frame=    6 fps=0.0 q=9.0 size=      23kB time=00:00:00.06 bitrate=3075.9kbits/s
frame=   16 fps= 15 q=9.0 size=      57kB time=00:00:00.16 bitrate=2913.4kbits/s
frame=   25 fps= 16 q=9.0 size=      91kB time=00:00:00.25 bitrate=2991.0kbits/s
frame=   32 fps= 15 q=9.0 Lsize=     113kB time=00:00:00.32 bitrate=2898.9kbits/
s
etc...
user3550682
  • 13
  • 1
  • 4
  • Can you give us a bit more info about what codecs/format the GoPro and your desktop recordings have? Also, playing in WMP without additional codecs is tricky unless you run a recent version of Windows. Full backwards-compatibility with, say Windows XP, can only be achieved by selecting an inefficient codec. – slhck Apr 19 '14 at 07:49
  • Sure, the desktop recording is done by camstudio and is using camstudio lossless codec 1.5. The gopro camera records in MPEG4 (.mp4) files using h.264 compression. I can live without backward compatibility to XP, as long as it is able to be played in media player on windows 7 with nothing additional installed (company is strict on this) – user3550682 Apr 19 '14 at 08:42
  • Also just edited the original question to show what I am currently doing – user3550682 Apr 19 '14 at 08:52
  • Thanks! It'd be great if you could show the full command line output as well. That way we can see what's going on. – slhck Apr 19 '14 at 09:02
  • Sure I have tried to edit it into my question (sorry if its messy, am new to this) – user3550682 Apr 19 '14 at 09:26
  • If it helps the gopro is using the lowest setting (720p = 1280x720 pixels (16:9)) - but the video will be watched in media player so I dont know if its possible to lower the resolution to bring down the file size while still looking good quality on a computer monitor. – user3550682 Apr 19 '14 at 09:33

1 Answers1

3

You can use the setpts, scale, concat, overlay, and format filters. I'm going to assume all inputs are 1280x720 since the size of the file you want to overlay is currently unknown.

Example

ffmpeg -i gopro0.mp4 -i gopro1.mp4 -i gopro2.mp4 -i over.avi -filter_complex \
"[0:v]setpts=PTS-STARTPTS[v0]; \
 [1:v]setpts=PTS-STARTPTS[v1]; \
 [2:v]setpts=PTS-STARTPTS[v2]; \
 [3:v]setpts=PTS-STARTPTS,scale=iw/4:-2[fg]; \
 [v0][v1][v2]concat=n=3:v=1:a=1[bg][a]; \
 [bg][fg]overlay=W-w-10:10,format=yuv420p[v]"
-map "[v]" -map "[a]" output.mp4

What each filter does

  • setpts makes the timestamps start at 0 which is recommended by concat and overlay.

  • scale will make over.avi a smaller frame size.

  • concat will concatenate each input.

  • overlay will place the scaled over.avi in the top-right corner with a padding of 10 pixels. Refer to the overlay documentation for additional options regarding inputs that have different durations (shortest and eof_action specifically).

  • format will ensure that your output uses a chroma subsampling scheme that is compatible with all players (assuming you are using the encoder libx264 which is default for MP4 if it is supported by your ffmpeg build).

Notes

  • If you want the output to have a smaller frame size, then add another scale:

    [bg][fg]overlay=W-w-10:10,scale=640:-2,format=yuv420p[v]"
    
  • I was unable to test these examples at this time, so leave a comment if anything does not work as expected and I will look at it on Sunday unless others provide additional help.

  • File types supported by Windows Media Center (Windows 7) is next to worthless since it does not provide specifics, so you may have to experiment, or others that are more familiar with Windows 7 can edit this answer.

llogan
  • 57,139
  • 15
  • 118
  • 145
  • Thats great thankyou works perfectly. The output is a much better quality, and smaller file size, and the process runs much faster than what I had managed on my own. – user3550682 Apr 20 '14 at 01:58