问题描述
在FFMPEG的GitHub上,我使用 encode_video.c
生成1秒的视频.这是有问题的示例: https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/encode_video.c
From FFMPEG's GitHub, I use the encode_video.c
to generate a 1 second video. Here is the example in question: https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/encode_video.c
我使用以下代码进行编译: gcc -Wall -o ffencode encode_video.c -lavcodec -lavutil -lz -lm
I compile with: gcc -Wall -o ffencode encode_video.c -lavcodec -lavutil -lz -lm
干净编译,零警告.
我通过运行以下代码来测试程序: ./ffencode video.mp4 libx264
I test the program by running: ./ffencode video.mp4 libx264
打印出许多统计信息(根据源代码预期)以及ffmpeg日志,但最终没有错误或警告.
Lots of stats printed out (expected based on source code) as well as ffmpeg logs, but ultimately no errors or warnings.
但是,生成的输出 video.mp4
只能由 ffplay
播放,并且VLC Player(以及Google Chrome)无法播放视频.
However, then the generated output video.mp4
, can only be played by ffplay
, and VLC Player (as well as Google Chrome) fail to play the video.
通过 vlc
命令行播放它实际上会打印:
Playing it via vlc
command line actually prints:
[00007ffd3550fec0] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
TagLib: MP4: Invalid atom size
TagLib: MP4: Invalid atom size
TagLib: MP4: Invalid atom size
查看 ffprobe
输出,比特率和持续时间字段为空:
Looking at ffprobe
output, the bitrate and duration fields are empty:
Input #0, h264, from 'video.mp4':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 352x288, 25 fps, 25 tbr, 1200k tbn, 50 tbc
我使用具有以下配置的ffmpeg 4.1:
I am using ffmpeg 4.1 with the following configuration:
ffprobe version 4.1 Copyright (c) 2007-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-opencl --enable-videotoolbox
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
有什么办法解决此问题吗?看到API的官方示例缺少此类基本信息,这真是令人惊讶.
Any ideas how to fix this? It is pretty surprising to see an API's official example to be lacking such basic information.
推荐答案
您将需要将视频流混合到视频容器中,例如 .mp4
.木星的东西保存在libavformat中.算法应该像这样:
You will need to perform muxing of your video stream into video container, such as .mp4
. Muxing stuff is kept in libavformat. Algorithm should go like this:
- 通过调用
av_register_all
或手动注册感兴趣的格式来初始化格式库. - 通过调用
avformat_alloc_context
创建混合环境 - 通过调用
avformat_new_stream
创建一个或多个媒体流 - 通过调用
avformat_write_header
编写标题 - 通过调用
av_write_frame
写入媒体数据 - 通过调用
av_write_trailer
编写预告片 - 通过调用
avformat_free_context
破坏混合环境
- Initialize format library by invoking
av_register_all
or manually registering formats of interests. - Create muxing context by invoking
avformat_alloc_context
- Create one or more media streams by invoking
avformat_new_stream
- Write header by invoking
avformat_write_header
- Write media data by invoking
av_write_frame
- Write trailer by invoking
av_write_trailer
- Destroy muxing context by invoking
avformat_free_context
这篇关于无法播放Libavcodec(ffmpeg)编码示例的视频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!