
Recherche avancée
Médias (29)
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#3 The Safest Place
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#4 Emo Creates
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#2 Typewriter Dance
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (68)
-
Demande de création d’un canal
12 mars 2010, parEn fonction de la configuration de la plateforme, l’utilisateur peu avoir à sa disposition deux méthodes différentes de demande de création de canal. La première est au moment de son inscription, la seconde, après son inscription en remplissant un formulaire de demande.
Les deux manières demandent les mêmes choses fonctionnent à peu près de la même manière, le futur utilisateur doit remplir une série de champ de formulaire permettant tout d’abord aux administrateurs d’avoir des informations quant à (...) -
Le profil des utilisateurs
12 avril 2011, parChaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...) -
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)
Sur d’autres sites (5101)
-
12 ffmpeg xfade transitions : "option not found"
17 juillet 2023, par nimdaI'm running into a strange error where each of these following 12 of the 56 xfade transitions are throwing errors :


- 

- hlwind
- hrwind
- vuwind
- vdwind
- coverleft
- coverright
- coverup
- coverdown
- revealleft
- revealright
- revealup
- revealdown


























I've tested all filter transitions with the following command, which is being generated by a nodeJS app with the fluent-ffmpeg library, and only the twelve listed above fail with the same error "option not found" :


ffmpeg -f lavfi -t 169
 -i color=c=000000:s=960x540:r=30:duration=169
 -i file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-1.jpg
 -i file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-2.jpg 
 -filter_complex
 [1:v]format=pix_fmts=yuva420p,scale=w=4608:h=-1,zoompan=z='1.2+(0*(ot/4))':x='(on/(30*4))*(iw-iw/1.2)':y='(ih-ih/zoom)/2':d=120:s=960x540[1_up];
 [1_up]scale=w=960:h=-1[1_down];
 [2:v]format=pix_fmts=yuva420p,scale=w=4608:h=-1,zoompan=z='1.2+(0*(ot/4))':x='(on/(30*4))*(iw-iw/1.2)':y='(ih-ih/zoom)/2':d=120:s=960x540[2_up];
 [2_up]scale=w=960:h=-1[2_down];
 [1_down][2_down]xfade=transition=revealdown:duration=1:offset=3[2_out];
 [0:v][2_out]overlay=x=0:y=0:enable='lte(t,7)'[all_out]
 -vcodec libx264 -r 30 -f mp4 -map [all_out] -preset veryfast -crf 18 -movflags frag_keyframe+empty_moov -pix_fmt yuv420p all.mp4



fflog output :


ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
 built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
 configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
 libavutil 58. 2.100 / 58. 2.100
 libavcodec 60. 3.100 / 60. 3.100
 libavformat 60. 3.100 / 60. 3.100
 libavdevice 60. 1.100 / 60. 1.100
 libavfilter 9. 3.100 / 9. 3.100
 libswscale 7. 1.100 / 7. 1.100
 libswresample 4. 10.100 / 4. 10.100
 libpostproc 57. 1.100 / 57. 1.100
Input #0, lavfi, from 'color=c=000000:s=960x540:r=30:duration=169':
 Duration: N/A, start: 0.000000, bitrate: N/A
 Stream #0:0: Video: wrapped_avframe, yuv420p, 960x540 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 30 tbn
Input #1, image2, from 'file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-1.jpg':
 Duration: 00:00:00.04, start: 0.000000, bitrate: 36486 kb/s
 Stream #1:0: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 960x540, 25 fps, 25 tbr, 25 tbn
Input #2, image2, from 'file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-2.jpg':
 Duration: 00:00:00.04, start: 0.000000, bitrate: 35680 kb/s
 Stream #2:0: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 960x540, 25 fps, 25 tbr, 25 tbn
[Parsed_xfade_8 @ 0x60000137cb00] [Eval @ 0x16f9b5348] Undefined constant or missing '(' in 'revealdown'
[Parsed_xfade_8 @ 0x60000137cb00] Unable to parse option value "revealdown"
Error applying option 'transition' to filter 'xfade': Option not found
Error initializing complex filters.
Option not found



The fflog for a successful video generation follows (for comparison to the erroneous log above) :


ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
 built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
 configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
 libavutil 58. 2.100 / 58. 2.100
 libavcodec 60. 3.100 / 60. 3.100
 libavformat 60. 3.100 / 60. 3.100
 libavdevice 60. 1.100 / 60. 1.100
 libavfilter 9. 3.100 / 9. 3.100
 libswscale 7. 1.100 / 7. 1.100
 libswresample 4. 10.100 / 4. 10.100
 libpostproc 57. 1.100 / 57. 1.100
Input #0, lavfi, from 'color=c=000000:s=960x540:r=30:duration=169':
 Duration: N/A, start: 0.000000, bitrate: N/A
 Stream #0:0: Video: wrapped_avframe, yuv420p, 960x540 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 30 tbn
