
Recherche avancée
Médias (1)
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
Autres articles (69)
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 est la première version de MediaSPIP stable.
Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Creating farms of unique websites
13 avril 2011, parMediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)
Sur d’autres sites (7237)
-
Trouble syncing libavformat/ffmpeg with x264 and RTP
26 décembre 2012, par Jacob PeddicordI've been working on some streaming software that takes live feeds
from various kinds of cameras and streams over the network using
H.264. To accomplish this, I'm using the x264 encoder directly (with
the "zerolatency" preset) and feeding NALs as they are available to
libavformat to pack into RTP (ultimately RTSP). Ideally, this
application should be as real-time as possible. For the most part,
this has been working well.Unfortunately, however, there is some sort of synchronization issue :
any video playback on clients seems to show a few smooth frames,
followed by a short pause, then more frames ; repeat. Additionally,
there appears to be approximately a 4-second delay. This happens with
every video player I've tried : Totem, VLC, and basic gstreamer pipes.I've boiled it all down to a somewhat small test case :
#include
#include
#include
#include
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>
#define WIDTH 640
#define HEIGHT 480
#define FPS 30
#define BITRATE 400000
#define RTP_ADDRESS "127.0.0.1"
#define RTP_PORT 49990
struct AVFormatContext* avctx;
struct x264_t* encoder;
struct SwsContext* imgctx;
uint8_t test = 0x80;
void create_sample_picture(x264_picture_t* picture)
{
// create a frame to store in
x264_picture_alloc(picture, X264_CSP_I420, WIDTH, HEIGHT);
// fake image generation
// disregard how wrong this is; just writing a quick test
int strides = WIDTH / 8;
uint8_t* data = malloc(WIDTH * HEIGHT * 3);
memset(data, test, WIDTH * HEIGHT * 3);
test = (test << 1) | (test >> (8 - 1));
// scale the image
sws_scale(imgctx, (const uint8_t* const*) &data, &strides, 0, HEIGHT,
picture->img.plane, picture->img.i_stride);
}
int encode_frame(x264_picture_t* picture, x264_nal_t** nals)
{
// encode a frame
x264_picture_t pic_out;
int num_nals;
int frame_size = x264_encoder_encode(encoder, nals, &num_nals, picture, &pic_out);
// ignore bad frames
if (frame_size < 0)
{
return frame_size;
}
return num_nals;
}
void stream_frame(uint8_t* payload, int size)
{
// initalize a packet
AVPacket p;
av_init_packet(&p);
p.data = payload;
p.size = size;
p.stream_index = 0;
p.flags = AV_PKT_FLAG_KEY;
p.pts = AV_NOPTS_VALUE;
p.dts = AV_NOPTS_VALUE;
// send it out
av_interleaved_write_frame(avctx, &p);
}
int main(int argc, char* argv[])
{
// initalize ffmpeg
av_register_all();
// set up image scaler
// (in-width, in-height, in-format, out-width, out-height, out-format, scaling-method, 0, 0, 0)
imgctx = sws_getContext(WIDTH, HEIGHT, PIX_FMT_MONOWHITE,
WIDTH, HEIGHT, PIX_FMT_YUV420P,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
// set up encoder presets
x264_param_t param;
x264_param_default_preset(&param, "ultrafast", "zerolatency");
param.i_threads = 3;
param.i_width = WIDTH;
param.i_height = HEIGHT;
param.i_fps_num = FPS;
param.i_fps_den = 1;
param.i_keyint_max = FPS;
param.b_intra_refresh = 0;
param.rc.i_bitrate = BITRATE;
param.b_repeat_headers = 1; // whether to repeat headers or write just once
param.b_annexb = 1; // place start codes (1) or sizes (0)
// initalize
x264_param_apply_profile(&param, "high");
encoder = x264_encoder_open(&param);
// at this point, x264_encoder_headers can be used, but it has had no effect
// set up streaming context. a lot of error handling has been ommitted
// for brevity, but this should be pretty standard.
avctx = avformat_alloc_context();
struct AVOutputFormat* fmt = av_guess_format("rtp", NULL, NULL);
avctx->oformat = fmt;
snprintf(avctx->filename, sizeof(avctx->filename), "rtp://%s:%d", RTP_ADDRESS, RTP_PORT);
if (url_fopen(&avctx->pb, avctx->filename, URL_WRONLY) < 0)
{
perror("url_fopen failed");
return 1;
}
struct AVStream* stream = av_new_stream(avctx, 1);
// initalize codec
AVCodecContext* c = stream->codec;
c->codec_id = CODEC_ID_H264;
c->codec_type = AVMEDIA_TYPE_VIDEO;
c->flags = CODEC_FLAG_GLOBAL_HEADER;
c->width = WIDTH;
c->height = HEIGHT;
c->time_base.den = FPS;
c->time_base.num = 1;
c->gop_size = FPS;
c->bit_rate = BITRATE;
avctx->flags = AVFMT_FLAG_RTP_HINT;
// write the header
av_write_header(avctx);
// make some frames
for (int frame = 0; frame < 10000; frame++)
{
// create a sample moving frame
x264_picture_t* pic = (x264_picture_t*) malloc(sizeof(x264_picture_t));
create_sample_picture(pic);
// encode the frame
x264_nal_t* nals;
int num_nals = encode_frame(pic, &nals);
if (num_nals < 0)
printf("invalid frame size: %d\n", num_nals);
// send out NALs
for (int i = 0; i < num_nals; i++)
{
stream_frame(nals[i].p_payload, nals[i].i_payload);
}
// free up resources
x264_picture_clean(pic);
free(pic);
// stream at approx 30 fps
printf("frame %d\n", frame);
usleep(33333);
}
return 0;
}This test shows black lines on a white background that
should move smoothly to the left. It has been written for ffmpeg 0.6.5
but the problem can be reproduced on 0.8 and 0.10 (from what I've tested so far). I've taken some shortcuts in error handling to make this example as short as
possible while still showing the problem, so please excuse some of the
nasty code. I should also note that while an SDP is not used here, I
have tried using that already with similar results. The test can be
compiled with :gcc -g -std=gnu99 streamtest.c -lswscale -lavformat -lx264 -lm -lpthread -o streamtest
It can be played with gtreamer directly :
gst-launch udpsrc port=49990 ! application/x-rtp,payload=96,clock-rate=90000 ! rtph264depay ! decodebin ! xvimagesink
You should immediately notice the stuttering. One common "fix" I've
seen all over the Internet is to add sync=false to the pipeline :gst-launch udpsrc port=49990 ! application/x-rtp,payload=96,clock-rate=90000 ! rtph264depay ! decodebin ! xvimagesink sync=false
This causes playback to be smooth (and near-realtime), but is a
non-solution and only works with gstreamer. I'd like to fix the
problem at the source. I've been able to stream with near-identical
parameters using raw ffmpeg and haven't had any issues :ffmpeg -re -i sample.mp4 -vcodec libx264 -vpre ultrafast -vpre baseline -b 400000 -an -f rtp rtp://127.0.0.1:49990 -an
So clearly I'm doing something wrong. But what is it ?
-
Encoding YUV file (uncompressed video) to mp4 playable file using H264 encoding with ffmpeg c++ (NOT command line)
20 avril 2023, par devprogMy goal is to encode a yuv file to a playable mp4 file (can be played with VLC) with ffmpeg c++ code.


First I have a source_1920x1080p30.mpg video (compressed) file.
Using ffmpeg CLI I created output_test.yuv file.

ffmpeg -i source_1920x1080p30.mpg -c:v rawvideo -pix_fmt yuv420p output_test.yuv


I used
ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 output_test.yuv
which played well.
Also usedffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 30 -i output_test.yuv -c:v libx264 vid.mp4

and the new vid.mp4 was playble.
So I have good yuv file.

I want to encode this output_test.yuv YUV file with ffmpeg by code.
I tested the ffmpeg site encode example ffmpeg site encode example and it was running good.


In that example, the frames are self made inside the code - But I want that the input would be my YUV file.


Becasue I used ffmpeg CLI to convert YUV to mp4 (as noted above) I am sure it can be done by code - but I dont how..


So, I tried to add to their example the use of the methods :
avformat_open_input() & avformat_find_stream_info()


#include 
#include 
#include 

extern "C" {
#include <libavformat></libavformat>avformat.h>
#include <libavcodec></libavcodec>avcodec.h>
 
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>
} 
// ffmpeg method.
static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
 FILE *outfile)
{
 int ret;
 
 /* send the frame to the encoder */
 if (frame)
 printf("Send frame %3" PRId64 "\n", frame->pts);
 
 ret = avcodec_send_frame(enc_ctx, frame);
 if (ret < 0) {
 fprintf(stderr, "Error sending a frame for encoding\n");
 exit(1);
 }
 
 while (ret >= 0) {
 ret = avcodec_receive_packet(enc_ctx, pkt);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 return;
 else if (ret < 0) {
 fprintf(stderr, "Error during encoding\n");
 exit(1);
 }
 
 printf("Write packet %3" PRId64 " (size=%5d)\n", pkt->pts, pkt->size);
 fwrite(pkt->data, 1, pkt->size, outfile);
 av_packet_unref(pkt);
 }
}

int main(int argc, char **argv)
{
 
 int ret;
 char errbuf[100];

 AVFormatContext* ifmt_ctx = avformat_alloc_context();

 AVDictionary* options = NULL;
 //av_dict_set(&options, "framerate", "30", 0);
 av_dict_set(&options, "video_size", "1920x1080", 0);
 av_dict_set(&options,"pixel_format", "yuv420p",0);
 av_dict_set(&options, "vcodec", "rawvideo", 0);

 if ((ret = avformat_open_input(&ifmt_ctx, "output_test.yuv", NULL, &options)) < 0) {
 av_strerror(ret, errbuf, sizeof(errbuf));
 fprintf(stderr, "Unable to open err=%s\n", errbuf);
 }

 const AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_RAWVIDEO); //Get pointer to rawvideo codec.

 AVCodecContext *pCodecContext = avcodec_alloc_context3(pCodec); //Allocate codec context.

 //Fill the codec context based on the values from the codec parameters.
 AVStream *vid_stream = ifmt_ctx->streams[0];
 avcodec_parameters_to_context(pCodecContext, vid_stream->codecpar);

 avcodec_open2(pCodecContext, pCodec, NULL); //Open the codec

 //Allocate memory for packet and frame
 AVPacket *pPacket = av_packet_alloc();
 AVFrame *pFrame = av_frame_alloc();

 // For output use:
 
 const char *filename, *codec_name;
 const AVCodec *codec;
 AVCodecContext *c= NULL;
 int i, x, y;
 FILE *f;
 // origin ffmpeg code - AVFrame *frame;
 AVPacket *pkt;
 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
 
 if (argc <= 2) {
 fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);
 exit(0);
 }
 filename = argv[1];
 codec_name = argv[2];
 
 /* find the mpeg1video encoder */
 codec = avcodec_find_encoder_by_name(codec_name);
 if (!codec) {
 fprintf(stderr, "Codec '%s' not found\n", codec_name);
 exit(1);
 }
 
 c = avcodec_alloc_context3(codec);
 if (!c) {
 fprintf(stderr, "Could not allocate video codec context\n");
 exit(1);
 }
 
 pkt = av_packet_alloc();
 if (!pkt)
 exit(1);
 
 /* put sample parameters */
 c->bit_rate = 400000;
 /* resolution must be a multiple of two */
 c->width = 352;
 c->height = 288;
 /* frames per second */
 c->time_base = (AVRational){1, 25};
 c->framerate = (AVRational){25, 1};
 
 /* emit one intra frame every ten frames
 * check frame pict_type before passing frame
 * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
 * then gop_size is ignored and the output of encoder
 * will always be I frame irrespective to gop_size
 */
 c->gop_size = 10;
 c->max_b_frames = 1;
 c->pix_fmt = AV_PIX_FMT_YUV420P;
 
 if (codec->id == AV_CODEC_ID_H264)
 av_opt_set(c->priv_data, "preset", "slow", 0);
 
 /* open it */
 ret = avcodec_open2(c, codec, NULL);
 if (ret < 0) {
 //fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
 exit(1);
 }
 
 f = fopen(filename, "wb");
 if (!f) {
 fprintf(stderr, "Could not open %s\n", filename);
 exit(1);
 }
