-1

In my case I have 3 .webm files the first one is audio only, the second one is video only, the third one is audio and video.

I want to concatenate them into a single file which shows black screen for audio only parts, video for video only parts, and plays both for the parts that have audio and video.

The video codec is VP8, the audio codec is Opus.

concat.txt contains the entries for the three files

I am using the following command to concatenate them.

ffmpeg -f concat -safe 0 -i ./concat.txt -c copy -y output.webm

This command creates the output file, when I play it it only plays the first audio only part and crashes when it reaches the video only part.

I also tried to add a dummy picture to the audio only files but the command fails when I try to concatenate.

Any and all help/critique is welcome.

Thank you!

More Info On the Input files

Input #0, matroska,webm, from 'original1.webm':
  Metadata:
    title           : -
    ENCODER         : Lavf58.45.100
  Duration: 00:00:09.99, start: 0.000000, bitrate: 34 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:00:09.990000000
Input #1, matroska,webm, from 'original2.webm':
  Metadata:
    title           : -
    ENCODER         : Lavf58.45.100
  Duration: 00:00:09.75, start: 0.000000, bitrate: 954 kb/s
    Stream #1:0: Video: vp8, yuv420p(tv, bt470bg/unknown/unknown, progressive), 1680x1050, SAR 1:1 DAR 8:5, 1k tbr, 1k tbn, 1k tbc (default)
    Metadata:
      DURATION        : 00:00:09.754000000
Input #2, matroska,webm, from 'original3.webm':
  Metadata:
    title           : -
    ENCODER         : Lavf58.45.100
  Duration: 00:00:10.02, start: 0.000000, bitrate: 912 kb/s
    Stream #2:0: Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:00:10.023000000
    Stream #2:1: Video: vp8, yuv420p(tv, bt470bg/unknown/unknown, progressive), 1680x1050, SAR 1:1 DAR 8:5, 1k tbr, 1k tbn, 1k tbc (default)
    Metadata:
      DURATION        : 00:00:09.965000000
Salar Khan
  • 457
  • 3
  • 13
  • 1
    Need to see info about each individual input to be able to give you an answer you can copy and paste. Info can be seen with `ffmpeg -i input1.webm -i input2.webm -i input3.webm` – llogan Feb 25 '21 at 19:31
  • @llogan I've added the info to the question. – Salar Khan Feb 26 '21 at 00:17

1 Answers1

1

All files to be concatenated must have the same attributes and stream order.

  1. Add black video to audio only file:

    ffmpeg -i audio.webm -f lavfi -i color=s=1680x1050 -r 1000 -map 0 -map 1 -c:a copy -c:v libvpx -shortest output1.webm
    
  2. Add silent audio to video only file:

    ffmpeg -f lavfi -i anullsrc=r=48000:cl=stereo -i video.webm -map 0 -map 1 -c:a libopus -c:v copy -shortest output2.webm
    
  3. Make input.txt with the following contents:

    file 'output1.webm'
    file 'output2.webm'
    file 'original3.webm'
    
  4. Concatenate with the concat demuxer:

    ffmpeg -f concat -safe 0 -i concat.txt -c copy output.webm
    
llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thanks allot @llogan. I am going to try this out, any specific reason for -r 1000 isn't that going to set the frame rate to 1000 fps?? I might be wrong. Also, later when we're running the concat command, is there any way to rescale the input videos simultaneously, for scenarios when resolutions are different or unknown?? Thank you so much! – Salar Khan Feb 26 '21 at 15:01
  • 1
    @LennyLinus Yes, `-r` is for matching the frame rate of your other video, but it's not necessary in this case as the timebase should be the same. Rescaling requires encoding, and if you need to rescale all videos then you should just use the concat filter instead as shown in [How to concatenate videos in ffmpeg with different attributes?](https://stackoverflow.com/a/57367243/). If you just want to make the color filter automatically scale to the size of the main video then see the scale2ref filter. – llogan Feb 26 '21 at 18:33
  • Thanks allot @llogan. This worked perfectly! – Salar Khan Feb 26 '21 at 21:47