Input #1, image2, from 'file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-1.jpg':
 Duration: 00:00:00.04, start: 0.000000, bitrate: 36486 kb/s
 Stream #1:0: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 960x540, 25 fps, 25 tbr, 25 tbn
Input #2, image2, from 'file:///Users/johnbandy/Work/Projects/Active/CNCT/XFade/_assets/crosstrekvx-2.jpg':
 Duration: 00:00:00.04, start: 0.000000, bitrate: 35680 kb/s
 Stream #2:0: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 960x540, 25 fps, 25 tbr, 25 tbn
Stream mapping:
 Stream #0:0 (wrapped_avframe) -> overlay
 Stream #1:0 (mjpeg) -> format:default
 Stream #2:0 (mjpeg) -> format:default
 overlay:default -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[swscaler @ 0x140158000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x120098000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x130078000] deprecated pixel format used, make sure you did set range correctly
 Last message repeated 2 times
[swscaler @ 0x140598000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x1302d8000] deprecated pixel format used, make sure you did set range correctly
 Last message repeated 1 times
[libx264 @ 0x138e09080] using SAR=1/1
[libx264 @ 0x138e09080] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x138e09080] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x138e09080] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=4 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'all.mp4':
 Metadata:
 encoder : Lavf60.3.100
 Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 960x540 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 15360 tbn
 Metadata:
 encoder : Lavc60.3.100 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 0 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A 
frame= 32 fps=0.0 q=24.0 size= 0kB time=00:00:01.00 bitrate= 0.3kbits/s speed=1.94x 
frame= 87 fps= 84 q=24.0 size= 0kB time=00:00:02.83 bitrate= 0.1kbits/s speed=2.75x 
frame= 164 fps=107 q=24.0 size= 0kB time=00:00:05.40 bitrate= 0.1kbits/s speed=3.52x 
frame= 812 fps=399 q=24.0 size= 512kB time=00:00:26.96 bitrate= 155.5kbits/s speed=13.3x 
frame= 1821 fps=718 q=24.0 size= 512kB time=00:01:00.60 bitrate= 69.2kbits/s speed=23.9x 
frame= 2469 fps=813 q=24.0 size= 512kB time=00:01:22.23 bitrate= 51.0kbits/s speed=27.1x 
frame= 3421 fps=967 q=24.0 size= 512kB time=00:01:53.96 bitrate= 36.8kbits/s speed=32.2x 
frame= 4522 fps=1120 q=24.0 size= 768kB time=00:02:30.63 bitrate= 41.8kbits/s speed=37.3x 
frame= 5070 fps=1184 q=-1.0 Lsize= 812kB time=00:02:48.90 bitrate= 39.4kbits/s speed=39.5x 
video:769kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.626653%
[libx264 @ 0x138e09080] frame I:21 Avg QP: 2.73 size: 3710
[libx264 @ 0x138e09080] frame P:1305 Avg QP: 6.83 size: 449
[libx264 @ 0x138e09080] frame B:3744 Avg QP: 9.07 size: 33
[libx264 @ 0x138e09080] consecutive B-frames: 1.1% 1.4% 0.0% 97.5%
[libx264 @ 0x138e09080] mb I I16..4: 95.4% 0.7% 3.8%
[libx264 @ 0x138e09080] mb P I16..4: 0.1% 0.3% 0.1% P16..4: 2.3% 0.2% 0.1% 0.0% 0.0% skip:97.0%
[libx264 @ 0x138e09080] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.1% 0.0% 0.0% direct: 0.1% skip:99.8% L0:70.9% L1:27.3% BI: 1.8%
[libx264 @ 0x138e09080] 8x8 transform intra:13.8% inter:71.9%
[libx264 @ 0x138e09080] coded y,uvDC,uvAC intra: 19.1% 12.6% 5.2% inter: 0.3% 0.5% 0.0%
[libx264 @ 0x138e09080] i16 v,h,dc,p: 94% 2% 4% 1%
[libx264 @ 0x138e09080] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 41% 22% 2% 6% 2% 9% 3% 8%
[libx264 @ 0x138e09080] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 32% 16% 2% 11% 4% 12% 3% 8%
[libx264 @ 0x138e09080] i8c dc,h,v,p: 88% 9% 2% 1%
[libx264 @ 0x138e09080] Weighted P-Frames: Y:1.6% UV:1.6%
[libx264 @ 0x138e09080] kb/s:37.25



-
Using Accord.Video.FFMPEG, I get "parameter is not valid exception". How can I solve it ?
31 mai 2023, par Sheron BlumentalI want to extract all the frames from an MP4 video file and display them on a PictureBox.


The original code comes from this Q&A : How can I time the presentation and extraction of frames from a video file ?


The exception happens after clicking the start button on the line :


var frame = videoReader.ReadVideoFrame();



The message