// This is ffmpeg code that I removed 
// frame = av_frame_alloc();
// if (!frame) {
// fprintf(stderr, "Could not allocate video frame\n");
// exit(1);
// }
// frame->format = c->pix_fmt;
// frame->width = c->width;
// frame->height = c->height;
// 
// ret = av_frame_get_buffer(frame, 0);
// if (ret < 0) {
// fprintf(stderr, "Could not allocate the video frame data\n");
// exit(1);
// }

 pFrame->format = c->pix_fmt;
 pFrame->width = c->width;
 pFrame->height = c->height;
 

 //Read video frames and pass through the decoder.
 //Note: Since the video is rawvideo, we don't really have to pass it through the decoder.
 while (av_read_frame(ifmt_ctx, pPacket) >= 0) 
 {
 //The video is not encoded - passing through the decoder is simply copy the data.
 avcodec_send_packet(pCodecContext, pPacket); //Supply raw packet data as input to the "decoder".
 avcodec_receive_frame(pCodecContext, pFrame); //Return decoded output data from the "decoder".

 fflush(stdout);
// This is ffmpeg code that I removed 
// /* Make sure the frame data is writable.
// On the first round, the frame is fresh from av_frame_get_buffer()
// and therefore we know it is writable.
// But on the next rounds, encode() will have called
// avcodec_send_frame(), and the codec may have kept a reference to
// the frame in its internal structures, that makes the frame
// unwritable.
// av_frame_make_writable() checks that and allocates a new buffer
// for the frame only if necessary.
// */
// ret = av_frame_make_writable(frame);
// if (ret < 0)
// exit(1);
// 
// /* Prepare a dummy image.
// In real code, this is where you would have your own logic for
// filling the frame. FFmpeg does not care what you put in the
// frame.
// */
// /* Y */
// for (y = 0; y < c->height; y++) {
// for (x = 0; x < c->width; x++) {
// frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
// }
// }
// 
// /* Cb and Cr */
// for (y = 0; y < c->height/2; y++) {
// for (x = 0; x < c->width/2; x++) {
// frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
// frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
// }
// }
 
 pFrame->pts = i;
 
 /* encode the image */
 encode(c, pFrame, pkt, f);
 }
 
 /* flush the encoder */
 encode(c, NULL, pkt, f);
 
 /* Add sequence end code to have a real MPEG file.
 It makes only sense because this tiny examples writes packets
 directly. This is called "elementary stream" and only works for some
 codecs. To create a valid file, you usually need to write packets
 into a proper file format or protocol; see mux.c.
 */
 if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)
 fwrite(endcode, 1, sizeof(endcode), f);
 fclose(f);
 
 avcodec_free_context(&c);
 av_frame_free(&pFrame);
 av_packet_free(&pkt);
 
 return 0;
}
</codec></output>


