
Recherche avancée
Autres articles (99)
-
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
Multilang : améliorer l’interface pour les blocs multilingues
18 février 2011, parMultilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela. -
L’agrémenter visuellement
10 avril 2011MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.
Sur d’autres sites (11751)
-
FFMPEG recode clip1 to match clip2 for concat demux
21 novembre 2020, par Gert GottschalkI want to concat two video clips using ffmpeg concat. To use concat demuxer both should have same codec settings. clip2 is much shorter so I want to recode it to match clip1. Initially clip2 had tbn not matching and I adjusted that with '-video_track_timescale 50000'. Still the concat video after the cut into clip2 is garbled (audio seems OK)


This is what ffprobe tells for clip1 :


ffprobe version N-80251-g0c7fa15 Copyright (c) 2007-2016 the FFmpeg developers
 built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
 configuration: --prefix=/home/tools/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/tools/ffmpeg_build/include --extra-ldflags=-L/home/tools/ffmpeg_build/lib --bindir=/home/tools/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
 libavutil 55. 24.100 / 55. 24.100
 libavcodec 57. 45.100 / 57. 45.100
 libavformat 57. 37.101 / 57. 37.101
 libavdevice 57. 0.101 / 57. 0.101
 libavfilter 6. 46.101 / 6. 46.101
 libswscale 4. 1.100 / 4. 1.100
 libswresample 2. 0.101 / 2. 0.101
 libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip1.mp4':
 Metadata:
 major_brand : isom
 minor_version : 1
 compatible_brands: isomavc1
 creation_time : 2020-11-09 01:16:52
 Duration: 01:23:09.33, start: 0.000000, bitrate: 2279 kb/s
 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2080 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
 Metadata:
 creation_time : 2020-11-09 01:16:52
 handler_name : 11.07_21-45_ard_90_TVOON_DE.mpg.HD_video.h264@GPAC0.5.2-DEV-revVersion: 0.5.2-426-gc5ad4e4+dfsg5-1ubuntu0.1
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
 Metadata:
 creation_time : 2020-11-09 01:17:45
 handler_name : 11.07_21-45_ard_90_TVOON_DE.mpg.HD.aac@GPAC0.5.2-DEV-revVersion: 0.5.2-426-gc5ad4e4+dfsg5-1ubuntu0.1



From clip2


ffprobe version N-80251-g0c7fa15 Copyright (c) 2007-2016 the FFmpeg developers
 built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
 configuration: --prefix=/home/tools/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/tools/ffmpeg_build/include --extra-ldflags=-L/home/tools/ffmpeg_build/lib --bindir=/home/tools/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
 libavutil 55. 24.100 / 55. 24.100
 libavcodec 57. 45.100 / 57. 45.100
 libavformat 57. 37.101 / 57. 37.101
 libavdevice 57. 0.101 / 57. 0.101
 libavfilter 6. 46.101 / 6. 46.101
 libswscale 4. 1.100 / 4. 1.100
 libswresample 2. 0.101 / 2. 0.101
 libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip2.mp4':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 encoder : Lavf57.37.101
 comment : 
 Duration: 00:18:42.02, start: 0.000000, bitrate: 1693 kb/s
 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1553 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
 Metadata:
 handler_name : VideoHandler
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s (default)
 Metadata:
 handler_name : SoundHandler



Then for concat :


/home/tools/bin/ffmpeg -f concat -i list.files -y clip12.mp4



The only gap is with
clip1 : 2080 kb/s
clip2 : 1553 kb/s


Is that significant ?


If yes, how to recode clip2 to match and result in concat clip12 being clean ?


EDIT (Per feedback from llogan) :


Probing input clips with latest ffprobe.


Clip1 :


