0

I have few mp4 video files that i wants to merge them.

I am using this commands to convert .mp4 to .ts and then merge them together. referance

ffmpeg -i part1.mp4  -bsf:v h264_mp4toannexb -f mpegts -y part1.ts # executes successfully

ffmpeg -i part2.mp4  -bsf:v h264_mp4toannexb -f mpegts -y part2.ts # executes successfully

ffmpeg -i "concat:part1.ts|part2.ts"  -bsf:a aac_adtstoasc -y full.mp4 # Error

Error:(but execution still continues) input packets too small error applying bitstream filters to an output packet for stream #0:1 past duration 0.999992 too large

it take more than hours to do merging of 2 files which it doesn't take with other video files ( i think there is problem with part2.mp4 but don't know how to solve it )

Here is video info

part1.mp4

 C:\Users\JAGZ\Desktop\vid>ffmpeg -i part1.mp4
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-b
zlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcac
a --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --e
nable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enab
le-zlib
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'part1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.104
  Duration: 00:00:07.21, start: 0.000000, bitrate: 2355 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt470bg), 720x576 [SAR 128:117 DAR 160:117], 2034 kb/s, 25 fps, 2
5 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
At least one output file must be specified

part2.mp4

C:\Users\JAGZ\Desktop\vid>ffmpeg -i part2.mp4
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-b
zlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcac
a --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --e
nable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enab
le-zlib
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 003075c0] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'part2.mp4':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2016-03-07T16:01:20.000000Z
    title           : 2006/14 Coke Crisis
    media_type      : 9
    network         : A/V Input
    date            : 2016-03-07
    iTunMOVI        : <?xml version="1.0" encoding="UTF-8"?>
                    : <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
                    : <plist version="1.0">
                    : <dict>
                    :   <key>asset-info</key>
                    :   <dict>
                    :           <key>file-size</key>
                    :           <integer>837215671</integer>
                    :           <key>flavor</key>
                    :           <string>4:640x480</string>
                    :           <key>high-definition</key>
                    :           <false/>
                    :           <key>screen-format</key>
                    :           <string>standard</string>
                    :           <key>soundtrack</key>
                    :           <string>LC</string>
                    :   </dict>
                    :   <key>cast</key>
                    :   <array/>
                    :   <key>codirectors</key>
                    :   <array/>
                    :   <key>copy-warning</key>
                    :   <string></string>
                    :   <key>directors</key>
                    :   <array/>
                    :   <key>producers</key>
                    :   <array/>
                    :   <key>screenwriters</key>
                    :   <array/>
                    :   <key>studio</key>
                    :   <string></string>
                    : </dict>
                    : </plist>
                    :
  Duration: 01:09:03.08, start: 0.000000, bitrate: 1616 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv), 640x480 [SAR 1:1 DAR 4:3], 1485 kb/s, 24.99 fps, 25 tbr, 25k
 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-03-07T16:01:20.000000Z
      handler_name    : ?Apple Video Media Handler
      encoder         : H.264/AVC
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2016-03-07T16:01:20.000000Z
      handler_name    : ?Apple Sound Media Handler
    Stream #0:2: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 512x748 [SAR 72:72 DAR 128:187], 90k tbr, 90k tbn, 90k tbc
At least one output file must be specified

can someone suggest me what change do i make in command to merge this videos ?

JAGGADAKU
  • 11
  • 2
  • 4
  • Please provide the full, uncut command line output from your first three commands. – slhck May 31 '17 at 12:23
  • @slhck updated details with full output – JAGGADAKU May 31 '17 at 12:34
  • You cannot join these two files without reencoding. They have different H264 profiles and different resolution. – Daniel B May 31 '17 at 12:38
  • @DanielB It's technically possible to join them but the output will not look as expected or may not play. – slhck May 31 '17 at 12:42
  • @JAGGADAKU I asked about the output of the three commands you were running, not the output of `ffmpeg -i part1.mp4`. (You need to disable `-v quiet`.) – slhck May 31 '17 at 12:43
  • @DanielB i am able to convert to .ts and then merge (both to .ts) but when i tries to convert it back to mp4 it shows many errors – JAGGADAKU May 31 '17 at 12:46

1 Answers1

2

There is a problem with your input: Your input videos have different frame dimensions (720×576 vs. 640×480). In such a case you cannot just concatenate the raw bitstreams. Well, you can, but then the playback will not support switching the resolution – it will just show at the resolution of your first input video, or may crash some players.

Instead, you should probably decode the videos and bring them to a common format (frame dimensions, frame rate, color space, pixel aspect ratio, …), then re-encode them.

The above can be achieved with the concat filter, but first, you have to scale/pad either one of those inputs, e.g. by upscaling part2.mp4 to 720×576 (with padding):

ffmpeg -i part1.mp4 -i part2.mp4 -filter_complex "\
[0:v]setsar=1[0v]; \
[1:v]scale=720:576:force_original_aspect_ratio=decrease,setsar=1,\
     pad=720:576:(ow-iw)/2:(oh-ih)/2[1v]; \
[0v][0:a][1v][1:a]concat=n=2:v=1:a=1[outv][outa] \
" -map "[outv]" -map "[outa]" \
-c:v libx264 -crf 23 \
output.mp4

See this post and the FFmpeg Wiki for more info on scaling and concatenating. And read the H.264 encoding guide on how to set the quality for the output.

slhck
  • 223,558
  • 70
  • 607
  • 592
  • Thank you for response......but above command says `No such filter: 'force_original_aspect_ratio' Error initializing complex filters. Invalid argument` i am running windows – JAGGADAKU May 31 '17 at 14:03
  • Sorry, there was a typo, please try again. – slhck May 31 '17 at 14:18
  • `[Parsed_concat_2 @ 04930620] Input link in1:v0 parameters (size 720x576, SAR 1:1) do not match the corresponding output link in0:v0 paramet ers (720x576, SAR 128:117) [Parsed_concat_2 @ 04930620] Failed to configure output pad on Parsed_concat_2 Error configuring complex filters. Invalid argument` Now this is problem........i am sorry but i don't have any idea about how this filter complex works – JAGGADAKU May 31 '17 at 14:42
  • True, the pixel aspect ratios are different for the two files as well, so you need to change that to 1 as well. The complex filter is a little complicated to understand, yeah. Providing your input files and the requested output would (have) help(ed). – slhck May 31 '17 at 14:58
  • another question. I already have libx264 enabled on my ffmpeg then why it says that `[NULL @ 047eb220] Unable to find a suitable output format for 'libx264' libx264: Invalid argument` – JAGGADAKU May 31 '17 at 15:52
  • Then you're using a wrong command line option. If you want x264 as codec, you need `-c:v libx264`. – slhck May 31 '17 at 19:47