使用ffmpeg将mkv转换为mp4

当我尝试使用ffmpeg将mkv转换为mp4时,会发生以下错误:

version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers built on Jun 12 2012 16:52:09 with gcc 4.6.3 *** THIS PROGRAM IS DEPRECATED *** This program is only provided for compatibility and will be removed in a future release. Please use avconv instead. [matroska,webm @ 0x1e939c0] max_analyze_duration reached [matroska,webm @ 0x1e939c0] Estimating duration from bitrate, this may be inaccurate Input #0, matroska,webm, from 'input.mkv': Duration: 00:01:00.76, start: 0.000000, bitrate: 384 kb/s Stream #0.0(eng): Video: h264 (High), yuv420p, 1280x544, PAR 1:1 DAR 40:17, 25 fps, 25 tbr, 1k tbn, 50 tbc (default) Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s (default) Stream #0.2(eng): Subtitle: [0][0][0][0] / 0x0000 Output #0, ipod, to 'output.m4v': Metadata: encoder : Lavf53.21.0 Stream #0.0(eng): Video: libx264, yuv420p, 1280x544 [PAR 1:1 DAR 40:17], q=2-31, 25 tbn, 25 tbc (default) Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, 384 kb/s (default) Stream mapping: Stream #0.0 -> #0.0 Stream #0.1 -> #0.1 Press ctrl-c to stop encoding [ipod @ 0x1e9b740] Application provided invalid, non monotonically increasing dts to muxer in stream 0: -2 >= -2 av_interleaved_write_frame(): Invalid argument 

我用这个命令转换文件:

 ffmpeg -i input.mkv -vcodec copy -acodec copy -absf aac_adtstoasc output.m4v 

输入文件具有以下特征:

 mediainfo input.mkv >General > >Unique ID : 200459305952356554213392832683163418790 (0x96CF0ED8DB5914CBB9E18163689280A6) >Complete name : input.mkv >Format : Matroska >Format version : Version 2 >File size : 1.46 GiB >Duration : 1h 5mn >Overall bit rate : 3 168 Kbps >Encoded date : UTC 2010-09-26 21:44:02 >Writing application : mkvmerge v2.9.5 ('Tu es le seul') built on >Jun 17 2009 16:28:30 >Writing library : libebml v0.7.8 + libmatroska v0.8.1 > >Video >ID : 1 >Format : AVC >Format/Info : Advanced Video Codec >Format profile : High@L3.1 >Format settings, CABAC : Yes >Format settings, ReFrames : 4 frames >Codec ID : V_MPEG4/ISO/AVC >Duration : 1h 5mn >Bit rate : 2 910 Kbps >Width : 1 280 pixels >Height : 720 pixels >Display aspect ratio : 16:9 >Frame rate : 25.000 fps >Color space : YUV >Chroma subsampling : 4:2:0 >Bit depth : 8 bits >Scan type : Progressive >Bits/(Pixel*Frame) : 0.126 >Stream size : 1.31 GiB (90%) >Writing library : x264 core 105 r1724 b02df7b >Encoding settings : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-2 / threads=18 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc=2pass / mbtree=0 / bitrate=2910 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00 > >Default : Yes >Forced : No > >Audio >ID : 2 >Format : AC-3 >Format/Info : Audio Coding 3 >Mode extension : CM (complete main) >Codec ID : A_AC3 >Duration : 1h 5mn >Bit rate mode : Constant >Bit rate : 256 Kbps >Channel(s) : 2 channels >Channel positions : Front: LR >Sampling rate : 48.0 KHz >Bit depth : 16 bits >Compression mode : Lossy Stream size : 121 MiB (8%) Language : English Default : Yes Forced : No 

作为ffmpeg的新手,我不确定错误的含义或如何纠正错误。

谢谢!

正如我已经在这里写的那样 ,我建议你在命令行中更改一些细节:

  • 如果您使用的是早于15.04的Ubuntu版本,请将ffmpeg替换为avconv ,因为它是Ubuntu使用的分叉器几年(请参阅注释)
  • 你真的需要-absf aac_adtstoasc吗? 它有一些问题可能在当前的Ubuntu的ffmpeg中没有得到纠正。 我建议你先试试没有它。
  • -vcodec copy -acodec copy可以简化为-codec copy-c copy 。 它还可以防止篡改除video和音频之外的其他流,如字幕。

所以获胜者是……

 ffmpeg -i input.mkv -c copy output.m4v 

如果这不起作用,请发布所有终端输出。

我知道它是一个非常老的线程,但我找到了成功运行ffmpeg的解决方案。 不要使用-vcodec copy -acodec copy ,而只使用ffmpeg -i input.mkv output.m4v 。 它将开始运行。

但在我的情况下,我将.mkv转换为.mp4,结果输出只是垃圾。 它会损失帧精度。

要自动将文件夹中的所有文件从MKV转换为MP4,您可以创建别名:

 alias mkv2mp4="for f in ./**/*.mkv; do ffmpeg -n -i \"\$f\" -c copy \"\${f%.mkv}.mp4\" && rm \"\$f\"; done" 

此命令执行以下步骤:

  • 递归循环遍历当前目录,查找.mkv文件
  • 将每个文件转换为.mp4,而不是覆盖现有文件
  • 转换成功后删除源文件

已经有一个关于这个如何将.mkv文件无损转换为.mp4文件的答案?

基本概念是MKV和MP4都是容器,它们只是容器,如果你想在两者之间切换,你基本上必须打开包装并重新打包音频和video轨道。

在尝试使用DVDStyler刻录MP4 DVD时,在Xubuntu 14.04上得到了这个; Bombono产生同样的错误。 ffmpeg#1154表明这可能已经修复了ffmpeg ,虽然可能不在avconv ? libav#478仍然标记为打开状态。

另请参阅: https : //unix.stackexchange.com/questions/127522/avconv-error-av-interleaved-write-frame

我提交了Launchpad#1339980 ; 总之,使用当前版本的ffmpeg ,而不是avconv

试试这个:: Linux中的Libav

安装:运行命令

 sudo apt-get install libav-tools 

video转换命令::转到文件夹包含video并在终端中运行

 avconv -i oldvideo.mkv -ar 22050 convertedvideo.mp4