在视频上添加水印的命令 [英] Command for putting watermark on video

查看:99
本文介绍了在视频上添加水印的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个视频上加水印,但FFmpeg命令无法执行,错误代码为3037.我运行相同的代码来修剪视频,并且视频被成功修剪,因此inputpathoutputpath没有任何问题我在Assets文件夹中也有ic_watermark.png.我尝试使用Drawable中的图像,但错误代码相同.

I tried to put watermark on one video but FFmpeg command won't execute and error code is 3037. I run the same code for trimming video and video is trimmed successfully so there is no issues with inputpath or outputpath also I have ic_watermark.png in assets folder. I tried with image from Drawable but same error code.

这是我尝试运行并在右上角添加水印的命令:

So here is the command which I tried to run and put watermark in right corner:

String[] cmd = new String[]{"-i", videoInputPath, "-i", imagePath, "-filter_complex", "overlay=main_w-overlay_w-5:main_h-overlay_h-5", videoOutPath };

这是整个方法:

private void executeFFmepg(String inputPath, String outputPath, String customCommand){
final Command command = videoKit.createCommand()
        .overwriteOutput()
        .inputPath(inputPath)
        .outputPath(outputPath)
        .customCommand(customCommand)
        .experimentalFlag()
        .build();
 new AsyncCommandExecutor(command, this).execute(); 
 }

我使用了一个基于FFmpeg的库: https://github.com/inFullMobile /videokit-ffmpeg-android 和说明说,这基本上是使用CLI参数调用FFmpeg main().

I used one library based on FFmpeg: https://github.com/inFullMobile/videokit-ffmpeg-android and description says that this is basically invoking FFmpeg main() with CLI arguments.

这是我从Log那里得到的:

ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (GCC)
  configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
05-29 15:35:08.591 24037-24037/com.cleatchaser D/FFmpeg: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/20180406_140202.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
05-29 15:35:08.596 24037-24037/com.cleatchaser D/FFmpeg:     compatible_brands: isom3gp4
    creation_time   : 2018-04-06 12:02:25
  Duration: 00:00:15.06, start: 0.000000, bitrate: 17185 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17029 kb/s, 29.95 fps, 30 tbr, 90k tbn, 180k tbc (default)
05-29 15:35:08.601 24037-24037/com.cleatchaser D/FFmpeg:     Metadata:
      rotate          : 90
      creation_time   : 2018-04-06 12:02:25
      handler_name    : VideoHandle
    Side data:
05-29 15:35:08.606 24037-24037/com.cleatchaser D/FFmpeg:       displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 123 kb/s (default)
    Metadata:
      creation_time   : 2018-04-06 12:02:25
05-29 15:35:08.611 24037-24037/com.cleatchaser D/FFmpeg:       handler_name    : SoundHandle
05-29 15:35:08.756 24037-24037/com.cleatchaser D/FFmpeg: Input #1, png_pipe, from '/storage/emulated/0/watermark.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 856x1324, 25 tbr, 25 tbn, 25 tbc

我尝试了类似问题的许多答案,但没有一个起作用.

I tried many answers from similar questions but none of them worked.

错误是否可能在引号中?

Is possible that error is in quotes?

我没有FFmpeg的经验,所以我们将不胜感激.谢谢

I don't have experience with FFmpeg so any help would be very appreciated. Thanks

推荐答案

如果将来有人在视频上加水印时遇到问题,可以使用此方法.可以使用Writingminds编译的FFmpeg库来完成: http://writingminds.github.io/ffmpeg-android-java/

If anyone has the issue in future with putting watermark on video here is how you can do it. This can be done using writingminds compiled FFmpeg library: http://writingminds.github.io/ffmpeg-android-java/

按照说明如何将FFmpeg设置到您的项目中.之后,通过运行以下命令,我可以在视频上添加水印:

Follow the instructions how to setup FFmpeg into your project. After that by running this command I was able to put watermark on video:

        String commands[]={"-y","-i",videoInputPath,"-i", imagePath,"-filter_complex","[1:v]scale=200:200 [ovrl], [0:v][ovrl]overlay=main_w-overlay_w-5:main_h-overlay_h-5:enable='between(t,"+0+","+timeInSec+")'","-codec:a","copy","-strict","-2","-c:v","libx264","-preset","ultrafast",videoOutPath};

videoInputPath-是视频的路径

imagePath-是来自外部存储器的图像路径.我尝试使用来自Drawable的图片,但没有发现该图片有效(不是说不可能)

imagePath - is path of an image from external storage. I tried by using image from Drawable but didn't find that working (not saying it's not possible)

timeInSec-是您可以从MediaMetadataRetriever获得的视频长度:

timeInSec - is length of video which you can get from MediaMetadataRetriever:

    File videoFile = new File(path);
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(this, Uri.fromFile(videoFile));
    String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    long timeInMillisec = Long.parseLong(time );
    timeInSec = (int) (timeInMillisec /1000);

videoOutPath-放置水印后将保存视频的路径

videoOutPath - path where video is going to be saved after putting watermark

上面的命令还将在200:200上缩放水印,您可以根据需要进行调整并将其放置在右下角.

Command above will also scale watermark on 200:200 you can adjust according to your needs and put it in bottom right side.

这篇关于在视频上添加水印的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