1

I am trying to add xfade filter and the command is working but audio of second video is missing in output video.

command is -

ffmpeg -i 1.mp4 -i 1.mp4  -filter_complex "[0:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];
[v0][v1]xfade=transition=pixelize:duration=1:offset=7,format=yuv420p" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus -deadline good -cpu-used 8 output.webm

the full log is below-

ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc - 
-disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid -- 
enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable- 
libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype 
--enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb -- 
enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-
sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:09.12, start: 0.000000, bitrate: 702 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 474x360, 568 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:08.75, start: 0.000000, bitrate: 2546 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360, 2416 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 (h264) -> scale (graph 0)
  Stream #1:0 (h264) -> scale (graph 0)
  format (graph 0) -> Stream #0:0 (libvpx-vp9)
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> opus (libopus))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x561afcf3a280] v1.7.0
Output #0, webm, to 'output.webm':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 480x360 [SAR 1:1 DAR 4:3], q=-1--1, 30 fps, 1k tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc58.91.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(und): Audio: opus (libopus), 48000 Hz, stereo, flt, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 libopus
frame=   87 fps=0.0 q=0.0 size=       1kB time=00:00:03.19 bitrate=   2.1kbits/sframe=  157 fps=156 q=0.0 size=     171kB time=00:00:05.51 bitrate= 254.3kbits/sframe=  227 fps=150 q=0.0 size=     171kB time=00:00:07.85 bitrate= 178.5kbits/sframe=  265 fps=131 q=0.0 size=     171kB time=00:00:08.31 bitrate= 168.7kbits/sframe=  303 fps=120 q=0.0 size=     256kB time=00:00:09.30 bitrate= 225.5kbits/sframe=  341 fps=113 q=0.0 size=     256kB time=00:00:10.56 bitrate= 198.4kbits/sframe=  379 fps=107 q=0.0 size=     256kB time=00:00:11.83 bitrate= 177.2kbits/sframe=  416 fps=103 q=0.0 size=     256kB time=00:00:13.06 bitrate= 160.5kbits/sframe=  454 fps=100 q=0.0 size=     256kB time=00:00:14.33 bitrate= 146.3kbits/sframe=  472 fps= 93 q=0.0 Lsize=    1168kB time=00:00:15.73 bitrate= 608.2kbits/s speed=3.09x    
video:1036kB audio:125kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.629681%

when using online url which has no audio getting this error- getting this error-

    ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://player.vimeo.com/external/183300180.sd.mp4?s=8d9b1561f39df586af49fe5ab105f57f5873854b&profile_id=164':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-09-19T12:39:02.000000Z
  Duration: 00:00:10.00, start: 0.000000, bitrate: 489 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt470bg/smpte170m/bt470bg), 640x360 [SAR 1:1 DAR 16:9], 486 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2016-09-19T12:39:02.000000Z
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://player.vimeo.com/external/166335878.sd.mp4?s=828bf6e8594fab383d7ee6bac40d3f247cc40af9&profile_id=164':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-05-12T09:34:11.000000Z
  Duration: 00:00:10.01, start: 0.000000, bitrate: 479 kb/s
    Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt470bg/smpte170m/bt470bg), 474x360 [SAR 1:1 DAR 79:60], 345 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2016-05-12T09:34:11.000000Z
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-05-12T09:34:11.000000Z
      handler_name    : L-SMASH Audio Handler
Stream specifier ':a' in filtergraph description [0:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=8,format=yuv420p;[0:a][1:a]acrossfade=d=0 matches no streams.
JohnTerry
  • 57
  • 1
  • 7

1 Answers1

0

You didn't tell ffmpeg what to do with the audio so it just picked the audio from the first input (see stream selection).

Because you are using xfade you probably want to use acrossfade as shown in Merging multiple video files with ffmpeg and xfade filter:

ffmpeg -i 1.mp4 -i 1.mp4 -filter_complex "[0:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=7,format=yuv420p;[0:a][1:a]acrossfade=d=1" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus -deadline good -cpu-used 8 output.webm

For input with no audio one method is to add the adelay filter:

ffmpeg -i noaudio -i input1 -filter_complex "[0:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=8,format=yuv420p;[1:a]adelay=8s:all=1" output

Other methods include using anullsrc + concat, or apad (if noaudio is not the first input).

llogan
  • 121,796
  • 28
  • 232
  • 243
  • This command worked but now I am getting error while passing video which has no audio. I have posted the log on post. is it possible that this command works for both cases ? – JohnTerry May 27 '21 at 21:38
  • this method will always add delay even if the first video has sound or not. so, I guess I have to use conditional statements to cover all the scenarios. It was very useful to me. Thanks alot. @llogan – JohnTerry May 27 '21 at 22:16
  • @JohnTerry Yes, you will need conditional statements. There is no universal command which works for all of these cases. – llogan May 27 '21 at 22:18
  • Is there any way to check if video has audio or not using ffmpeg only. or should I open a new question ? – JohnTerry May 28 '21 at 19:55
  • @JohnTerry ffmpeg is not meant to be machine parsed, so it's not the right tool for the job. I strongly recommend ffprobe. See [Using ffprobe to check if file is audio or video only](https://stackoverflow.com/a/32289198/) for some examples. But ffmpeg is fine for casual use or just reading the console output yourself. – llogan May 28 '21 at 20:04
  • I see. I will check it out for sure. @llogan – JohnTerry May 28 '21 at 20:09
  • I have tried the commands and they worked perfectly as i needed. but i tried them with ffmpeg version 4.2.2 . now the problem is I am using ffmpeg version n4.3.1 which does not have ffprobe with it. I tried pip install ffprobe but it did not work. so is there way to add ffprobe now? – JohnTerry May 28 '21 at 22:11
  • @JohnTerry I don't know anything about pip. What is your OS? – llogan May 28 '21 at 22:20
  • I use Ubuntu 20.04.2 LTS . pip is python package-management system i tried it with virtual environment. – JohnTerry May 28 '21 at 22:23
  • @JohnTerry ffprobe is included in the ffmpeg package in ubuntu repo and is installed to `/usr/bin/ffprobe` – llogan May 28 '21 at 22:26
  • It was giving me error but then i tried it with `ffmpeg.ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 1.mp4` and it worked. Thanks again @llogan – JohnTerry May 28 '21 at 22:40