ffprobe version N-54874-ga1553b0cfb-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2007-2020 the FFmpeg developers
 built with gcc 8 (Debian 8.3.0-6)
 configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
 libavutil 56. 60.100 / 56. 60.100
 libavcodec 58.112.101 / 58.112.101
 libavformat 58. 64.100 / 58. 64.100
 libavdevice 58. 11.102 / 58. 11.102
 libavfilter 7. 88.102 / 7. 88.102
 libswscale 5. 8.100 / 5. 8.100
 libswresample 3. 8.100 / 3. 8.100
 libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip1.mp4':
 Metadata:
 major_brand : isom
 minor_version : 1
 compatible_brands: isomavc1
 creation_time : 2020-11-09T01:16:52.000000Z
 Duration: 01:23:09.33, start: 0.000000, bitrate: 2279 kb/s
 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2080 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
 Metadata:
 creation_time : 2020-11-09T01:16:52.000000Z
 handler_name : 11.07_21-45_ard_90_TVOON_DE.mpg.HD_video.h264@GPAC0.5.2-DEV-revVersion: 0.5.2-426-gc5ad4e4+dfsg5-1ubuntu0.1
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
 Metadata:
 creation_time : 2020-11-09T01:17:45.000000Z
 handler_name : 11.07_21-45_ard_90_TVOON_DE.mpg.HD.aac@GPAC0.5.2-DEV-revVersion: 0.5.2-426-gc5ad4e4+dfsg5-1ubuntu0.1



Command & log to change clip2 :


/usr/share/ffmpeg.4.3.1//ffmpeg-git-20201104-amd64-static/ffmpeg -i clip2.avi -ss 00:12:55 -t 00:05:48 -c:v libx264 -profile:v main -video_track_timescale 50k -c:a copy -y clip2.mp4 2> ffmpeg_clip2.log
ffmpeg version N-54874-ga1553b0cfb-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2020 the FFmpeg developers
 built with gcc 8 (Debian 8.3.0-6)
 configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
 libavutil 56. 60.100 / 56. 60.100
 libavcodec 58.112.101 / 58.112.101
 libavformat 58. 64.100 / 58. 64.100
 libavdevice 58. 11.102 / 58. 11.102
 libavfilter 7. 88.102 / 7. 88.102
 libswscale 5. 8.100 / 5. 8.100
 libswresample 3. 8.100 / 3. 8.100
 libpostproc 55. 8.100 / 55. 8.100
Input #0, avi, from 'clip2.avi':
 Metadata:
 comment : 
 encoder : Lavf58.42.100
 encoded_by : www.onlinetvrecorder.com
 Duration: 00:35:48.90, start: 0.000000, bitrate: 2243 kb/s
 Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 2034 kb/s, 50 fps, 50 tbr, 50 tbn, 100 tbc
 Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 192 kb/s
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
 Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A 
...
frame= 0 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A
[libx264 @ 0x71fb740] using SAR=1/1
[libx264 @ 0x71fb740] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3
[libx264 @ 0x71fb740] profile Main, level 3.2, 4:2:0, 8-bit
[libx264 @ 0x71fb740] 264 - core 161 r3027 4121277 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 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=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'clip2.mp4':
 Metadata:
 comment : 
 encoded_by : www.onlinetvrecorder.com
 encoder : Lavf58.64.100
 Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 50 fps, 50k tbn, 50 tbc
 Metadata:
 encoder : Lavc58.112.101 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
 Stream #0:1: Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
