简体   繁体   English

AVI到MP4 - ffmpeg转换

[英]AVI to MP4 - ffmpeg conversion

I'm running a debian 7.5 machine with ffmpeg-2.2 installed following these instructions 我按照这些说明运行了安装了ffmpeg-2.2的debian 7.5机器

Issue 问题

I'm trying to display a mp4 video inside my browser. 我正在尝试在浏览器中显示mp4视频。 The original file has an AVI container format. 原始文件具有AVI容器格式。 I can successfully convert it to mp4 and the targetfile is readable (video + sound) with the totem movie player. 我可以成功地将它转换为mp4,目标文件是可读的(视频+声音)与图腾电影播放器​​。 So I thought everything would be OK displaying the bellow page 所以我认为一切都可以显示下面的页面

HTML5 web page HTML5网页

<!DOCTYPE html><html>
<head>
    <title>Webcam</title>
</head>
<body>
<video width="640" height="480" controls>
  <source src="/path/to/output.mp4" type="video/mp4">
<h3>Your browser does not support the video tag</h3>
</video>
</body></html>

Input probe 输入探针

$ ffprobe -show_streams input.avi

  Duration: 00:08:22.90, start: 0.000000, bitrate: 1943 kb/s
    Stream #0:0: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 64 kb/s
    Stream #0:1: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 720x540 [SAR 1:1 DAR 4:3], 1870 kb/s, 29.97 fps, 25 tbr, 29.97 tbn, 25 tbc

Convert 兑换

$ ffmpeg -y -fflags +genpts -i input.avi -acodec copy -vcodec copy ouput.mp4 $ ffmpeg -y -fflags + genpts -i input.avi -acodec copy -vcodec copy ouput.mp4

Html browser Html浏览器

Opening the above html file plays sound but no video is displayed. 打开上面的html文件播放声音,但不显示视频。

When I use other .mp4 files, videos succesfully displayed so I'm sure I face a conversion issue. 当我使用其他.mp4文件时,视频会成功显示,所以我确定我遇到了转换问题。

Not : I've tryed a lot of other ffmpeg options but without success. 不是:我已经尝试了很多其他的ffmpeg选项,但没有成功。

Any idea ? 任何想法 ?

Thanks in advance. 提前致谢。

Your command was stream copying (re-muxing) MPEG-4 Part 2 video into MP4 container, but this format is probably not playable by the browser. 您的命令是 MPEG-4 Part 2视频流复制 (重新复用)到MP4容器中,但浏览器可能无法播放此格式。 You should use H.264 video instead for MP4 container: 您应该使用H.264视频代替MP4容器:

ffmpeg -i input.avi -c:v libx264 <... more options ...> -c:a libfaac \
-movflags +faststart output.mp4

-movflags +faststart will allow the video to begin playback before the file is completely downloaded by the viewer. -movflags +faststart将允许视频在观众完全下载文件之前开始播放。

Note that you can specify multiple alternative media resources for compatibility: 请注意,您可以指定多个备用媒体资源以实现兼容性:

<video width="640" height="480" controls>
  <source src="/path/to/output.mp4" type="video/mp4">
  <source src="/path/to/output.webm" type="video/webm">
  <source src="/path/to/output.ogv" type="video/ogg">
  ...
</video>

Also see: 另见:

I suggest to use the WebM format instead of an MP4. 我建议使用WebM格式而不是MP4格式。 If you look here it seems that WebM is a good choice for compatibility. 如果你看这里似乎WebM是兼容性的好选择。

And in fact I made a similar test by own 事实上,我自己做了类似的测试

<!DOCTYPE html><html>
<head>
    <title>Play a file</title>
</head>
<body>
<video width="640" height="480" controls>
  <source src="vid/output.webm" type="video/webm">
<h3>Your browser does not support the video tag</h3>
</video>

<video width="640" height="480" controls>
  <source src="vid/output.mp4" type="video/mp4">
<h3>Your browser does not support the video tag</h3>
</video>

</body></html>

And I used a video converted by: 我使用了一个视频转换为:

  • ffmpeg -i F:\\Videos\\bbb_1sec.ts ./vid/output.mp4 and ffmpeg -i F:\\ Videos \\ bbb_1sec.ts ./vid/output.mp4 and
  • ffmpeg -i F:\\Videos\\bbb_1sec.ts ./vid/output.webm ffmpeg -i F:\\ Videos \\ bbb_1sec.ts ./vid/output.webm

the MP4 video doesn't work under Firefox 29... but the WebM version is OK MP4视频在Firefox 29下不起作用......但是WebM版本没问题

In another hand the conversion will take more time due to the transcoding to VP8/vorbis. 另一方面,由于转换为VP8 / vorbis,转换将花费更多时间。 But your input video stream that you copied (transmux) into the mp4 file my be out-of the spec( Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658) ) 但是您复制(transmux)到mp4文件中的输入视频流超出了规范( 视频:mpeg4(高级简单配置文件)(XVID / 0x44495658)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM