使用Ffmpeg设置视频流元数据 [英] Setting video stream metadata using Ffmpeg

查看:427
本文介绍了使用Ffmpeg设置视频流元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaCV FFmpegFrameRecorder 类将Android的相机预览帧编码为视频。



目标是复制以下命令行的结果:

  ffmpeg -i input.mp4 -metadata:s:v:0 rotate =90output.mp4 

如下修改了 startUnsafe()方法,但无法生成如果((video_st = avformat_new_stream(oc,video_codec))!= null){
video_c = video_st.codec();
video_c.codec_id(oformat.video_codec());
video_c.codec_type(AVMEDIA_TYPE_VIDEO);
...
AVDictionary avDictionary = new AVDictionary(null);
av_dict_set(avDictionary,rotate,90,0);
video_st.metadata(avDictionaty);
...
}
...
avformat_write_header(oc,(PointerPointer)null);

这仍然正确编码视频,但添加的元数据永远不会出现在ffprobe上。如果有帮助,视频编码是h264。



顺便说一句,ffprobe输出是:

  ffprobe版本2.3.3版权所有(c)2007-2014 FFmpeg开发人员
建立于2015年1月22日18:22:57与Apple LLVM版本6.0(clang-600.0.56)(基于LLVM 3.5svn)
配置:--prefix = / usr / local / Cellar / ffmpeg / 2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 - enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc = clang --host-cflags = --host-ldflags = --enable-libx264 --enable-libfaac --enable -libmp3lame --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable -ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi - -enable-libx265
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55 13.102
libavfilter 4. 11.100 / 4. 11 .100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
从'abcd.mp4'输入#0,mov,mp4,m4a,3gp,3g2,mj2:
元数据:
major_brand:isom
minor_version: 512
compatible_brands:isomiso2avc1mp41
编码器:Lavf56.15.102
持续时间:00:00:19.48,开始:0.023220,比特率:572 kb / s
流#0:0 ):视频:h264(约束基线)(avc1 / 0x31637661),yuv420p,1280x720,573 kb / s,5.71 fps,30 tbr,15360 tbn,60 tbc(默认)
元数据:
handler_name: VideoHandler
流#0:1(und):音频:aac(mp4a / 0x6134706D),44100 Hz,mono,fltp,64 kb / s(默认)
元数据:
handler_name:SoundHandler

有什么建议,为什么会失败?谢谢。

解决方案

似乎这个问题产生了很多兴趣,所以我添加了一些更多的信息。遵循此 GitHub问题 JavaCV的Samuel 提交了一些更改,以便更容易地访问元数据设置。



可以实现设置元数据通过以下代码片段:

  AVDictionary metadata = new AVDictionary(null); $($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
}
video_st.metadata(元数据);

现在可以通过执行 mvn install -Pffmpeg 或者等到下一个JavacV发布,这应该是0.12。



PS:你可以看到,这与我在问题中提出的非常相似,所以我不知道为什么它不起作用。


I'm using the JavaCV FFmpegFrameRecorder class to encode Android's camera preview frames into a video.

The goal would be to replicate the result of the following command line:

ffmpeg -i input.mp4 -metadata:s:v:0 rotate="90" output.mp4

I modified the startUnsafe() method as follows, but it failed to generate the desired output:

if ((video_st = avformat_new_stream(oc, video_codec)) != null) {
        video_c = video_st.codec();
        video_c.codec_id(oformat.video_codec());
        video_c.codec_type(AVMEDIA_TYPE_VIDEO);
        ...
        AVDictionary avDictionary = new AVDictionary(null);
        av_dict_set(avDictionary, "rotate", "90", 0);
        video_st.metadata(avDictionaty);
        ...
}
...
avformat_write_header(oc, (PointerPointer) null);

This still encodes the video correctly, but the added metadata never appears on ffprobe. If it helps, the video encoding is h264.

By the way, here's the ffprobe output:

ffprobe version 2.3.3 Copyright (c) 2007-2014 the FFmpeg developers
  built on Jan 22 2015 18:22:57 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi --enable-libx265
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'abcd.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:19.48, start: 0.023220, bitrate: 572 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 573 kb/s, 5.71 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

Any suggestions on why is it failing? Thanks.

解决方案

It seems this question generated a lot of interest so I'm adding some more info. Following this GitHub issue Samuel from JavaCV committed some changes to allow easier access to metadata settings.

Setting metadata can be achieved through the following code snippet:

AVDictionary metadata = new AVDictionary(null);
for (Entry<String, String> e : videoMetadata.entrySet()) {
    av_dict_set(metadata, e.getKey(), e.getValue(), 0);
}
video_st.metadata(metadata);

You can enable it right now by doing mvn install -Pffmpeg or wait until the next JavacV release, which should be 0.12.

PS: As you can see, this is pretty similar to what I presented in my question, so I'm not sure why it didn't work in the first place.

这篇关于使用Ffmpeg设置视频流元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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