frame= 15 fps=0.4 q=0.0 size= 0kB time=00:00:00.31 bitrate= 1.2kbits/s speed=0.00806x 
...
frame=17400 fps= 73 q=-1.0 Lsize= 62382kB time=00:05:47.97 bitrate=1468.6kbits/s speed=1.47x 
video:53846kB audio:8156kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.611439%
[libx264 @ 0x71fb740] frame I:157 Avg QP:18.21 size: 42082
[libx264 @ 0x71fb740] frame P:5607 Avg QP:22.21 size: 6677
[libx264 @ 0x71fb740] frame B:11636 Avg QP:23.93 size: 953
[libx264 @ 0x71fb740] consecutive B-frames: 8.3% 6.0% 5.0% 80.8%
[libx264 @ 0x71fb740] mb I I16..4: 47.5% 0.0% 52.5%
[libx264 @ 0x71fb740] mb P I16..4: 5.7% 0.0% 1.1% P16..4: 35.4% 6.2% 3.0% 0.0% 0.0% skip:48.4%
[libx264 @ 0x71fb740] mb B I16..4: 0.2% 0.0% 0.0% B16..8: 21.0% 0.4% 0.0% direct: 0.5% skip:77.9% L0:45.1% L1:53.8% BI: 1.2%
[libx264 @ 0x71fb740] coded y,uvDC,uvAC intra: 24.6% 38.3% 6.0% inter: 2.8% 4.7% 0.0%
[libx264 @ 0x71fb740] i16 v,h,dc,p: 43% 24% 15% 18%
[libx264 @ 0x71fb740] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 20% 19% 6% 7% 6% 6% 6% 4%
[libx264 @ 0x71fb740] i8c dc,h,v,p: 57% 20% 20% 4%
[libx264 @ 0x71fb740] Weighted P-Frames: Y:0.5% UV:0.4%
[libx264 @ 0x71fb740] ref P L0: 70.3% 12.1% 14.0% 3.6% 0.0%
[libx264 @ 0x71fb740] ref B L0: 92.9% 5.9% 1.2%
[libx264 @ 0x71fb740] ref B L1: 97.5% 2.5%
[libx264 @ 0x71fb740] kb/s:1267.54



I'm observing mismatch in what I assume is the audio channel.


Clip1 :


/usr/share/ffmpeg.4.3.1//ffmpeg-git-20201104-amd64-static/ffprobe clip1.mp4
 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2080 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)



Clip2 :


/usr/share/ffmpeg.4.3.1//ffmpeg-git-20201104-amd64-static/ffprobe clip2.mp4 
 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1267 kb/s, 50 fps, 50 tbr, 50k tbn, 100 tbc (default)
 Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)



Probably need to match audio channel. I noticed that the concat too a long time. I was expecting the concat to just do copying and not re-rendering.


-
Use FFMPEG mux flv and send rtmp on IOS
5 novembre 2020, par downlossI would like to use iphone camera & microphone to capture information pushed out through FFMPEG RTMP Streaming



The following Function capture information on IOS



- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{ 
 if (connection == videoCaptureConnection)
 {
 [manager264 encoderToH264:sampleBuffer];
 }
 else if (connection == audioCaptureConnection)
 {
 [manager264 encoderToMP3:sampleBuffer];
 }
}




Initialization FFMPEG



- (int)setX264Resource
{
 Global_Variables_VVV = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 avformat_network_init();
 av_register_all();

 pFormatCtx = avformat_alloc_context();
 avformat_alloc_output_context2(&pFormatCtx, NULL, "flv", out_file);
 fmt = pFormatCtx->oformat;

 //Open output URL
 if (avio_open(&pFormatCtx->pb, out_file, AVIO_FLAG_READ_WRITE) < 0)
 {
 printf("Failed to open output file! \n");
 return -1;
 }

 /* Add the audio and video streams using the default format codecs
 * and initialize the codecs. */
 video_st = NULL;
 audio_st = NULL;
 if (fmt->video_codec != AV_CODEC_ID_NONE) {
 video_st = add_stream(pFormatCtx, &pCodec, AV_CODEC_ID_H264);
 }
 if (fmt->audio_codec != AV_CODEC_ID_NONE) {
 audio_st = add_stream(pFormatCtx, &aCodec, AV_CODEC_ID_MP3);
 }

 /* Now that all the parameters are set, we can open the audio and
 * video codecs and allocate the necessary encode buffers. */
 if (video_st)
 [self open_video:pFormatCtx avcodec:pCodec avstream:video_st];

 if (audio_st)
 [self open_audio:pFormatCtx avcodec:aCodec avstream:audio_st];

 // Show some Information
 av_dump_format(pFormatCtx, 0, out_file, 1);

 //Write File Header
 avformat_write_header(pFormatCtx, NULL);

 av_new_packet(&pkt, picture_size);
 av_new_packet(&pkt2, picture_size);

 AVCodecContext *c = video_st->codec;

 y_size = c->width * c->height;

 if (pFrame)
 pFrame->pts = 0;

 if(aFrame)
 {
 aFrame->pts = 0;
 }

 return 0;
}

