Massimo Vantaggio
Massimo Vantaggio

Reputation: 269

ffmpeg: concat and encode with one command

I have a script that automates encode and concat a series of input video files. I'm trying to get encode and concat in a single command.

At the moment it does not work causing immense empty pauses in the final video output.

I would like to get the result with concat demux instead of concat protocol because it is much harder to automate in a script

Do you know if it is possible to archive this result with concat demux? Thanks a lot!

Massimo

ENCODE / CONCAT 1080p

for f in ./*.mp4; do echo "file '$f'" >> list.txt; done

ffmpeg -f concat -safe 0 -y -i list.txt -i ../logo/logo.png -c:a aac -b:a 384k -ar 48000 -ac 2 -af aresample=async=1000 -c:v libx264 -x264opts keyint=50:min-keyint=50:no-scenecut -bf 0 -r 25 -b:v 4800k -maxrate 4800k -bufsize 3000k -profile:v main -crf 22 -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-10:10,scale=1920:1080,setsar=1" ../buffer/1080set.mp4

It seems to add long pause at low frame-rate:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb03f05e600] Auto-inserting h264_mp4toannexb bitstream filter

frame= 9745 fps= 13 q=27.0 size= 186368kB time=00:18:52.56 bitrate=1348.0kbits

frame= 9745 fps= 13 q=27.0 size= 186368kB time=00:18:56.57 bitrate=1343.3kbits/

frame= 9745 fps= 13 q=27.0 size= 186368kB time=00:19:00.65 bitrate=1338.5kbits/

frame= 9745 fps= 13 q=27.0 size= 186368kB time=00:19:02.29 bitrate=1336.5kbits/

More than 1000 frames duplicated

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2016-02-27T22:25:49.000000Z
    encoder         : HandBrake 0.10.5 2016021100
  Duration: 00:06:29.87, start: 0.000000, bitrate: 3447 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 768x432, 3282 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-27T22:25:49.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
    Metadata:
      creation_time   : 2016-02-27T22:25:49.000000Z
      handler_name    : Stereo

Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: M4V mp42isom
    creation_time   : 2016-02-27T18:52:37.000000Z
  Duration: 00:07:16.93, start: 0.000000, bitrate: 1184 kb/s
    Stream #1:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 991 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-02-27T18:52:37.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : AVC Coding
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2016-02-27T18:52:37.000000Z
      handler_name    : Mainconcept MP4 Sound Media Handler

Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-06-27T17:58:17.000000Z
  Duration: 00:05:05.05, start: 0.000000, bitrate: 2622 kb/s
    Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 2301 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-06-27T17:58:17.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2017-06-27T17:58:17.000000Z
      handler_name    : Alias Data Handler

Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '4.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-06-27T17:53:32.000000Z
  Duration: 00:06:47.36, start: 0.000000, bitrate: 3144 kb/s
    Stream #3:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 2819 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-06-27T17:53:32.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2017-06-27T17:53:32.000000Z
      handler_name    : Alias Data Handler

Upvotes: 1

Views: 4651

Answers (1)

llogan
llogan

Reputation: 133783

concat demxuer

The concat demuxer needs all inputs to have the same formats, number of streams, type of streams, order of streams (or use exact_stream_id), timebase, frame rate, audio sample rate, audio channel layout, and it is also recommended to have the same width and height.

In your case the timebase (tbn) of the first input is different than the rest. You can pre-process this input to conform it to the others:

ffmpeg -i 1.mp4 -c copy -video_track_timescale 25k 1_reset.mp4

Then run your command using the concat demuxer.

concat filter

Because you're re-encoding anyway it may be easier for you to use the concat filter. This allows you to conform each input using various filters then concate all in one command. There are several examples of such use on this site.

Upvotes: 1

Related Questions