EDIT : I added combined code of ffmpeg and reading/decoding from YUV file according @Rotem (thanks). Frame from decoder pushed right to encode() method of ffmpeg. The out video was not good... Should I manipulate the YUV input frame before send it to encode() method ? if yes how to do it ?


-
FFmpeg avcodec_open2 throws -22 ("Invalid Argument")
14 avril 2023, par stupidbutseekingI got stuck trying to write a simple video conversion using C++ and ffmpeg.


When trying to convert a video using FFmpeg, calling avcodec_open2 fails with the code "-22" which seems to be an "Invalid Argument"-error.


I can't figure out why it fails, nor what the invalid argument is. In the following snippet I create the output codec and pass its context the information from the source (code further down below).


The check for the "outputCodec" works and does not throw an error. As far as I know an "AVDictionary"-argument is optional. So I guess the reason for the error is the context.


const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

 if (!outputCodec)
 {
 std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
 return -1;
 }

 AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
 outputCodecContext->bit_rate = bitRate;
 outputCodecContext->width = inputCodecContext->width;
 outputCodecContext->height = inputCodecContext->height;
 outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
 outputCodecContext->time_base = inputCodecContext->time_base;

 **int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL); //THIS RETURNS -22**
 if (errorCode != 0)
 {
 std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
 return -1;
 }