static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id)
{
 AVCodecContext *c;
 AVStream *st;
 /* find the encoder */
 *codec = avcodec_find_encoder(codec_id);
 if (!(*codec))
 {
 NSLog(@"Could not find encoder for '%s'\n",
 avcodec_get_name(codec_id));
 }
 st = avformat_new_stream(oc, *codec);
 if (!st)
 {
 NSLog(@"Could not allocate stream\n");
 }
 st->id = oc->nb_streams-1;
 c = st->codec;
 switch ((*codec)->type)
 {
 case AVMEDIA_TYPE_AUDIO:
 c->codec_id = AV_CODEC_ID_MP3;
 c->codec_type = AVMEDIA_TYPE_AUDIO;
 c->channels = 1;

 c->sample_fmt = AV_SAMPLE_FMT_S16P;
 c->bit_rate = 128000;
 c->sample_rate = 44100;
 c->channel_layout = AV_CH_LAYOUT_MONO;
 break;
 case AVMEDIA_TYPE_VIDEO:
 c->codec_id = AV_CODEC_ID_H264;
 c->codec_type=AVMEDIA_TYPE_VIDEO;
 /* Resolution must be a multiple of two. */
 c->width = 720;
 c->height = 1280;
 /* timebase: This is the fundamental unit of time (in seconds) in terms
 * of which frame timestamps are represented. For fixed-fps content,
 * timebase should be 1/framerate and timestamp increments should be
 * identical to 1. */
 c->time_base.den = 30;
 c->time_base.num = 1;
 c->gop_size = 15; /* emit one intra frame every twelve frames at most */
 c->pix_fmt = PIX_FMT_YUV420P;
 c->max_b_frames = 0;
 c->bit_rate = 3000000;
 c->qmin = 10;
 c->qmax = 51;

 break;
 default:
 break;
 }
 /* Some formats want stream headers to be separate. */
 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
 c->flags |= CODEC_FLAG_GLOBAL_HEADER;
 return st;
}




SampleBuffer will turn into H264 and pushed out RTMP Streaming



- (void)encoderToH264:(CMSampleBufferRef)sampleBuffer
{
 CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
 if (CVPixelBufferLockBaseAddress(imageBuffer, 0) == kCVReturnSuccess)
 {
 UInt8 *bufferbasePtr = (UInt8 *)CVPixelBufferGetBaseAddress(imageBuffer);
 UInt8 *bufferPtr = (UInt8 *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer,0);
 UInt8 *bufferPtr1 = (UInt8 *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer,1);
 size_t buffeSize = CVPixelBufferGetDataSize(imageBuffer);
 size_t width = CVPixelBufferGetWidth(imageBuffer);
 size_t height = CVPixelBufferGetHeight(imageBuffer);
 size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
 size_t bytesrow0 = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,0);
 size_t bytesrow1 = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,1);
 size_t bytesrow2 = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,2);
 UInt8 *yuv420_data = (UInt8 *)malloc(width * height *3/ 2); // buffer to store YUV with layout YYYYYYYYUUVV


 /* convert NV12 data to YUV420*/
 UInt8 *pY = bufferPtr ;
 UInt8 *pUV = bufferPtr1;
 UInt8 *pU = yuv420_data + width*height;
 UInt8 *pV = pU + width*height/4;
 for(int i =0;i/Read raw YUV data
 picture_buf = yuv420_data;
 pFrame->data[0] = picture_buf; // Y
 pFrame->data[1] = picture_buf+ y_size; // U
 pFrame->data[2] = picture_buf+ y_size*5/4; // V

 int got_picture = 0;

 // Encode
 pFrame->width = 720;
 pFrame->height = 1280;
 pFrame->format = PIX_FMT_YUV420P;

 AVCodecContext *c = video_st->codec;
 int ret = avcodec_encode_video2(c, &pkt, pFrame, &got_picture);
 if(ret < 0)
 {
 printf("Failed to encode! \n");
 }

 if (got_picture==1)
 {
 /* Compute current audio and video time. */
 video_time = video_st ? video_st->pts.val * av_q2d(video_st->time_base) : 0.0;
 pFrame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);

 if(pkt.size != 0)
 {
 printf("Succeed to encode frame: %5lld\tsize:%5d\n", pFrame->pts, pkt.size);
 pkt.stream_index = video_st->index;
 ret = av_write_frame(pFormatCtx, &pkt);
 av_free_packet(&pkt);
 }
 }
 free(yuv420_data);
 }
 CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
}




