-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
save avpack raw data into h264 file, but it can't play,help! #86
Comments
Don't write raw h264 data to the file. Try to use h264 muxer. |
Sample, that works for me: #include <iostream>
#include "av.h"
#include "format.h"
#include "codeccontext.h"
#include "formatcontext.h"
using namespace std;
int main(int argc, char** argv)
{
if (argc < 3)
return 2;
string input_uri{argv[1]};
string output_uri{argv[2]};
av::init();
//
// INPUT
//
av::FormatContext ictx;
ictx.openInput(input_uri);
ictx.findStreamInfo();
ssize_t video_stream = -1;
//
// OUTPUT
//
av::OutputFormat oformat("h264");
av::FormatContext octx;
octx.setFormat(oformat);
for (size_t i = 0; i < ictx.streamsCount(); ++i) {
auto st = ictx.stream(i);
auto coder = av::GenericCodecContext(st);
if (!st.isVideo())
continue;
if (!octx.outputFormat().codecSupported(coder.codec()))
continue;
auto ost = octx.addStream(coder.codec());
ost.setTimeBase(st.timeBase());
auto ocoder = av::GenericCodecContext(ost);
ocoder.copyContextFrom(coder);
video_stream = i;
break;
}
clog << "VideoStream: " << video_stream << '\n';
octx.openOutput(output_uri);
octx.writeHeader();
octx.dump();
while (true) {
auto pkt = ictx.readPacket();
if (!pkt)
break;
if (pkt.streamIndex() != video_stream)
continue;
pkt.setStreamIndex(0);
octx.writePacket(pkt);
}
octx.writePacket();
octx.writeTrailer();
return 0;
} |
Just read about format of h264 packets and difference between Annex-B format and AVCC format. Start from here. Basically, AVPacket contains NALU without FFmpeg "h264" format saves frames into container in AnnexB format. You can do it manually by prepend 0x01000000 to the Similar things done by BSF (bitstream filter) that used by your last sample. By my opinion, it is not a good idea to use same AVPacket pointer to receive processed packets from bistream filter chain. |
container is FLV, how can i save raw h264 file?
The text was updated successfully, but these errors were encountered: