Recherche avancée

Médias (1)

Mot : - Tags -/artwork

Autres articles (48)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (7902)

  • ffmpeg aresample has no effect while it works in ffplay

    11 novembre 2020, par Lemon Sky

    I have a .ts file which is missing frames 20 seconds into the file. I'd like to fill the missing parts with silence. This works using the following command with ffplay :

    


    ffplay -i http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts -af aresample=async=1

    


    The same should work with ffmpeg but no silence is injected. Instead, the audio just continues playing. Example :

    


    ffmpeg -i http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts -af aresample=async=1 -f wav -acodec pcm_s16le -ac 2 - | ffplay -i -

    


    What am I doing wrong ?

    


    Log :

    


    >ffmpeg -y -nostats -loglevel trace -i http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts -af aresample=async=1 -f wav -acodec pcm_s16le -ac 2 out.wav
ffmpeg version 4.3.1-2020-11-08-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.0 (Rev3, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-nostats' ... matched as option 'stats' (print progress report during encoding) with argument 0.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'trace'.
Reading option '-i' ... matched as input url with argument 'http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts'.
Reading option '-af' ... matched as option 'af' (set audio filters) with argument 'aresample=async=1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'wav'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'pcm_s16le'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '2'.
Reading option 'out.wav' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option nostats (print progress report during encoding) with argument 0.
Applying option loglevel (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts.
Successfully parsed a group of options.
Opening an input file: http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts.
[NULL @ 000001d0e7bbd200] Opening 'http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts' for reading
[http @ 000001d0e7bbe2c0] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy,data'
[tcp @ 000001d0e7bc0d00] Original list of addresses:
[tcp @ 000001d0e7bc0d00] Address 144.2.127.86 port 80
[tcp @ 000001d0e7bc0d00] Interleaved list of addresses:
[tcp @ 000001d0e7bc0d00] Address 144.2.127.86 port 80
[tcp @ 000001d0e7bc0d00] Starting connection attempt to 144.2.127.86 port 80
[tcp @ 000001d0e7bc0d00] Successfully connected to 144.2.127.86 port 80
[http @ 000001d0e7bbe2c0] request: GET /KFYI-AM_2020-10-30_09-05-26.ts HTTP/1.1
User-Agent: Lavf/58.45.100
Accept: */*
Range: bytes=0-
Connection: close
Host: tyberis.com
Icy-MetaData: 1


[http @ 000001d0e7bbe2c0] header='HTTP/1.1 206 Partial Content'
[http @ 000001d0e7bbe2c0] http_code=206
[http @ 000001d0e7bbe2c0] header='Content-Type: video/vnd.dlna.mpeg-tts'
[http @ 000001d0e7bbe2c0] header='Last-Modified: Tue, 10 Nov 2020 19:12:18 GMT'
[http @ 000001d0e7bbe2c0] header='Accept-Ranges: bytes'
[http @ 000001d0e7bbe2c0] header='ETag: "7c6a9e6895b7d61:0"'
[http @ 000001d0e7bbe2c0] header='Server: Microsoft-IIS/10.0'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Origin: *'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Range'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Credentials: true'
[http @ 000001d0e7bbe2c0] header='Date: Wed, 11 Nov 2020 15:52:32 GMT'
[http @ 000001d0e7bbe2c0] header='Connection: close'
[http @ 000001d0e7bbe2c0] header='Content-Length: 6531496'
[http @ 000001d0e7bbe2c0] header='Content-Range: bytes 0-6531495/6531496'
[http @ 000001d0e7bbe2c0] header=''
Probing mpegts score:50 size:2048
[mpegts @ 000001d0e7bbd200] Format mpegts probed with size=2048 and score=50
[mpegts @ 000001d0e7bbd200] Probe: 7648, score: 41, dvhs_score: -2, fec_score: -2
[mpegts @ 000001d0e7bbd200] Filter: pid=0x11 type=1
[mpegts @ 000001d0e7bbd200] Filter: pid=0x0 type=1
[mpegts @ 000001d0e7bbd200] Filter: pid=0x12 type=1
[mpegts @ 000001d0e7bbd200] SDT:
[mpegts @ 000001d0e7bbd200] tag: 0x48 len=18
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] PAT:
[mpegts @ 000001d0e7bbd200] sid=0x1 pid=0x1000
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] Filter: pid=0x1000 type=1
[mpegts @ 000001d0e7bbd200] PMT: len 21
[mpegts @ 000001d0e7bbd200] sid=0x1 sec_num=0/0 version=0 tid=2
[mpegts @ 000001d0e7bbd200] pcr_pid=0x100
[mpegts @ 000001d0e7bbd200] Filter: pid=0x100 type=0
[mpegts @ 000001d0e7bbd200] stream=0 stream_type=f pid=100 prog_reg_desc=
[mpegts @ 000001d0e7bbd200] tuning done
[mpegts @ 000001d0e7bbd200] Before avformat_find_stream_info() pos: 0 bytes read:7648 seeks:0 nb_streams:1
[mpegts @ 000001d0e7bbd200] Skipping after seek
[mpegts @ 000001d0e7bbd200] SDT:
[mpegts @ 000001d0e7bbd200] tag: 0x48 len=18
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] PAT:
[mpegts @ 000001d0e7bbd200] sid=0x1 pid=0x1000
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] PMT: len 21
[mpegts @ 000001d0e7bbd200] sid=0x1 sec_num=0/0 version=0 tid=2
[mpegts @ 000001d0e7bbd200] pcr_pid=0x100
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[mpegts @ 000001d0e7bbd200] probing stream 0 pp:2500
Probing aac score:51 size:2640
Probing flac score:13 size:2640
[mpegts @ 000001d0e7bbd200] Probe with size=2640, packets=1 detected aac with score=51
[mpegts @ 000001d0e7bbd200] probed stream 0
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
    Last message repeated 11 times
[mpegts @ 000001d0e7bbd200] max_analyze_duration 5000000 reached at 5014800 microseconds st:0
[tcp @ 000001d0e7c31480] Original list of addresses:
[tcp @ 000001d0e7c31480] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Interleaved list of addresses:
[tcp @ 000001d0e7c31480] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Starting connection attempt to 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Successfully connected to 144.2.127.86 port 80
[http @ 000001d0e7bbe2c0] request: GET /KFYI-AM_2020-10-30_09-05-26.ts HTTP/1.1
User-Agent: Lavf/58.45.100
Accept: */*
Range: bytes=6281496-
Connection: close
Host: tyberis.com
Icy-MetaData: 1


[http @ 000001d0e7bbe2c0] header='HTTP/1.1 206 Partial Content'
[http @ 000001d0e7bbe2c0] http_code=206
[http @ 000001d0e7bbe2c0] header='Content-Type: video/vnd.dlna.mpeg-tts'
[http @ 000001d0e7bbe2c0] header='Last-Modified: Tue, 10 Nov 2020 19:12:18 GMT'
[http @ 000001d0e7bbe2c0] header='Accept-Ranges: bytes'
[http @ 000001d0e7bbe2c0] header='ETag: "7c6a9e6895b7d61:0"'
[http @ 000001d0e7bbe2c0] header='Server: Microsoft-IIS/10.0'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Origin: *'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Range'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Credentials: true'
[http @ 000001d0e7bbe2c0] header='Date: Wed, 11 Nov 2020 15:52:32 GMT'
[http @ 000001d0e7bbe2c0] header='Connection: close'
[http @ 000001d0e7bbe2c0] header='Content-Length: 250000'
[http @ 000001d0e7bbe2c0] header='Content-Range: bytes 6281496-6531495/6531496'
[http @ 000001d0e7bbe2c0] header=''
[mpegts @ 000001d0e7bbd200] Skipping after seek
[mpegts @ 000001d0e7bbd200] Probe: 763, score: 5, dvhs_score: 1, fec_score: 1
[mpegts @ 000001d0e7bbd200] Probe: 8192, score: 44, dvhs_score: -3, fec_score: -3
[tcp @ 000001d0e7c31580] Original list of addresses:
[tcp @ 000001d0e7c31580] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Interleaved list of addresses:
[tcp @ 000001d0e7c31580] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Starting connection attempt to 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Successfully connected to 144.2.127.86 port 80
[http @ 000001d0e7bbe2c0] request: GET /KFYI-AM_2020-10-30_09-05-26.ts HTTP/1.1
User-Agent: Lavf/58.45.100
Accept: */*
Range: bytes=6266023-
Connection: close
Host: tyberis.com
Icy-MetaData: 1


[http @ 000001d0e7bbe2c0] header='HTTP/1.1 206 Partial Content'
[http @ 000001d0e7bbe2c0] http_code=206
[http @ 000001d0e7bbe2c0] header='Content-Type: video/vnd.dlna.mpeg-tts'
[http @ 000001d0e7bbe2c0] header='Last-Modified: Tue, 10 Nov 2020 19:12:18 GMT'
[http @ 000001d0e7bbe2c0] header='Accept-Ranges: bytes'
[http @ 000001d0e7bbe2c0] header='ETag: "7c6a9e6895b7d61:0"'
[http @ 000001d0e7bbe2c0] header='Server: Microsoft-IIS/10.0'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Origin: *'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Range'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Credentials: true'
[http @ 000001d0e7bbe2c0] header='Date: Wed, 11 Nov 2020 15:52:32 GMT'
[http @ 000001d0e7bbe2c0] header='Connection: close'
[http @ 000001d0e7bbe2c0] header='Content-Length: 265473'
[http @ 000001d0e7bbe2c0] header='Content-Range: bytes 6266023-6531495/6531496'
[http @ 000001d0e7bbe2c0] header=''
[tcp @ 000001d0e7c31480] Original list of addresses:
[tcp @ 000001d0e7c31480] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Interleaved list of addresses:
[tcp @ 000001d0e7c31480] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Starting connection attempt to 144.2.127.86 port 80
[tcp @ 000001d0e7c31480] Successfully connected to 144.2.127.86 port 80
[http @ 000001d0e7bbe2c0] request: GET /KFYI-AM_2020-10-30_09-05-26.ts HTTP/1.1
User-Agent: Lavf/58.45.100
Accept: */*
Range: bytes=6281644-
Connection: close
Host: tyberis.com
Icy-MetaData: 1


[http @ 000001d0e7bbe2c0] header='HTTP/1.1 206 Partial Content'
[http @ 000001d0e7bbe2c0] http_code=206
[http @ 000001d0e7bbe2c0] header='Content-Type: video/vnd.dlna.mpeg-tts'
[http @ 000001d0e7bbe2c0] header='Last-Modified: Tue, 10 Nov 2020 19:12:18 GMT'
[http @ 000001d0e7bbe2c0] header='Accept-Ranges: bytes'
[http @ 000001d0e7bbe2c0] header='ETag: "7c6a9e6895b7d61:0"'
[http @ 000001d0e7bbe2c0] header='Server: Microsoft-IIS/10.0'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Origin: *'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Range'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Credentials: true'
[http @ 000001d0e7bbe2c0] header='Date: Wed, 11 Nov 2020 15:52:33 GMT'
[http @ 000001d0e7bbe2c0] header='Connection: close'
[http @ 000001d0e7bbe2c0] header='Content-Length: 249852'
[http @ 000001d0e7bbe2c0] header='Content-Range: bytes 6281644-6531495/6531496'
[http @ 000001d0e7bbe2c0] header=''
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
    Last message repeated 88 times
[tcp @ 000001d0e7c31580] Original list of addresses:
[tcp @ 000001d0e7c31580] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Interleaved list of addresses:
[tcp @ 000001d0e7c31580] Address 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Starting connection attempt to 144.2.127.86 port 80
[tcp @ 000001d0e7c31580] Successfully connected to 144.2.127.86 port 80
[http @ 000001d0e7bbe2c0] request: GET /KFYI-AM_2020-10-30_09-05-26.ts HTTP/1.1
User-Agent: Lavf/58.45.100
Accept: */*
Range: bytes=0-
Connection: close
Host: tyberis.com
Icy-MetaData: 1


[http @ 000001d0e7bbe2c0] header='HTTP/1.1 206 Partial Content'
[http @ 000001d0e7bbe2c0] http_code=206
[http @ 000001d0e7bbe2c0] header='Content-Type: video/vnd.dlna.mpeg-tts'
[http @ 000001d0e7bbe2c0] header='Last-Modified: Tue, 10 Nov 2020 19:12:18 GMT'
[http @ 000001d0e7bbe2c0] header='Accept-Ranges: bytes'
[http @ 000001d0e7bbe2c0] header='ETag: "7c6a9e6895b7d61:0"'
[http @ 000001d0e7bbe2c0] header='Server: Microsoft-IIS/10.0'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Origin: *'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Range'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT'
[http @ 000001d0e7bbe2c0] header='Access-Control-Allow-Credentials: true'
[http @ 000001d0e7bbe2c0] header='Date: Wed, 11 Nov 2020 15:52:33 GMT'
[http @ 000001d0e7bbe2c0] header='Connection: close'
[http @ 000001d0e7bbe2c0] header='Content-Length: 6531496'
[http @ 000001d0e7bbe2c0] header='Content-Range: bytes 0-6531495/6531496'
[http @ 000001d0e7bbe2c0] header=''
[mpegts @ 000001d0e7bbd200] stream 0: start_time: 1.4 duration: 1097.98
[mpegts @ 000001d0e7bbd200] format: start_time: 1.4 duration: 1097.98 (estimate from pts) bitrate=47 kb/s
[mpegts @ 000001d0e7bbd200] After avformat_find_stream_info() pos: 0 bytes read:329238 seeks:3 frames:117
Input #0, mpegts, from 'http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts':
  Duration: 00:18:17.98, start: 1.400000, bitrate: 47 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100], 117, 1/90000: Audio: aac (HE-AACv2) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 45 kb/s
Successfully opened the file.
Parsing a group of options: output url out.wav.
Applying option af (set audio filters) with argument aresample=async=1.
Applying option f (force format) with argument wav.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument pcm_s16le.
Applying option ac (set number of audio channels) with argument 2.
Successfully parsed a group of options.
Opening an output file: out.wav.
[file @ 000001d0e7c06200] Setting default whitelist 'file,crypto,data'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[mpegts @ 000001d0e7bbd200] Skipping after seek
[mpegts @ 000001d0e7bbd200] SDT:
[mpegts @ 000001d0e7bbd200] tag: 0x48 len=18
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] PAT:
[mpegts @ 000001d0e7bbd200] sid=0x1 pid=0x1000
[mpegts @ 000001d0e7bbd200] new_program: id=0x0001
[mpegts @ 000001d0e7bbd200] PMT: len 21
[mpegts @ 000001d0e7bbd200] sid=0x1 sec_num=0/0 version=0 tid=2
[mpegts @ 000001d0e7bbd200] pcr_pid=0x100
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
detected 4 logical cores
[Parsed_aresample_0 @ 000001d0e7be5e80] Setting 'async' to value '1'
[graph_0_in_0_0 @ 000001d0e7beeac0] Setting 'time_base' to value '1/44100'
[graph_0_in_0_0 @ 000001d0e7beeac0] Setting 'sample_rate' to value '44100'
[graph_0_in_0_0 @ 000001d0e7beeac0] Setting 'sample_fmt' to value 'fltp'
[graph_0_in_0_0 @ 000001d0e7beeac0] Setting 'channel_layout' to value '0x3'
[graph_0_in_0_0 @ 000001d0e7beeac0] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
[format_out_0_0 @ 000001d0e7bf0080] Setting 'sample_fmts' to value 's16'
[format_out_0_0 @ 000001d0e7bf0080] Setting 'channel_layouts' to value '0x3'
[AVFilterGraph @ 000001d0e7be6540] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed
[Parsed_aresample_0 @ 000001d0e7be5e80] [SWR @ 000001d0e81bb8c0] Using fltp internally between filters
[Parsed_aresample_0 @ 000001d0e7be5e80] ch:2 chl:stereo fmt:fltp r:44100Hz -> ch:2 chl:stereo fmt:s16 r:44100Hz
Output #0, wav, to 'out.wav':
  Metadata:
    ISFT            : Lavf58.45.100
    Stream #0:0, 0, 1/44100: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc58.91.100 pcm_s16le
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 7 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
(...)
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 4 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
timestamp discontinuity for stream #0:0 (id=256, type=audio): 69892061, new offset= -71292061
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
[aac @ 000001d0e7c0ed80] illegal icc
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 7 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
[mpegts @ 000001d0e7bbd200] pid=100 pes_code=0x1c0
[aac @ 000001d0e7c0ed80] ChannelElement 1.0 missing
    Last message repeated 9 times
(...)
size=    5000kB time=00:00:29.02 bitrate=1411.2kbits/s speed=6.11x
video:0kB audio:5000kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.001523%
Input file #0 (http://tyberis.com/KFYI-AM_2020-10-30_09-05-26.ts):
  Input stream #0:0 (audio): 625 packets read (174267 bytes); 625 frames decoded (1280000 samples);
  Total: 625 packets (174267 bytes) demuxed
Output file #0 (out.wav):
  Output stream #0:0 (audio): 625 frames encoded (1280000 samples); 625 packets muxed (5120000 bytes);
  Total: 625 packets (5120000 bytes) muxed
625 frames successfully decoded, 0 decoding errors
[AVIOContext @ 000001d0e7c2e280] Statistics: 4 seeks, 22 writeouts
[AVIOContext @ 000001d0e7bc9780] Statistics: 533494 bytes read, 3 seeks```


    


  • how to extract audio from video using ffmpeg c++

    29 septembre 2020, par daenerys

    I am trying to write c++ code on how to extract audio from mp4 format file. I have compiled the examples in ffmpeg library and tried to run the demuxing_decoding.c file. The problem is that on running the code, it starts to decode way more than the actual file size and decodes wrong codec format (the decoded files cant be run).

    



    here is the demuxing_decoding.c that I am trying to run :

    



    #include &#xA;&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavutil></libavutil>channel_layout.h>&#xA;#include <libavutil></libavutil>common.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libavutil></libavutil>mathematics.h>&#xA;#include <libavutil></libavutil>samplefmt.h>&#xA;&#xA;#define INBUF_SIZE 4096&#xA;#define AUDIO_INBUF_SIZE 20480&#xA;#define AUDIO_REFILL_THRESH 4096&#xA;&#xA;/* check that a given sample format is supported by the encoder */&#xA;static int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt)&#xA;{&#xA;    const enum AVSampleFormat *p = codec->sample_fmts;&#xA;&#xA;    while (*p != AV_SAMPLE_FMT_NONE) {&#xA;        if (*p == sample_fmt)&#xA;            return 1;&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;/* just pick the highest supported samplerate */&#xA;static int select_sample_rate(AVCodec *codec)&#xA;{&#xA;    const int *p;&#xA;    int best_samplerate = 0;&#xA;&#xA;    if (!codec->supported_samplerates)&#xA;        return 44100;&#xA;&#xA;    p = codec->supported_samplerates;&#xA;    while (*p) {&#xA;        best_samplerate = FFMAX(*p, best_samplerate);&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return best_samplerate;&#xA;}&#xA;&#xA;/* select layout with the highest channel count */&#xA;static int select_channel_layout(AVCodec *codec)&#xA;{&#xA;    const uint64_t *p;&#xA;    uint64_t best_ch_layout = 0;&#xA;    int best_nb_channels   = 0;&#xA;&#xA;    if (!codec->channel_layouts)&#xA;        return AV_CH_LAYOUT_STEREO;&#xA;&#xA;    p = codec->channel_layouts;&#xA;    while (*p) {&#xA;        int nb_channels = av_get_channel_layout_nb_channels(*p);&#xA;&#xA;        if (nb_channels > best_nb_channels) {&#xA;            best_ch_layout    = *p;&#xA;            best_nb_channels = nb_channels;&#xA;        }&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return best_ch_layout;&#xA;}&#xA;&#xA;/*&#xA; * Audio encoding example&#xA; */&#xA;static void audio_encode_example(const char *filename)&#xA;{&#xA;    AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    AVFrame *frame;&#xA;    AVPacket pkt;&#xA;    int i, j, k, ret, got_output;&#xA;    int buffer_size;&#xA;    FILE *f;&#xA;    uint16_t *samples;&#xA;    float t, tincr;&#xA;&#xA;    printf("Encode audio file %s\n", filename);&#xA;&#xA;    /* find the MP2 encoder */&#xA;    codec = avcodec_find_encoder(AV_CODEC_ID_MP2);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate audio codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* put sample parameters */&#xA;    c->bit_rate = 64000;&#xA;&#xA;    /* check that the encoder supports s16 pcm input */&#xA;    c->sample_fmt = AV_SAMPLE_FMT_S16;&#xA;    if (!check_sample_fmt(codec, c->sample_fmt)) {&#xA;        fprintf(stderr, "Encoder does not support sample format %s",&#xA;                av_get_sample_fmt_name(c->sample_fmt));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* select other audio parameters supported by the encoder */&#xA;    c->sample_rate    = select_sample_rate(codec);&#xA;    c->channel_layout = select_channel_layout(codec);&#xA;    c->channels       = av_get_channel_layout_nb_channels(c->channel_layout);&#xA;&#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "wb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* frame containing input raw audio */&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate audio frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame->nb_samples     = c->frame_size;&#xA;    frame->format         = c->sample_fmt;&#xA;    frame->channel_layout = c->channel_layout;&#xA;&#xA;    /* the codec gives us the frame size, in samples,&#xA;     * we calculate the size of the samples buffer in bytes */&#xA;    buffer_size = av_samples_get_buffer_size(NULL, c->channels, c->frame_size,&#xA;                                             c->sample_fmt, 0);&#xA;    if (buffer_size &lt; 0) {&#xA;        fprintf(stderr, "Could not get sample buffer size\n");&#xA;        exit(1);&#xA;    }&#xA;    samples = av_malloc(buffer_size);&#xA;    if (!samples) {&#xA;        fprintf(stderr, "Could not allocate %d bytes for samples buffer\n",&#xA;                buffer_size);&#xA;        exit(1);&#xA;    }&#xA;    /* setup the data pointers in the AVFrame */&#xA;    ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,&#xA;                                   (const uint8_t*)samples, buffer_size, 0);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not setup audio frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* encode a single tone sound */&#xA;    t = 0;&#xA;    tincr = 2 * M_PI * 440.0 / c->sample_rate;&#xA;    for (i = 0; i &lt; 200; i&#x2B;&#x2B;) {&#xA;        av_init_packet(&amp;pkt);&#xA;        pkt.data = NULL; // packet data will be allocated by the encoder&#xA;        pkt.size = 0;&#xA;&#xA;        for (j = 0; j &lt; c->frame_size; j&#x2B;&#x2B;) {&#xA;            samples[2*j] = (int)(sin(t) * 10000);&#xA;&#xA;            for (k = 1; k &lt; c->channels; k&#x2B;&#x2B;)&#xA;                samples[2*j &#x2B; k] = samples[2*j];&#xA;            t &#x2B;= tincr;&#xA;        }&#xA;        /* encode the samples */&#xA;        ret = avcodec_encode_audio2(c, &amp;pkt, frame, &amp;got_output);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error encoding audio frame\n");&#xA;            exit(1);&#xA;        }&#xA;        if (got_output) {&#xA;            fwrite(pkt.data, 1, pkt.size, f);&#xA;            av_free_packet(&amp;pkt);&#xA;        }&#xA;    }&#xA;&#xA;    /* get the delayed frames */&#xA;    for (got_output = 1; got_output; i&#x2B;&#x2B;) {&#xA;        ret = avcodec_encode_audio2(c, &amp;pkt, NULL, &amp;got_output);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error encoding frame\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        if (got_output) {&#xA;            fwrite(pkt.data, 1, pkt.size, f);&#xA;            av_free_packet(&amp;pkt);&#xA;        }&#xA;    }&#xA;    fclose(f);&#xA;&#xA;    av_freep(&amp;samples);&#xA;    av_frame_free(&amp;frame);&#xA;    avcodec_close(c);&#xA;    av_free(c);&#xA;}&#xA;&#xA;/*&#xA; * Audio decoding.&#xA; */&#xA;static void audio_decode_example(const char *outfilename, const char *filename)&#xA;{&#xA;    AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    int len;&#xA;    FILE *f, *outfile;&#xA;    uint8_t inbuf[AUDIO_INBUF_SIZE &#x2B; AV_INPUT_BUFFER_PADDING_SIZE];&#xA;    AVPacket avpkt;&#xA;    AVFrame *decoded_frame = NULL;&#xA;&#xA;    av_init_packet(&amp;avpkt);&#xA;&#xA;    printf("Decode audio file %s to %s\n", filename, outfilename);&#xA;&#xA;    /* find the mpeg audio decoder */&#xA;    codec = avcodec_find_decoder(AV_CODEC_ID_MP2);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate audio codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "rb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;    outfile = fopen(outfilename, "wb");&#xA;    if (!outfile) {&#xA;        av_free(c);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* decode until eof */&#xA;    avpkt.data = inbuf;&#xA;    avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);&#xA;&#xA;    while (avpkt.size > 0) {&#xA;        int i, ch;&#xA;        int got_frame = 0;&#xA;&#xA;        if (!decoded_frame) {&#xA;            if (!(decoded_frame = av_frame_alloc())) {&#xA;                fprintf(stderr, "Could not allocate audio frame\n");&#xA;                exit(1);&#xA;            }&#xA;        }&#xA;&#xA;        len = avcodec_decode_audio4(c, decoded_frame, &amp;got_frame, &amp;avpkt);&#xA;        if (len &lt; 0) {&#xA;            fprintf(stderr, "Error while decoding\n");&#xA;            exit(1);&#xA;        }&#xA;        if (got_frame) {&#xA;            /* if a frame has been decoded, output it */&#xA;            int data_size = av_get_bytes_per_sample(c->sample_fmt);&#xA;            if (data_size &lt; 0) {&#xA;                /* This should not occur, checking just for paranoia */&#xA;                fprintf(stderr, "Failed to calculate data size\n");&#xA;                exit(1);&#xA;            }&#xA;            for (i=0; inb_samples; i&#x2B;&#x2B;)&#xA;                for (ch=0; chchannels; ch&#x2B;&#x2B;)&#xA;                    fwrite(decoded_frame->data[ch] &#x2B; data_size*i, 1, data_size, outfile);&#xA;        }&#xA;        avpkt.size -= len;&#xA;        avpkt.data &#x2B;= len;&#xA;        avpkt.dts =&#xA;        avpkt.pts = AV_NOPTS_VALUE;&#xA;        if (avpkt.size &lt; AUDIO_REFILL_THRESH) {&#xA;            /* Refill the input buffer, to avoid trying to decode&#xA;             * incomplete frames. Instead of this, one could also use&#xA;             * a parser, or use a proper container format through&#xA;             * libavformat. */&#xA;            memmove(inbuf, avpkt.data, avpkt.size);&#xA;            avpkt.data = inbuf;&#xA;            len = fread(avpkt.data &#x2B; avpkt.size, 1,&#xA;                        AUDIO_INBUF_SIZE - avpkt.size, f);&#xA;            if (len > 0)&#xA;                avpkt.size &#x2B;= len;&#xA;        }&#xA;    }&#xA;&#xA;    fclose(outfile);&#xA;    fclose(f);&#xA;&#xA;    avcodec_close(c);&#xA;    av_free(c);&#xA;    av_frame_free(&amp;decoded_frame);&#xA;}&#xA;&#xA;/*&#xA; * Video encoding example&#xA; */&#xA;static void video_encode_example(const char *filename, int codec_id)&#xA;{&#xA;    AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    int i, ret, x, y, got_output;&#xA;    FILE *f;&#xA;    AVFrame *frame;&#xA;    AVPacket pkt;&#xA;    uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;&#xA;    printf("Encode video file %s\n", filename);&#xA;&#xA;    /* find the mpeg1 video encoder */&#xA;    codec = avcodec_find_encoder(codec_id);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate video codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* put sample parameters */&#xA;    c->bit_rate = 400000;&#xA;    /* resolution must be a multiple of two */&#xA;    c->width = 352;&#xA;    c->height = 288;&#xA;    /* frames per second */&#xA;    c->time_base = (AVRational){1,25};&#xA;    /* emit one intra frame every ten frames&#xA;     * check frame pict_type before passing frame&#xA;     * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I&#xA;     * then gop_size is ignored and the output of encoder&#xA;     * will always be I frame irrespective to gop_size&#xA;     */&#xA;    c->gop_size = 10;&#xA;    c->max_b_frames = 1;&#xA;    c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;&#xA;    if (codec_id == AV_CODEC_ID_H264)&#xA;        av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;&#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "wb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;    frame->format = c->pix_fmt;&#xA;    frame->width  = c->width;&#xA;    frame->height = c->height;&#xA;&#xA;    /* the image can be allocated by any means and av_image_alloc() is&#xA;     * just the most convenient way if av_malloc() is to be used */&#xA;    ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,&#xA;                         c->pix_fmt, 32);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not allocate raw picture buffer\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* encode 1 second of video */&#xA;    for (i = 0; i &lt; 25; i&#x2B;&#x2B;) {&#xA;        av_init_packet(&amp;pkt);&#xA;        pkt.data = NULL;    // packet data will be allocated by the encoder&#xA;        pkt.size = 0;&#xA;&#xA;        fflush(stdout);&#xA;        /* prepare a dummy image */&#xA;        /* Y */&#xA;        for (y = 0; y &lt; c->height; y&#x2B;&#x2B;) {&#xA;            for (x = 0; x &lt; c->width; x&#x2B;&#x2B;) {&#xA;                frame->data[0][y * frame->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;            }&#xA;        }&#xA;&#xA;        /* Cb and Cr */&#xA;        for (y = 0; y &lt; c->height/2; y&#x2B;&#x2B;) {&#xA;            for (x = 0; x &lt; c->width/2; x&#x2B;&#x2B;) {&#xA;                frame->data[1][y * frame->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;                frame->data[2][y * frame->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;            }&#xA;        }&#xA;&#xA;        frame->pts = i;&#xA;&#xA;        /* encode the image */&#xA;        ret = avcodec_encode_video2(c, &amp;pkt, frame, &amp;got_output);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error encoding frame\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        if (got_output) {&#xA;            printf("Write frame %3d (size=%5d)\n", i, pkt.size);&#xA;            fwrite(pkt.data, 1, pkt.size, f);&#xA;            av_free_packet(&amp;pkt);&#xA;        }&#xA;    }&#xA;&#xA;    /* get the delayed frames */&#xA;    for (got_output = 1; got_output; i&#x2B;&#x2B;) {&#xA;        fflush(stdout);&#xA;&#xA;        ret = avcodec_encode_video2(c, &amp;pkt, NULL, &amp;got_output);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error encoding frame\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        if (got_output) {&#xA;            printf("Write frame %3d (size=%5d)\n", i, pkt.size);&#xA;            fwrite(pkt.data, 1, pkt.size, f);&#xA;            av_free_packet(&amp;pkt);&#xA;        }&#xA;    }&#xA;&#xA;    /* add sequence end code to have a real mpeg file */&#xA;    fwrite(endcode, 1, sizeof(endcode), f);&#xA;    fclose(f);&#xA;&#xA;    avcodec_close(c);&#xA;    av_free(c);&#xA;    av_freep(&amp;frame->data[0]);&#xA;    av_frame_free(&amp;frame);&#xA;    printf("\n");&#xA;}&#xA;&#xA;/*&#xA; * Video decoding example&#xA; */&#xA;&#xA;static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,&#xA;                     char *filename)&#xA;{&#xA;    FILE *f;&#xA;    int i;&#xA;&#xA;    f = fopen(filename,"w");&#xA;    fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);&#xA;    for (i = 0; i &lt; ysize; i&#x2B;&#x2B;)&#xA;        fwrite(buf &#x2B; i * wrap, 1, xsize, f);&#xA;    fclose(f);&#xA;}&#xA;&#xA;static int decode_write_frame(const char *outfilename, AVCodecContext *avctx,&#xA;                              AVFrame *frame, int *frame_count, AVPacket *pkt, int last)&#xA;{&#xA;    int len, got_frame;&#xA;    char buf[1024];&#xA;&#xA;    len = avcodec_decode_video2(avctx, frame, &amp;got_frame, pkt);&#xA;    if (len &lt; 0) {&#xA;        fprintf(stderr, "Error while decoding frame %d\n", *frame_count);&#xA;        return len;&#xA;    }&#xA;    if (got_frame) {&#xA;        printf("Saving %sframe %3d\n", last ? "last " : "", *frame_count);&#xA;        fflush(stdout);&#xA;&#xA;        /* the picture is allocated by the decoder, no need to free it */&#xA;        snprintf(buf, sizeof(buf), outfilename, *frame_count);&#xA;        pgm_save(frame->data[0], frame->linesize[0],&#xA;                 frame->width, frame->height, buf);&#xA;        (*frame_count)&#x2B;&#x2B;;&#xA;    }&#xA;    if (pkt->data) {&#xA;        pkt->size -= len;&#xA;        pkt->data &#x2B;= len;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;static void video_decode_example(const char *outfilename, const char *filename)&#xA;{&#xA;    AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    int frame_count;&#xA;    FILE *f;&#xA;    AVFrame *frame;&#xA;    uint8_t inbuf[INBUF_SIZE &#x2B; AV_INPUT_BUFFER_PADDING_SIZE];&#xA;    AVPacket avpkt;&#xA;&#xA;    av_init_packet(&amp;avpkt);&#xA;&#xA;    /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */&#xA;    memset(inbuf &#x2B; INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);&#xA;&#xA;    printf("Decode video file %s to %s\n", filename, outfilename);&#xA;&#xA;    /* find the mpeg1 video decoder */&#xA;    codec = avcodec_find_decoder(AV_CODEC_ID_MPEG1VIDEO);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate video codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    if (codec->capabilities &amp; AV_CODEC_CAP_TRUNCATED)&#xA;        c->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames&#xA;&#xA;    /* For some codecs, such as msmpeg4 and mpeg4, width and height&#xA;       MUST be initialized there because this information is not&#xA;       available in the bitstream. */&#xA;&#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "rb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame_count = 0;&#xA;    for (;;) {&#xA;        avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);&#xA;        if (avpkt.size == 0)&#xA;            break;&#xA;&#xA;        /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)&#xA;           and this is the only method to use them because you cannot&#xA;           know the compressed data size before analysing it.&#xA;&#xA;           BUT some other codecs (msmpeg4, mpeg4) are inherently frame&#xA;           based, so you must call them with all the data for one&#xA;           frame exactly. You must also initialize &#x27;width&#x27; and&#xA;           &#x27;height&#x27; before initializing them. */&#xA;&#xA;        /* NOTE2: some codecs allow the raw parameters (frame size,&#xA;           sample rate) to be changed at any frame. We handle this, so&#xA;           you should also take care of it */&#xA;&#xA;        /* here, we use a stream based decoder (mpeg1video), so we&#xA;           feed decoder and see if it could decode a frame */&#xA;        avpkt.data = inbuf;&#xA;        while (avpkt.size > 0)&#xA;            if (decode_write_frame(outfilename, c, frame, &amp;frame_count, &amp;avpkt, 0) &lt; 0)&#xA;                exit(1);&#xA;    }&#xA;&#xA;    /* some codecs, such as MPEG, transmit the I and P frame with a&#xA;       latency of one frame. You must do the following to have a&#xA;       chance to get the last frame of the video */&#xA;    avpkt.data = NULL;&#xA;    avpkt.size = 0;&#xA;    decode_write_frame(outfilename, c, frame, &amp;frame_count, &amp;avpkt, 1);&#xA;&#xA;    fclose(f);&#xA;&#xA;    avcodec_close(c);&#xA;    av_free(c);&#xA;    av_frame_free(&amp;frame);&#xA;    printf("\n");&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const char *output_type;&#xA;&#xA;    /* register all the codecs */&#xA;    avcodec_register_all();&#xA;&#xA;    if (argc &lt; 2) {&#xA;        printf("usage: %s output_type\n"&#xA;               "API example program to decode/encode a media stream with libavcodec.\n"&#xA;               "This program generates a synthetic stream and encodes it to a file\n"&#xA;               "named test.h264, test.mp2 or test.mpg depending on output_type.\n"&#xA;               "The encoded stream is then decoded and written to a raw data output.\n"&#xA;               "output_type must be chosen between &#x27;h264&#x27;, &#x27;mp2&#x27;, &#x27;mpg&#x27;.\n",&#xA;               argv[0]);&#xA;        return 1;&#xA;    }&#xA;    output_type = argv[1];&#xA;&#xA;    if (!strcmp(output_type, "h264")) {&#xA;        video_encode_example("test.h264", AV_CODEC_ID_H264);&#xA;    } else if (!strcmp(output_type, "mp2")) {&#xA;        audio_encode_example("test.mp2");&#xA;        audio_decode_example("test.pcm", "test.mp2");&#xA;    } else if (!strcmp(output_type, "mpg")) {&#xA;        video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO);&#xA;        video_decode_example("test%02d.pgm", "test.mpg");&#xA;    } else {&#xA;        fprintf(stderr, "Invalid output type &#x27;%s&#x27;, choose between &#x27;h264&#x27;, &#x27;mp2&#x27;, or &#x27;mpg&#x27;\n",&#xA;                output_type);&#xA;        return 1;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;&#xA;

    What could be wrong ?&#xA;The command I used is :

    &#xA;&#xA;

    ./demuxing_decoding /home/cortana/Burn.mp4 /home/cortana/Desktop/Burn.mp4 /home/cortana/Desktop/Burn.aac&#xA;

    &#xA;

  • FFMPEG API Mp4 H264 Encoding/Muxing - unspecified pixel format

    28 juillet 2020, par Fabrice

    I'm working on a c++ project using ffmpeg. I have to generate an mp4 file with h264 encoding.

    &#xA;

    My problem is that the file generate but when reading the file with VLC I've got no image, and analyzing it with ffprobe give me (log below) the error :

    &#xA;

    &#xA;

    unspecified pixel format

    &#xA;

    &#xA;

    ffprobe version N-93020-g3224d6691c Copyright (c) 2007-2019 the FFmpeg developers&#xA;  built with gcc 8.2.1 (GCC) 20181201&#xA;  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt&#xA;  libavutil      56. 26.100 / 56. 26.100&#xA;  libavcodec     58. 44.100 / 58. 44.100&#xA;  libavformat    58. 26.100 / 58. 26.100&#xA;  libavdevice    58.  6.101 / 58.  6.101&#xA;  libavfilter     7. 48.100 /  7. 48.100&#xA;  libswscale      5.  4.100 /  5.  4.100&#xA;  libswresample   3.  4.100 /  3.  4.100&#xA;  libpostproc    55.  4.100 / 55.  4.100&#xA;[h264 @ 02a46240] non-existing PPS 0 referenced&#xA;[h264 @ 02a46240] decode_slice_header error&#xA;[h264 @ 02a46240] no frame!&#xA;...&#xA;[h264 @ 02a46240] non-existing PPS 0 referenced&#xA;[h264 @ 02a46240] decode_slice_header error&#xA;[h264 @ 02a46240] no frame!&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 02a35380] decoding for stream 0 failed&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 02a35380] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 352x288, 320 kb/s): unspecified pixel format&#xA;Consider increasing the value for the &#x27;analyzeduration&#x27; and &#x27;probesize&#x27; options&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;C:\Users\Fabrice\Desktop\video\Test.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 512&#xA;    compatible_brands: isomiso2avc1mp41&#xA;    encoder         : Lavf58.26.100&#xA;  Duration: 00:00:09.00, start: 0.000000, bitrate: 323 kb/s&#xA;    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 352x288, 320 kb/s, 25.11 fps, 25 tbr, 12800 tbn, 25600 tbc (default)&#xA;    Metadata:&#xA;      handler_name    : VideoHandler&#xA;

    &#xA;

    Here is the code I use to genererate my mp4 File, it's based on sample from ffmpeg (see : FFMPEG Muxing sample). I have tried to adapt it without using deprecated function. It works using webm/vp8 encoding, but not mp4/h264.

    &#xA;

    #include &#xA;#include &#xA;#include &#xA;extern "C"&#xA;{&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>error.h> &#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;}&#xA;&#xA;#pragma comment(lib, "avcodec.lib")&#xA;#pragma comment(lib, "swscale.lib")&#xA;#pragma comment(lib, "avformat.lib")&#xA;#pragma comment(lib, "avutil.lib")&#xA;&#xA;/* 10 seconds stream duration */&#xA;#define STREAM_DURATION   10.0&#xA;#define STREAM_FRAME_RATE 25 /* 25 images/s */&#xA;#define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))&#xA;#define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */&#xA;&#xA;//#pragma warning(disable : 4996) // TODO: remove&#xA;&#xA;static int sws_flags = SWS_BICUBIC;&#xA;&#xA;/* Add an output stream. */&#xA;static AVStream *add_stream(AVFormatContext *formatContext, AVCodec **codec, enum AVCodecID codecId, AVCodecContext **codecCtx)&#xA;{&#xA;    AVStream *stream;&#xA;&#xA;    // Get the encoder codec&#xA;    *codec = avcodec_find_encoder(codecId);&#xA;    if (!(*codec)) {&#xA;        fprintf(stderr, "Could not find encoder for &#x27;%s&#x27;\n",&#xA;            avcodec_get_name(codecId));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    // Get the stream for codec&#xA;    stream = avformat_new_stream(formatContext, *codec);&#xA;    if (!stream) {&#xA;        fprintf(stderr, "Could not allocate stream\n");&#xA;        exit(1);&#xA;    }&#xA;    stream->id = formatContext->nb_streams - 1;&#xA;&#xA;    (*codecCtx) = avcodec_alloc_context3(*codec);&#xA;&#xA;    switch ((*codec)->type) {&#xA;    case AVMEDIA_TYPE_VIDEO:&#xA;        stream->codecpar->codec_id = codecId;&#xA;        stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;        stream->codecpar->bit_rate = 400000;&#xA;        stream->codecpar->width = 352;&#xA;        stream->codecpar->height = 288;&#xA;        stream->codecpar->format = STREAM_PIX_FMT;&#xA;        stream->time_base = { 1, STREAM_FRAME_RATE };&#xA;&#xA;        avcodec_parameters_to_context((*codecCtx), stream->codecpar);&#xA;        (*codecCtx)->gop_size = 12; /* emit one intra frame every twelve frames at most */&#xA;        (*codecCtx)->max_b_frames = 2;&#xA;        (*codecCtx)->time_base = { 1, STREAM_FRAME_RATE };&#xA;        if ((*codecCtx)->codec_id == AV_CODEC_ID_MPEG1VIDEO) {&#xA;            /* Needed to avoid using macroblocks in which some coeffs overflow.&#xA;             * This does not happen with normal video, it just happens here as&#xA;             * the motion of the chroma plane does not match the luma plane. */&#xA;            (*codecCtx)->mb_decision = 2;&#xA;        }&#xA;        break;&#xA;&#xA;    default:&#xA;        break;&#xA;    }&#xA;    &#xA;    //if (stream->codecpar->codec_id == AV_CODEC_ID_H264) {&#xA;    //  av_opt_set(codecCtx, "preset", "ultrafast", 0);&#xA;    //}&#xA;    //(*codecCtx)->flags |= AV_CODEC_FLAG_LOW_DELAY;&#xA;&#xA;    /* Some formats want stream headers to be separate. */&#xA;    if (formatContext->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;        (*codecCtx)->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;&#xA;    int ret = avcodec_parameters_from_context(stream->codecpar, (*codecCtx));&#xA;    if (ret &lt; 0) {&#xA;        char error[255];&#xA;        av_strerror(ret, error, 255);&#xA;        fprintf(stderr, "avcodec_parameters_from_context returned (%d) - %s", ret, error);&#xA;        return false;&#xA;    }&#xA;&#xA;    return stream;&#xA;}&#xA;&#xA;/**************************************************************/&#xA;/* video output */&#xA;&#xA;static AVFrame *frame_video;&#xA;static int frame_count;&#xA;&#xA;static void open_video(AVCodec *codec, AVStream *stream, AVCodecContext *codecCtx)&#xA;{&#xA;    int ret;&#xA;&#xA;    /* open the codec */&#xA;    ret = avcodec_open2(codecCtx, codec, NULL);&#xA;    if (ret &lt; 0) {&#xA;        char error[255];&#xA;        av_strerror(ret, error, 255);&#xA;        fprintf(stderr, "Could not open video codec: %s\n", error);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* allocate and init a re-usable frame */&#xA;    frame_video = av_frame_alloc();&#xA;    if (!frame_video) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame_video->format = codecCtx->pix_fmt;&#xA;    frame_video->width = codecCtx->width;&#xA;    frame_video->height = codecCtx->height;&#xA;&#xA;    ret = av_frame_get_buffer(frame_video, 32);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not allocate the video frame data\n");&#xA;        exit(1);&#xA;    }&#xA;}&#xA;&#xA;/* Prepare a dummy image. */&#xA;static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height)&#xA;{&#xA;    int x, y, i;&#xA;&#xA;    i = frame_index;&#xA;&#xA;    /* Y */&#xA;    for (y = 0; y &lt; height; y&#x2B;&#x2B;)&#xA;        for (x = 0; x &lt; width; x&#x2B;&#x2B;)&#xA;            pict->data[0][y * pict->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;&#xA;    /* Cb and Cr */&#xA;    for (y = 0; y &lt; height / 2; y&#x2B;&#x2B;) {&#xA;        for (x = 0; x &lt; width / 2; x&#x2B;&#x2B;) {&#xA;            pict->data[1][y * pict->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;            pict->data[2][y * pict->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;int timestamp = 0;&#xA;static void write_video_frame(AVFormatContext *formatContext, AVStream *stream, AVCodecContext *codecCtx)&#xA;{&#xA;    int ret;&#xA;    static struct SwsContext *sws_ctx;&#xA;&#xA;    if (frame_count >= STREAM_NB_FRAMES) {&#xA;        /* No more frames to compress. The codec has a latency of a few&#xA;         * frames if using B-frames, so we get the last frames by&#xA;         * passing the same picture again. */&#xA;    }&#xA;    else {&#xA;        if (codecCtx->pix_fmt != AV_PIX_FMT_YUV420P) {&#xA;            /* as we only generate a YUV420P picture, we must convert it&#xA;             * to the codec pixel format if needed */&#xA;            if (!sws_ctx) {&#xA;                sws_ctx = sws_getContext(codecCtx->width, codecCtx->height, AV_PIX_FMT_YUV420P,&#xA;                    codecCtx->width, codecCtx->height, codecCtx->pix_fmt,&#xA;                    sws_flags, NULL, NULL, NULL);&#xA;                if (!sws_ctx) {&#xA;                    fprintf(stderr, "Could not initialize the conversion context\n");&#xA;                    exit(1);&#xA;                }&#xA;            }&#xA;            fill_yuv_image(frame_video, frame_count, codecCtx->width, codecCtx->height);&#xA;            sws_scale(sws_ctx, (const uint8_t * const *)frame_video->data, frame_video->linesize,&#xA;                0, codecCtx->height, frame_video->data, frame_video->linesize);&#xA;        }&#xA;        else {&#xA;            fill_yuv_image(frame_video, frame_count, codecCtx->width, codecCtx->height);&#xA;        }&#xA;    }&#xA;&#xA;    frame_video->format = AV_PIX_FMT_YUV420P;&#xA;    frame_video->width = codecCtx->width;&#xA;    frame_video->height = codecCtx->height;&#xA;&#xA;    if (formatContext->oformat->flags &amp; 0x0020) {&#xA;        /* Raw video case - directly store the picture in the packet */&#xA;        AVPacket pkt;&#xA;        av_init_packet(&amp;pkt);&#xA;&#xA;        pkt.flags |= AV_PKT_FLAG_KEY;&#xA;        pkt.stream_index = stream->index;&#xA;        pkt.data = frame_video->data[0];&#xA;        pkt.size = sizeof(AVPicture);&#xA;&#xA;        ret = av_interleaved_write_frame(formatContext, &amp;pkt);&#xA;    }&#xA;    else {&#xA;        AVPacket pkt = { 0 };&#xA;        av_init_packet(&amp;pkt);&#xA;&#xA;        /* encode the image */&#xA;        fprintf(stderr, "\nFrame type : %c\n", av_get_picture_type_char(frame_video->pict_type));&#xA;        fprintf(stderr, "Frame pts: %lld, \n", frame_video->pts);&#xA;        fprintf(stderr, "Codec timebase: %d/%d\n", codecCtx->time_base.num, codecCtx->time_base.den);&#xA;        fprintf(stderr, "Stream timebase: %d/%d\n", stream->time_base.num, stream->time_base.den);&#xA;        fprintf(stderr, "Resacale: %lld, \n\n", av_rescale_q(1, codecCtx->time_base, stream->time_base));&#xA;        ret = avcodec_send_frame(codecCtx, frame_video);&#xA;        if (ret &lt; 0) {&#xA;            char error[255];&#xA;            av_strerror(ret, error, 255);&#xA;            fprintf(stderr, "Error encoding video frame: %s\n", error);&#xA;            exit(1);&#xA;        }&#xA;        /* If size is zero, it means the image was buffered. */&#xA;        ret = avcodec_receive_packet(codecCtx, &amp;pkt);&#xA;        if (!ret &amp;&amp; pkt.size) {&#xA;            pkt.stream_index = stream->index;&#xA;            fprintf(stderr, "Packet flags : %d\n", pkt.flags);&#xA;            fprintf(stderr, "Packet pts: %lld\n", pkt.pts);&#xA;            fprintf(stderr, "Packet dts: %lld\n", pkt.dts);&#xA;            fprintf(stderr, "Packet duration: %lld\n", pkt.duration);&#xA;            fprintf(stderr, "Packet pos: %lld\n\n", pkt.pos);&#xA;            &#xA;            /* Write the compressed frame to the media file. */&#xA;            ret = av_interleaved_write_frame(formatContext, &amp;pkt);&#xA;        }&#xA;        else {&#xA;            ret = 0;&#xA;        }&#xA;    }&#xA;    if (ret != 0) {&#xA;        char error[255];&#xA;        av_strerror(ret, error, 255);&#xA;        fprintf(stderr, "Error while writing video frame: %s\n", error);&#xA;        exit(1);&#xA;    }&#xA;    frame_count&#x2B;&#x2B;;&#xA;}&#xA;&#xA;static void close_video(AVFormatContext *oc, AVStream *st)&#xA;{&#xA;    av_free(frame_video->data[0]);&#xA;    av_free(frame_video);&#xA;}&#xA;&#xA;/**************************************************************/&#xA;/* media file output */&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    // The outputed media&#xA;    char filename[100];&#xA;    const char *mediaFormat = "mp4"; AVCodecID mediaVideoCodec = AV_CODEC_ID_H264;&#xA;    //const char *mediaFormat="webm"; AVCodecID mediaVideoCodec = AV_CODEC_ID_VP8;&#xA;    AVOutputFormat *formatOut;&#xA;    AVFormatContext *formatCtx;&#xA;&#xA;    // The video stream&#xA;    AVStream *stream_video;&#xA;    AVCodec *codec_video = nullptr;&#xA;    AVCodecContext *codecCtx_video = nullptr;&#xA;    double time_video = 0;&#xA;&#xA;    // Return code&#xA;    int ret;&#xA;&#xA;    strcpy_s(filename, "C:\\Test.");&#xA;    strcat_s(filename, mediaFormat);&#xA;&#xA;    // allocate the output media context&#xA;    avformat_alloc_output_context2(&amp;formatCtx, NULL, NULL, filename);&#xA;    if (!formatCtx) {&#xA;        return 1;&#xA;    }&#xA;    formatOut = formatCtx->oformat;&#xA;&#xA;    // Add the video stream using H264 codec&#xA;    stream_video = NULL;&#xA;    stream_video = add_stream(formatCtx, &amp;codec_video, mediaVideoCodec, &amp;codecCtx_video);&#xA;&#xA;    // Open video codec and allocate the necessary encode buffers&#xA;    if (stream_video)&#xA;        open_video(codec_video, stream_video, codecCtx_video);&#xA;&#xA;    av_dump_format(formatCtx, 0, filename, 1);&#xA;&#xA;    // Open the output media file, if needed&#xA;    if (!(formatOut->flags &amp; AVFMT_NOFILE)) {&#xA;        ret = avio_open(&amp;formatCtx->pb, filename, AVIO_FLAG_WRITE);&#xA;        if (ret &lt; 0) {&#xA;            char error[255];&#xA;            av_strerror(ret, error, 255);&#xA;            fprintf(stderr, "Could not open &#x27;%s&#x27;: %s\n", filename, error);&#xA;            return 1;&#xA;        }&#xA;    }&#xA;&#xA;    // Write media header&#xA;    ret = avformat_write_header(formatCtx, NULL);&#xA;    if (ret &lt; 0) {&#xA;        char error[255];&#xA;        av_strerror(ret, error, 255);&#xA;        fprintf(stderr, "Error occurred when opening output file: %s\n", error);&#xA;        return 1;&#xA;    }&#xA;&#xA;    if (frame_video)&#xA;        frame_video->pts = 0;&#xA;    for (;;) {&#xA;        // Compute video time from last added video frame&#xA;        time_video = ((double)frame_video->pts) * av_q2d(stream_video->time_base);&#xA;&#xA;        // Stop media if enough time&#xA;        if (!stream_video || time_video >= STREAM_DURATION)&#xA;            break;&#xA;&#xA;        // Add a video frame&#xA;        write_video_frame(formatCtx, stream_video, codecCtx_video);&#xA;&#xA;        // Increase frame pts according to time base&#xA;        frame_video->pts &#x2B;= av_rescale_q(1, codecCtx_video->time_base, stream_video->time_base);&#xA;    }&#xA;&#xA;    // Write media trailer&#xA;    av_write_trailer(formatCtx);&#xA;&#xA;    /* Close each codec. */&#xA;    if (stream_video)&#xA;        close_video(formatCtx, stream_video);&#xA;&#xA;    if (!(formatOut->flags &amp; AVFMT_NOFILE))&#xA;        /* Close the output file. */&#xA;        avio_close(formatCtx->pb);&#xA;&#xA;    /* free the stream */&#xA;    avformat_free_context(formatCtx);&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    What am I missing ? Which part give me this error ?

    &#xA;