SampleBuffer will turn into MP3 and pushed out RTMP Streaming



-(void)encoderToMP3:(CMSampleBufferRef)sampleBuffer
{
 CMSampleTimingInfo timing_info;
 CMSampleBufferGetSampleTimingInfo(sampleBuffer, 0, &timing_info);
 double pts=0;
 double dts=0;
 AVCodecContext *c;
 int got_packet, ret;
 c = audio_st->codec;
 CMItemCount numSamples = CMSampleBufferGetNumSamples(sampleBuffer);

 NSUInteger channelIndex = 0;

 CMBlockBufferRef audioBlockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);

 size_t audioBlockBufferOffset = (channelIndex * numSamples * sizeof(SInt16));
 size_t lengthAtOffset = 0;
 size_t totalLength = 0;
 SInt16 *samples = NULL;
 CMBlockBufferGetDataPointer(audioBlockBuffer, audioBlockBufferOffset, &lengthAtOffset, &totalLength, (char **)(&samples));

 const AudioStreamBasicDescription *audioDescription = CMAudioFormatDescriptionGetStreamBasicDescription(CMSampleBufferGetFormatDescription(sampleBuffer));

 SwrContext *swr = swr_alloc();

 int in_smprt = (int)audioDescription->mSampleRate;
 av_opt_set_int(swr, "in_channel_layout", AV_CH_LAYOUT_MONO, 0);
 av_opt_set_int(swr, "out_channel_layout", audio_st->codec->channel_layout, 0);

 av_opt_set_int(swr, "in_channel_count", audioDescription->mChannelsPerFrame, 0);
 av_opt_set_int(swr, "out_channel_count", 1, 0);

 av_opt_set_int(swr, "out_channel_layout", audio_st->codec->channel_layout, 0);
 av_opt_set_int(swr, "in_sample_rate", audioDescription->mSampleRate,0);

 av_opt_set_int(swr, "out_sample_rate", audio_st->codec->sample_rate,0);

 av_opt_set_sample_fmt(swr, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);

 av_opt_set_sample_fmt(swr, "out_sample_fmt", audio_st->codec->sample_fmt, 0);

 swr_init(swr);
 uint8_t **input = NULL;
 int src_linesize;
 int in_samples = (int)numSamples;
 ret = av_samples_alloc_array_and_samples(&input, &src_linesize, audioDescription->mChannelsPerFrame, in_samples, AV_SAMPLE_FMT_S16P, 0);

 *input=(uint8_t*)samples;
 uint8_t *output=NULL;

 int out_samples = av_rescale_rnd(swr_get_delay(swr, in_smprt) +in_samples, (int)audio_st->codec->sample_rate, in_smprt, AV_ROUND_UP);

 av_samples_alloc(&output, NULL, audio_st->codec->channels, out_samples, audio_st->codec->sample_fmt, 0);
 in_samples = (int)numSamples;
 out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **)input, in_samples);

 aFrame->nb_samples =(int) out_samples;

 ret = avcodec_fill_audio_frame(aFrame, audio_st->codec->channels, audio_st->codec->sample_fmt,
 (uint8_t *)output,
 (int) out_samples *
 av_get_bytes_per_sample(audio_st->codec->sample_fmt) *
 audio_st->codec->channels, 1);
 if (ret < 0)
 {
 fprintf(stderr, "Error fill audio frame: %s\n", av_err2str(ret));
 }
 aFrame->channel_layout = audio_st->codec->channel_layout;
 aFrame->channels=audio_st->codec->channels;
 aFrame->sample_rate= audio_st->codec->sample_rate;

 if (timing_info.presentationTimeStamp.timescale!=0)
 pts=(double) timing_info.presentationTimeStamp.value/timing_info.presentationTimeStamp.timescale;


 aFrame->pts = pts*audio_st->time_base.den;
 aFrame->pts = av_rescale_q(aFrame->pts, audio_st->time_base, audio_st->codec->time_base);

 ret = avcodec_encode_audio2(c, &pkt2, aFrame, &got_packet);

 if (ret < 0)
 {
 fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
 }
 swr_free(&swr);

 if (got_packet)
 {
 pkt2.stream_index = audio_st->index; 

 // Write the compressed frame to the media file.

 ret = av_interleaved_write_frame(pFormatCtx, &pkt2);
 if (ret != 0)
 {
 fprintf(stderr, "Error while writing audio frame: %s\n", av_err2str(ret));
 av_free_packet(&pkt2);
 }
 }
}