Here is the code for getting the input file & context :


std::string inputFilename = "input_video.mp4";
 std::string outputFilename = "output.avi";
 std::string codecName = "mpeg4";
 int bitRate = 400000;

 AVFormatContext* inputFormatContext = NULL;
 if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
 return -1;
 }

 [Do Video Stream Search)

 AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
 const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
 AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
 if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
 {
 std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
 return -1;
 }
 if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
 return -1;
 }



The purpose was simply to get started with ffmpeg in an own C++ project.


If it is of any need, I downloaded the ffmpeg libs from here. I used the gpl shared ones. The architecture is win x64. I referenced them through the project properties (additional libraries and so on).


I tried to convert a .mp4 video to an .avi video with an "mpeg4" compression.
I also tried other compressions like "libx264" but none worked.


I searched for the problem on stackoverflow but could not find the exact same problem. While its purpose is different this post is about the same error code when calling avcodec_open2. But its solution is not working for me. I inspected the watch for the "outputContext" while running the code and the codec_id, codec_type and format is set. I use the time_base from the input file. According to my understanding, this should be equal to the source. So I can not find out what I am missing.


Thanks in advance and sorry for my english.


And for completion, here is the whole method :


int TestConvert()
{
 std::string inputFilename = "input_video.mp4";
 std::string outputFilename = "output.avi";
 std::string codecName = "mpeg4";
 int bitRate = 400000;

 AVFormatContext* inputFormatContext = NULL;
 if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
 return -1;
 }

 int videoStreamIndex = -1;
 for (unsigned int i = 0; i < inputFormatContext->nb_streams; i++)
 {
 if (inputFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 videoStreamIndex = i;
 break;
 }
 }

 AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
 const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
 AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
 if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
 {
 std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
 return -1;
 }
 if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
 {
 std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
 return -1;
 }

 const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

 if (!outputCodec)
 {
 std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
 return -1;
 }

 AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
 outputCodecContext->bit_rate = bitRate;
 outputCodecContext->width = inputCodecContext->width;
 outputCodecContext->height = inputCodecContext->height;
 outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
 outputCodecContext->time_base = inputCodecContext->time_base;

 int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL);
 if (errorCode != 0)
 {
 std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
 return -1;
 }

 AVFormatContext* outputFormatContext = NULL;
 if (avformat_alloc_output_context2(&outputFormatContext, NULL, NULL, outputFilename.c_str()) != 0)
 {
 std::cout << "Fehler beim Erstellen des Ausgabe-Formats" << std::endl;
 return -1;
 }

 AVStream* outputVideoStream = avformat_new_stream(outputFormatContext, outputCodec);
 if (outputVideoStream == NULL)
 {
 std::cout << "Fehler beim Hinzufügen des Video-Streams zum Ausgabe-Format" << std::endl;
 return -1;
 }
 outputVideoStream->id = outputFormatContext->nb_streams - 1;
 AVCodecParameters* outputCodecParameters = outputVideoStream->codecpar;
 if (avcodec_parameters_from_context(outputCodecParameters, outputCodecContext) != 0)
 {
 std::cout << "Fehler beim Setzen des Ausgabe-Codecs" << std::endl;
 return -1;
 }

 if (!(outputFormatContext->oformat->flags & AVFMT_NOFILE))
 {
 if (avio_open(&outputFormatContext->pb, outputFilename.c_str(), AVIO_FLAG_WRITE) != 0)
 {
 std::cout << "Fehler beim Öffnen der Ausgabedatei" << std::endl;
 return -1;
 }
 }

 if (avformat_write_header(outputFormatContext, NULL) != 0)
 {
 std::cout << "Fehler beim Schreiben des Ausgabe-Formats in die Ausgabedatei" << std::endl;
 return -1;
 }

 AVPacket packet;
 int response;
 AVFrame* frame = av_frame_alloc();
 AVFrame* outputFrame = av_frame_alloc();
 while (av_read_frame(inputFormatContext, &packet) == 0)
 {
 if (packet.stream_index == videoStreamIndex)
 {
 response = avcodec_send_packet(inputCodecContext, &packet);
 while (response >= 0)
 {
 response = avcodec_receive_frame(inputCodecContext, frame);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }
 else if (response < 0)
 {
 std::cout << "Fehler beim Dekodieren des Video-Pakets" << std::endl;
 return -1;
 }

 struct SwsContext* swsContext = sws_getContext(inputCodecContext->width, inputCodecContext->height, inputCodecContext->pix_fmt, outputCodecContext->width, outputCodecContext->height, outputCodecContext->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL); if (!swsContext)
 {
 std::cout << "Fehler beim Erstellen des SwsContext" << std::endl;
 return -1;
 }
 sws_scale(swsContext, frame->data, frame->linesize, 0, inputCodecContext->height, outputFrame->data, outputFrame->linesize);
 sws_freeContext(swsContext);

 outputFrame->pts = frame->pts;
 outputFrame->pkt_dts = frame->pkt_dts;
 //outputFrame->pkt_duration = frame->pkt_duration;
 response = avcodec_send_frame(outputCodecContext, outputFrame);
 while (response >= 0)
 {
 response = avcodec_receive_packet(outputCodecContext, &packet);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }
 else if (response < 0)
 {
 std::cout << "Fehler beim Kodieren des Ausgabe-Frames" << std::endl;
 return -1;
 }

 packet.stream_index = outputVideoStream->id;
 av_packet_rescale_ts(&packet, outputCodecContext->time_base, outputVideoStream->time_base);
 if (av_interleaved_write_frame(outputFormatContext, &packet) != 0)
 {
 std::cout << "Fehler beim Schreiben des Ausgabe-Pakets" << std::endl;
 return -1;
 }
 av_packet_unref(&packet);
 }
 }
 }
 av_packet_unref(&packet);
 }

 av_write_trailer(outputFormatContext);
 avcodec_free_context(&inputCodecContext);
 avcodec_free_context(&outputCodecContext);
 avformat_close_input(&inputFormatContext);
 avformat_free_context(inputFormatContext);
 avformat_free_context(outputFormatContext);
 av_frame_free(&frame);
 av_frame_free(&outputFrame);

 return 0;

}