Comments (4)
Don't write raw h264 data to the file. Try to use h264 muxer.
from avcpp.
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;
}
from avcpp.
one more question, i want to get raw h264 packet , then send to HARDWARE DECODER, but if use your example, how can realize this function? i try some code like this:
i just test my code is ok,it can create h264 file, and it can play, and the raw packet can send to hardware decoder. BUT, it this code RIGHT? it this code have memory leak?? PLEASE HELP ME!
from avcpp.
Just read about format of h264 packets and difference between Annex-B format and AVCC format. Start from here.
Basically, AVPacket contains NALU without [start code]
. I deeply work only with Xilinx VCU via OpenMAX interface. This decoder expects packets in AnnexB format with start codes.
FFmpeg "h264" format saves frames into container in AnnexB format. You can do it manually by prepend 0x01000000 to the pkt.data()
.
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.
from avcpp.
Related Issues (20)
- Create aggregate headers roughly corresponding to FFmpeg's libraries
- `av::Rational`: define other relational operators
- Broken with FFmpeg 5.1 HOT 2
- CMake: INTERFACE_LIBRARY targets may only have whitelisted properties. HOT 2
- FFmpeg 5.1: fix channel_layout API HOT 1
- Is this project still alive? HOT 1
- Spelling Mistake in Content - "insormation" should be "information" in README HOT 1
- Broken Link in CONTRIBUTING.md - 404 Error
- `api2-decode-encode-video.cpp` example and correct stream tear-down sequence HOT 3
- Decoded frames have invalid PTS
- Copy a stream without transcoding HOT 3
- Take into account the filter size when calculating the delay HOT 1
- Memory leak (duplicate initialization) of all `CodecContext2` derived classes
- example api2-decode fail HOT 9
- compile ffmpeg with cuda surpport, so can avcpp use hwaccelerate? HOT 1
- problem: not with libpostproc?
- Why do you use new Codec() object in examples? HOT 2
- Debugging the library HOT 1
- Error compiling catch on Ubuntu 21 gcc 11.2.0 HOT 2
- Support for gpu-accelerated decoding? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avcpp.