4

我正在使用 MediaRecorder 录制音频 (oga/vorbis) 文件。当我通过 Chrome 记录这些文件时,我遇到了问题:我无法在 ffmpeg 上编辑文件,当我尝试在 Firefox 上播放它们时,它说它们已损坏(尽管它们在 Chrome 上播放正常)。

查看他们在 ffmpeg 上的元数据,我得到了这个:

Input #0, matroska,webm, from '91.oga':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
[STREAM]
index=0
codec_name=opus
codec_long_name=Opus (Opus Interactive Audio Codec)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=eng
[/STREAM]
[FORMAT]
filename=91.oga
nb_streams=1
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=N/A
size=7195
bit_rate=N/A
probe_score=100
TAG:encoder=Chrome

如您所见,持续时间存在问题。我看过这样的帖子: 如何在 Chrome 中为从 MediaRecorder 录制的音频添加预定义的长度?

但即使尝试这样做,我在尝试剪切和合并文件时也遇到了错误。例如在运行时:

ffmpeg -f concat  -i 89_inputs.txt -c copy final.oga

我得到了很多这样的:

[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57612, current: 1980; changing to 57613. This may result in incorrect timestamps in the output file.
[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57613, current: 2041; changing to 57614. This may result in incorrect timestamps in the output file.
DTS -442721849179034176, next:42521 st:0 invalid dropping
PTS -442721849179034176, next:42521 invalid dropping st:0
[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57614, current: 2041; changing to 57615. This may result in incorrect timestamps in the output file.
[oga @ 00000000006789c0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
DTS -442721849179031296, next:42521 st:0 invalid dropping
PTS -442721849179031296, next:42521 invalid dropping st:0

有谁知道我们需要对从 Chrome 录制的音频文件做些什么才能使它们有用?还是我的设置有问题?

记录器js:

if (navigator.getUserMedia) {
  console.log('getUserMedia supported.');

  var constraints = { audio: true };
  var chunks = [];

  var onSuccess = function(stream) {
    var mediaRecorder = new MediaRecorder(stream);

    record.onclick = function() {
      mediaRecorder.start();
      console.log(mediaRecorder.state);
      console.log("recorder started");
      record.style.background = "red";

      stop.disabled = false;
      record.disabled = true;

      var aud = document.getElementById("audioClip");
      start = aud.currentTime;
    }

    stop.onclick = function() {
      console.log(mediaRecorder.state);
      console.log("Recording request sent.");
      mediaRecorder.stop();
    }

    mediaRecorder.onstop = function(e) {
      console.log("data available after MediaRecorder.stop() called.");

      var audio = document.createElement('audio');
      audio.setAttribute('controls', '');
      audio.setAttribute('id', 'audioClip');

      audio.controls = true;
      var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs="vorbis"' });
      chunks = [];
      var audioURL = window.URL.createObjectURL(blob);
      audio.src = audioURL;

      sendRecToPost(blob);   // this just send the audio blob to the server by post
      console.log("recorder stopped");

    }
4

1 回答 1

0

我在ffmpeg 文档中发现我们可以使用此选项在转换时设置元数据:

//-metadata[:metadata_specifier] key=value (output,per-metadata)
//Set a metadata key/value pair.

ffmpeg -i in.avi -metadata title="my title" out.flv

您还可以测试持续时间转换限制是否适用于您的案例:

//-t duration (input/output)
//When used as an input option (before -i), limit the duration of data read from the input file.

//When used as an output option (before an output url), stop writing the output after its duration reaches duration.
于 2017-06-03T01:31:36.350 回答