[英]ffmpeg mp4 video is not playing on html5 video player on browser (corrupt format)
I am executing the following command to insert a watermark on the video and output as a mp4 format but that format is not playing on the browser by html5 video player. 我正在执行以下命令,以在视频上插入水印并以mp4格式输出,但是html5视频播放器无法在浏览器上播放该格式。
$video_url = '../../../uploads/myvideo.mp4';
$watermarked = '../../../uploads/watermarked_video.mp4';
exec("ffmpeg -i $video_url -vf \"movie='sos.png', crop=iw:ih:0:0:dar [img]; [in] [img] overlay=(W-w)/2:(H-h)/2 [out]\" -vcodec mpeg4 -f avi $watermarked"); //creating water marked video
if i download it to my local machine then its playing perfectly on the player. 如果我将其下载到本地计算机,则可以在播放器上完美播放。
is there any syntax problem? 有语法问题吗?
The output format is not quite right. 输出格式不太正确。 There are two factors to consider here:
这里有两个要考虑的因素:
ffmpeg supports reading and writing many different formats and codecs, as does VLC player. ffmpeg和VLC播放器一样,支持读取和写入许多不同的格式和编解码器。 QuickTime does too, but not quite as many.
QuickTime也可以,但数量却不尽相同。 Browsers, however, are much more picky.
但是,浏览器更加挑剔。 You're saving your file in an "AVI" container format, which browsers don't support.
您正在以“ AVI”容器格式保存文件,浏览器不支持该格式。 And you should probably use
libx264
as the codec, which will output H.264 video and is a little more widely used and reliable than mpeg4
which will output MPEG-4 Part 2 video. 而且您可能应该使用
libx264
作为编解码器,它将输出H.264视频,并且比将输出MPEG-4 Part 2视频的mpeg4
更加广泛使用和可靠。
Try this: 尝试这个:
$video_url = '../../../uploads/myvideo.mp4';
$watermarked = '../../../uploads/watermarked_video.mp4';
exec("ffmpeg -i $video_url -i sos.png -filter_complex \"[1:v]crop=iw:ih:0:0:dar [img]; [0:v] [img] overlay=(W-w)/2:(H-h)/2 [out]\" -map \"[out]\" -map 0:a -vcodec libx264 -acodec copy $watermarked"); //creating water marked video
I've removed the -f
parameter because ffmpeg can infer the format from the output file extension. 我删除了
-f
参数,因为ffmpeg可以从输出文件扩展名推断格式。
The movie filter has been removed from the example because it is not needed. 影片过滤器已从示例中删除,因为不需要它。
-vf
was replaced in this example with -filter_complex
. 在此示例中,
-vf
被-filter_complex
。 See simple and complex filtering to see what the differences are. 查看简单过滤和复杂过滤,以了解不同之处。
The audio in this example will be stream copied with -acodec copy
instead of re-encoded. 此示例中的音频将使用
-acodec copy
进行流复制 ,而不是重新编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.