Soon "Broken pipe" problem occurs after execution.
PTS is currently feeling is not adjusted, but do not know how to adjust the PTS.



2016-03-09 16:57:41.058 PoliceCamPlayer[1004:193465] recordVideo....
[libx264 @ 0x12f8b6e00] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x12f8b6e00] profile Constrained Baseline, level 3.1
[libx264 @ 0x12f8b6e00] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=2 lookahead_threads=2 sliced_threads=1 slices=2 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=15 keyint_min=1 scenecut=40 intra_refresh=0 rc=abr mbtree=0 bitrate=3000 ratetol=1.0 qcomp=0.60 qpmin=25 qpmax=51 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://XXX.XX.XXX.XX/myapp/jackal':
 Stream #0:0: Video: h264 (libx264), yuv420p, 720x1280, q=25-51, 3000 kb/s, 23 tbc
 Stream #0:1: Audio: mp3 (libmp3lame), 44100 Hz, mono, s16p, 64 kb/s
[flv @ 0x12f8b5400] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
[flv @ 0x12f8b5400] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
[libx264 @ 0x12f8b6e00] Provided packet is too small, needs to be 33468
Failed to encode! 
Audio_pts:4154432515 pts_time:4.15443e+06 dts:4154432515 dts_time:4.15443e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:43 pts_time:0.043 dts:43 dts_time:0.043 duration:0 duration_time:0 stream_index:0
Audio_pts:4154433667 pts_time:4.15443e+06 dts:4154433667 dts_time:4.15443e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154434854 pts_time:4.15443e+06 dts:4154434854 dts_time:4.15443e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:86 pts_time:0.086 dts:86 dts_time:0.086 duration:0 duration_time:0 stream_index:0
Audio_pts:4154435996 pts_time:4.15444e+06 dts:4154435996 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154437138 pts_time:4.15444e+06 dts:4154437138 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:129 pts_time:0.129 dts:129 dts_time:0.129 duration:0 duration_time:0 stream_index:0
Audio_pts:4154438281 pts_time:4.15444e+06 dts:4154438281 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:172 pts_time:0.172 dts:172 dts_time:0.172 duration:0 duration_time:0 stream_index:0
Audio_pts:4154439467 pts_time:4.15444e+06 dts:4154439467 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:215 pts_time:0.215 dts:215 dts_time:0.215 duration:0 duration_time:0 stream_index:0
Audio_pts:4154440609 pts_time:4.15444e+06 dts:4154440609 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154441752 pts_time:4.15444e+06 dts:4154441752 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:258 pts_time:0.258 dts:258 dts_time:0.258 duration:0 duration_time:0 stream_index:0
Audio_pts:4154442884 pts_time:4.15444e+06 dts:4154442884 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154444071 pts_time:4.15444e+06 dts:4154444071 dts_time:4.15444e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:301 pts_time:0.301 dts:301 dts_time:0.301 duration:0 duration_time:0 stream_index:0
Audio_pts:4154445213 pts_time:4.15445e+06 dts:4154445213 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154446355 pts_time:4.15445e+06 dts:4154446355 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:344 pts_time:0.344 dts:344 dts_time:0.344 duration:0 duration_time:0 stream_index:0
Audio_pts:4154447498 pts_time:4.15445e+06 dts:4154447498 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:387 pts_time:0.387 dts:387 dts_time:0.387 duration:0 duration_time:0 stream_index:0
Audio_pts:4154448640 pts_time:4.15445e+06 dts:4154448640 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154449826 pts_time:4.15445e+06 dts:4154449826 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:430 pts_time:0.43 dts:430 dts_time:0.43 duration:0 duration_time:0 stream_index:0
Audio_pts:4154450969 pts_time:4.15445e+06 dts:4154450969 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154452101 pts_time:4.15445e+06 dts:4154452101 dts_time:4.15445e+06 duration:1152 duration_time:1.152 stream_index:1
...................
...................
...................
Video_pts:4343 pts_time:4.343 dts:4343 dts_time:4.343 duration:0 duration_time:0 stream_index:0
Audio_pts:4154622619 pts_time:4.15462e+06 dts:4154622619 dts_time:4.15462e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:4386 pts_time:4.386 dts:4386 dts_time:4.386 duration:0 duration_time:0 stream_index:0
Audio_pts:4154623761 pts_time:4.15462e+06 dts:4154623761 dts_time:4.15462e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154624903 pts_time:4.15462e+06 dts:4154624903 dts_time:4.15462e+06 duration:1152 duration_time:1.152 stream_index:1
Audio_pts:4154626090 pts_time:4.15463e+06 dts:4154626090 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:4429 pts_time:4.429 dts:4429 dts_time:4.429 duration:0 duration_time:0 stream_index:0
Audio_pts:4154627222 pts_time:4.15463e+06 dts:4154627222 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Video_pts:4472 pts_time:4.472 dts:4472 dts_time:4.472 duration:0 duration_time:0 stream_index:0
Error while writing audio frame: Broken pipe
Audio_pts:4154628365 pts_time:4.15463e+06 dts:4154628365 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Error while writing audio frame: Broken pipe
Audio_pts:4154629507 pts_time:4.15463e+06 dts:4154629507 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Error while writing audio frame: Broken pipe
Audio_pts:4154630693 pts_time:4.15463e+06 dts:4154630693 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Error while writing audio frame: Broken pipe
Audio_pts:4154631836 pts_time:4.15463e+06 dts:4154631836 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
Error while writing audio frame: Broken pipe
Audio_pts:4154632978 pts_time:4.15463e+06 dts:4154632978 dts_time:4.15463e+06 duration:1152 duration_time:1.152 stream_index:1
.......................
.......................
.......................
2016-03-09 16:57:49.345 PoliceCamPlayer[1004:193465] stopRecord!!!
Video_pts:7783 pts_time:7.783 dts:7783 dts_time:7.783 duration:0 duration_time:0 stream_index:0
[flv @ 0x12f8b5400] Failed to update header with correct duration.
[flv @ 0x12f8b5400] Failed to update header with correct filesize.
[libx264 @ 0x12f8b6e00] frame I:28 Avg QP:25.36 size: 24181
[libx264 @ 0x12f8b6e00] frame P:154 Avg QP:25.34 size: 6603
[libx264 @ 0x12f8b6e00] mb I I16..4: 80.9% 0.0% 19.1%
[libx264 @ 0x12f8b6e00] mb P I16..4: 5.9% 0.0% 0.2% P16..4: 28.2% 4.4% 1.0% 0.0% 0.0% skip:60.2%
[libx264 @ 0x12f8b6e00] final ratefactor: 16.70
[libx264 @ 0x12f8b6e00] coded y,uvDC,uvAC intra: 35.8% 9.3% 0.4% inter: 8.8% 1.6% 0.0%
[libx264 @ 0x12f8b6e00] i16 v,h,dc,p: 28% 26% 26% 21%
[libx264 @ 0x12f8b6e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 26% 25% 3% 7% 4% 5% 3% 13%
[libx264 @ 0x12f8b6e00] i8c dc,h,v,p: 85% 9% 5% 0%
[libx264 @ 0x12f8b6e00] kb/s:1712.63



-
FFMPEG change audio channel tag for MOV file
7 mars 2016, par Daniil ShevelevI am having difficulty renaming audio stream on MOV (works fine on MP4).
As you can see during the run it shows expected result - audio stream 2 labelled as ’div’, but when I check using ffprobe all the streams are labelled ’eng’.
Below is the code that I use.PS C:\Tools\ffmpeg-20160224-git-10fa50c-win64-static\bin> .\ffmpeg.exe -i C:\Users\dan\Downloads\IceRoadDVTest2.mov -vcodec copy -acodec copy -map 0:v:0 -map 0:a:0 -map 0:a:1 -metadata:s:a:1 language=div -qp 0 TEST2_copy.mov
ffmpeg version N-78646-g10fa50c Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enab
le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --ena
ble-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 24.106 / 57. 24.106
libavformat 57. 26.100 / 57. 26.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 35.100 / 6. 35.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Guessed Channel Layout for Input Stream #0.2 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\dan\Downloads\IceRoadDVTest2.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2015-04-23 16:12:25
com.apple.finalcutstudio.media.uuid: 34E5E804-CFCA-47F4-9F88-38A1AF158F12
Duration: 00:01:00.29, start: 0.000000, bitrate: 53086 kb/s
Stream #0:0(eng): Video: mpeg2video (4:2:2) (xd5b / 0x62356478), yuv422p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 49997 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 59.94 tbc (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
encoder : XDCAM HD422 1080i60 (50 Mb/s)
timecode : 00:00:00;00
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
Stream #0:2(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
Stream #0:3(eng): Data: none (tmcd / 0x64636D74) (default)
Metadata:
creation_time : 2015-04-23 16:12:42
handler_name : Apple Alias Data Handler
timecode : 00:00:00;00
Output #0, mov, to 'TEST2_copy.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
com.apple.finalcutstudio.media.uuid: 34E5E804-CFCA-47F4-9F88-38A1AF158F12
encoder : Lavf57.26.100
Stream #0:0(eng): Video: mpeg2video (xd5b / 0x62356478), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 49997 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 2997 tbc (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
encoder : XDCAM HD422 1080i60 (50 Mb/s)
timecode : 00:00:00;00
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, 1536 kb/s (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
Stream #0:2(div): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, 1536 kb/s (default)
Metadata:
creation_time : 2015-04-23 16:12:25
handler_name : Apple Alias Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame= 1807 fps=0.0 q=-1.0 Lsize= 390647kB time=00:01:00.29 bitrate=53076.7kbits/s speed=99.2x
video:367986kB audio:22610kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.013180%
PS C:\Tools\ffmpeg-20160224-git-10fa50c-win64-static\bin> .\ffprobe.exe .\TEST2_copy.mov
ffprobe version N-78646-g10fa50c Copyright (c) 2007-2016 the FFmpeg developers
built with gcc 5.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enab
le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --ena
ble-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 19.100 / 55. 19.100
libavcodec 57. 24.106 / 57. 24.106
libavformat 57. 26.100 / 57. 26.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 35.100 / 6. 35.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\TEST2_copy.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf57.26.100
Duration: 00:01:00.29, start: 0.000000, bitrate: 53076 kb/s
Stream #0:0(eng): Video: mpeg2video (4:2:2) (xd5b / 0x62356478), yuv422p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 49997 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : DataHandler
encoder : XDCAM HD422 1080i60 (50 Mb/s)
timecode : 00:00:00;00
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
handler_name : DataHandler
Stream #0:2(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
handler_name : DataHandler
Stream #0:3(eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : DataHandler
timecode : 00:00:00;00
Unsupported codec with id 0 for input stream 3