FFmpeg:连接多个视频,一些有音频,一些没有

时间:2017-09-05 14:26:51

标签: audio video ffmpeg

我试图连接5个视频,其中第一个和最后一个没有音轨。我尝试了以下命令:

    Stream specifier ':a:0' in filtergraph description [0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] [3:v:0] [3:a:0] [4:v:0] [4:a:0] concat=n=5:v=1:a=1 [v] [a] matches no streams.

我收到输出错误:

   Stream specifier ':v:0' in filtergraph description [0:v:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] [3:v:0] [3:a:0] [4:v:0] [4:a:0] concat=n=5:v=1:a=1 [v] [a] matches no streams.

我知道第一个和最后一个视频没有音频,但我不知道如何编写语句来忽略这些视频中的音轨。我试过删除[0:a:0],但这只会引发另一个错误:

@Service
public class EmailServiceImpl implements EmailService {
    private static final String EMAIL_SIMPLE_TEMPLATE_NAME = "html/html";
@Value("${email.user.register.body}")
private String USER_REGISTER_MESSAGE_BODY;

@Value("${email.user.register.subject}")
private String USER_REGISTER_MESSAGE_SUBJECT;

@Value("${mailSender.address}")
private String SENDER_EMAIL_ADDRESS;

@Autowired
private JavaMailSender mailSender;

@Autowired
private TemplateEngine templateEngine;

@Override
public void sendEmail(MimeMessagePreparator preparator) {
    mailSender.send(preparator);
}

@Async
@Override
public void sendUserRegisterEmail(String receiver, String receiverEmailAddress){
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setSubject(USER_REGISTER_MESSAGE_SUBJECT);
            message.setTo(receiverEmailAddress);
            message.setFrom(SENDER_EMAIL_ADDRESS);
            message.setText(String.format(USER_REGISTER_MESSAGE_BODY, receiver));
        }
    };
    sendEmail(preparator);
}

public void sendMailWithInline(
        final String recipientName, final String recipientEmail, final String imageResourceName,
        final byte[] imageBytes, final String imageContentType, final Locale locale)
        throws MessagingException {

    // Prepare the evaluation context
    final Context ctx = new Context(locale);
    ctx.setVariable("name", recipientName);
    ctx.setVariable("subscriptionDate", new Date());
    ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
    ctx.setVariable("imageResourceName", imageResourceName); // so that we can reference it from HTML

    // Prepare message using a Spring helper
    final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
    final MimeMessageHelper message =
            new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart
    message.setSubject("Example HTML email with inline image");
    message.setFrom("adbuylk@gmail.com");
    message.setTo(recipientEmail);

    // Create the HTML body using Thymeleaf
    final String htmlContent = this.templateEngine.process(EMAIL_SIMPLE_TEMPLATE_NAME, ctx);
    message.setText(htmlContent, true); // true = isHtml

    // Add the inline image, referenced from the HTML code as "cid:${imageResourceName}"
    final InputStreamSource imageSource = new ByteArrayResource(imageBytes);
    message.addInline(imageResourceName, imageSource, imageContentType);

    // Send mail
    this.mailSender.send(mimeMessage);

}

它没有意义,我有点失落。

1 个答案:

答案 0 :(得分:5)

如果您同时连接音频,则所有视频输入必须与音频配对。如果文件本身没有任何音频,则可以使用虚拟静音音轨。

使用

ffmpeg -i 1-copyright/copyright2018640x480.mp4 -i 2-openingtitle/EOTIntroFINAL640x480.mp4
       -i 3-videos/yelling.mp4 -i 4-endtitle/EOTOutroFINAL640x480.mp4
       -i 5-learnabout/Niambi640.mp4 -f lavfi -t 0.1 -i anullsrc -filter_complex
       "[0:v:0][5:a][1:v:0][1:a:0][2:v:0][2:a:0][3:v:0][3:a:0][4:v:0][5:a] concat=n=5:v=1:a=1 [v][a]"
       -map "[v]" -map "[a]" output_video.mp4