System.ArgumentException
 HResult=0x80070057
 Message=Parameter is not valid.
 Source=System.Drawing
 StackTrace:
 at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
 at Accord.Video.FFMPEG.VideoFileReader.DecodeVideoFrame(BitmapData bitmapData)
 at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32 frameIndex, BitmapData output)
 at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame()
 at Extract_Frames.Form1.<getvideoframesasync>d__15.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 114
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
 at Extract_Frames.Form1.d__17.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 151
</getvideoframesasync>


The full code


using Accord.IO;
using Accord.Video;
using Accord.Video.FFMPEG;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Extract_Frames
{
 public partial class Form1 : Form
 {
 Bitmap frame = null;
 Graphics frameGraphics = null;
 bool isVideoRunning = false;
 IProgress<bitmap> videoProgress = null;
 private CancellationTokenSource cts = null;
 private readonly object syncRoot = new object();
 private static long pause = 0;
 private int frameRate = 0;
 private List<bitmap> frames = new List<bitmap>();
 string fileName;

 public Form1()
 {
 InitializeComponent();

 }

 private void Form1_Load(object sender, EventArgs e)
 {

 }

 private void StopPlayback(bool cancel)
 {
 lock (syncRoot)
 {
 if (cancel) cts?.Cancel();
 cts?.Dispose();
 cts = null;
 }
 }

 int counter =1;
 private void Updater(Bitmap videoFrame)
 {
 frames.Add(videoFrame);

 label1.Text = "Current Frame Number : " + counter;
 trackBar1.Value = counter;
 counter++;

 //Size size = new Size(videoFrame.Width, videoFrame.Height);
 //pictureBox1.ClientSize = size;
 using (videoFrame) frameGraphics.DrawImage(videoFrame, Point.Empty);

 pictureBox1.Invalidate();
 }

 private async Task GetVideoFramesAsync(IProgress<bitmap> updater, string fileName, int intervalMs, CancellationToken token = default)
 {
 using (var videoReader = new VideoFileReader())
 {
 if (token.IsCancellationRequested) return;
 videoReader.Open(fileName);

 videoReader.ReadVideoFrame(1);
 trackBar1.Value = 1;

 label1.Text = "Current Frame Number : " + counter.ToString();

 while (true)
 {
 if (Interlocked.Read(ref pause) == 0)
 {
 var frame = videoReader.ReadVideoFrame();

 if (token.IsCancellationRequested || frame is null) break;
 updater.Report(frame);
 }
 await Task.Delay(frameRate).ConfigureAwait(false);
 }
 }
 }

 private void trackBar2_Scroll(object sender, EventArgs e)
 {
 frameRate = trackBar2.Value / 25;
 }

 private async void buttonStart_Click(object sender, EventArgs e)
 {
 string fileName = textBox1.Text;

 if (isVideoRunning) return;
 isVideoRunning = true;

 using (var videoReader = new VideoFileReader())
 {
 videoReader.Open(fileName);
 frame = new Bitmap(videoReader.Width + 2, videoReader.Height + 2);
 trackBar1.Maximum = (int)videoReader.FrameCount;
 }

 videoProgress = new Progress<bitmap>((bitmap) => Updater(bitmap));
 cts = new CancellationTokenSource();
 pictureBox1.Image = frame;
 try
 {
 frameGraphics = Graphics.FromImage(frame);
 // Set the fame rate to 25 frames per second
 //int frameRate = 1000 / 25;
 await GetVideoFramesAsync(videoProgress, fileName, frameRate, cts.Token);
 }
 finally
 {
 frameGraphics?.Dispose();
 StopPlayback(false);
 isVideoRunning = false;
 }
 }

 private void buttonPause_Click(object sender, EventArgs e)
 {
 if (pause == 0)
 {
 buttonPause.Text = "Resume";
 Interlocked.Increment(ref pause);
 }
 else
 {
 Interlocked.Decrement(ref pause);
 buttonPause.Text = "Pause";
 }
 }

 private void buttonStop_Click(object sender, EventArgs e)
 {
 StopPlayback(true);
 }

 protected override void OnFormClosing(FormClosingEventArgs e)
 {
 if (isVideoRunning) StopPlayback(true);
 pictureBox1.Image?.Dispose();
 base.OnFormClosing(e);
 }

 private void pictureBox1_Paint(object sender, PaintEventArgs e)
 {
 ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
 }

 private void trackBar1_Scroll(object sender, EventArgs e)
 {
 pictureBox1.Image = frames[trackBar1.Value];
 }

 private void button1_Click(object sender, EventArgs e)
 {
 using (OpenFileDialog openFileDialog = new OpenFileDialog())
 {
 openFileDialog.InitialDirectory = "c:\\";
 openFileDialog.Filter = "video files (*.mp4)|*.mp4|All files (*.*)|*.*";
 openFileDialog.FilterIndex = 2;
 openFileDialog.RestoreDirectory = true;

 if (openFileDialog.ShowDialog() == DialogResult.OK)
 {
 // Get the path of specified file
 textBox1.Text = openFileDialog.FileName;
 }
 }
 }
 }
}
</bitmap></bitmap></bitmap></bitmap></bitmap>


-
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;

}