FFmpeg how generate a sequence of videos with bash

2019-08-18 05:13发布

i try to write an .sh that read a folder create a playlist of mp4 files and then generate an only big video with a sequence of all videos find in the folder, and encode it for dash:

printf "file '%s'\n" ./*.mp4 > playlist.sh
ffmpeg -f concat -safe 0 -i playlist.sh -c copy concat.mp4

Till now i follow the demux concat official guido to ffmpeg website. Without result, also the following give me "more than 1000 frames duplicated between videos of the sequence"

ffmpeg -f concat -i playlist.sh -c:a aac -b:a 384k -ar 48000 -ac 2 -c:v libx264 -x264opts 'keyint=50:min-keyint=50:no-scenecut' -r 25 -b:v 2400k -maxrate 2400k -bufsize 1200k -vf "scale=-1:432 " out.mp4

Thanks a lot

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-18 05:55

Sry, cannot comment (yet)...

Your commands are correct, I could just concat some sample videos. Do you always get the mentioned error, or also something else? And is the video working, or no video is created? In most cases, the input video is incorrect. Wrong input format (not fitting to file extension) or worse like ending at wrong frame. Perhaps you can make the video available?

PS: Needed to add -safe 0 to the second command to avoid error [concat @ 0x7fbfd1000000] Unsafe file name './small.mp4'

Hint: Do not use file extension .sh for your list of video files. This extension is used for shell scripts, so it can be confusing. Just use .txt.

UPDATE @Massimo Vantaggio

We should not create new answers, but I cannot comment yours and I also don't know how to continue our discussion, so I edit my answer.

Your videos don't look very different. Can't see, what's wrong with the first one.

Perhaps you could use ffprobe -report input.mp4 to get more informations. Look for errors or warnings.

My assumption is still that the video was cut in a hard way (by conversion software), so keyframes are messed up or something else.

You can also try to first reencode your video with ffmpeg. After that, it should be complete compatible with ffmpeg ;)

Something like this:

ffmpeg -i small.mp4 -acodec aac -ab 192k -vcodec libx264 -vb 1024k -f mp4 output.mp4

Use -ab and -vb from your input video, or at least the bitrate from input. Quality will decrease a little bit and file size increase, but it should be okay.

查看更多
Fickle 薄情
3楼-- · 2019-08-18 05:55

i change the second video with one another and its work,

This is the info of the video that corrupt the process:

ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ghost.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

Below the info of the video that work, can you help me to understand the differences?

ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'contro.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 #0: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 #0: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

thanks a lot!

查看更多
登录 后发表回答