
Recherche avancée
Médias (1)
-
Carte de Schillerkiez
13 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
Autres articles (54)
-
Demande de création d’un canal
12 mars 2010, parEn fonction de la configuration de la plateforme, l’utilisateur peu avoir à sa disposition deux méthodes différentes de demande de création de canal. La première est au moment de son inscription, la seconde, après son inscription en remplissant un formulaire de demande.
Les deux manières demandent les mêmes choses fonctionnent à peu près de la même manière, le futur utilisateur doit remplir une série de champ de formulaire permettant tout d’abord aux administrateurs d’avoir des informations quant à (...) -
Gestion de la ferme
2 mars 2010, parLa ferme est gérée dans son ensemble par des "super admins".
Certains réglages peuvent être fais afin de réguler les besoins des différents canaux.
Dans un premier temps il utilise le plugin "Gestion de mutualisation" -
Support audio et vidéo HTML5
10 avril 2011MediaSPIP 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 (8961)
-
Handling correctly the ffmpeg & ffprobe with php
29 septembre 2014, par coccoHandling correctly the ffmpeg & ffprobe with php
maybe not relevant final goals :
- upload clip with ajax
- get ajax info from
ffprobe
using php as json executingffprobe
once only (noffmpeg
) - handle all calculations with javascript
- maybe an extra php script tool that can create gifs, extract frames(thumbs), or a video grid preview
- when rdy ajax the conversion info to the final php conversion script executing ffmpeg once only (just the final ffmpeg string.).
I’m trying to write my own ffmpeg local web video editor that converts all formats to mp4 automatically. As mp4 is the most compatible container now and the h264+aac/+ac3 is also one of the best compressions. I also want to be able to cut, crop, resize, remove streams, add streams and more. I’m stuck on some simple problems :
1. HOW TO GET THE INFO ?
I’m using ffprobe to get the file information as json with the following command :
ffprobe -v quiet -print_format json -show_format -show_streams -show_packets '.$video
this gives you a lot of information, but some relevant stuff is not always present. I need the duration (in milliseconds),the fps (as a float) and the total frames (as an integer).
i know that these values can sometimes be found inside this array :
format.duration //Total duration
streams[0].duration //Video duration
streams[1].duration //Audio duration
streams[0].avg_frame_rate //Average framerate
streams[0].r_frame_rate //Video framerate
streams[0].nb_frames //Total framesbut most of the time
nb_frames
is missing, alsoavg_frame_rate
differs fromr_frame_rate
, which is also not always available.I know that i could use multiple commands to increase the chance to get the correct values.. but srsly ???
//fps
ffmpeg -i INPUT 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p"
//duration
ffmpeg -i INPUT 2>&1 | awk '/Duration/ {split($2,a,":");print a[1]*3600+a[2]*60+a[3]}'
//frames
ffmpeg -i INPUT -vcodec copy -f rawvideo -y /dev/null 2>&1 | tr ^M '\n' | awk '/^frame=/ {print $2}'|tail -n 1I don’t want to execute ffmpeg 3 times to get this information ; I’d prefer to just use ffprobe.
So... is there an elegant way to get the extra info that is not always present inside the ffprobe output (fps, frames, duration) ???
In the preview i want to be able to jump correctly to a specific frame (NOT TIME). if the above parameters are aviable i can do that using this command.
ffmpeg -i INPUT -vf 'select=gte(n\,FRAMENUMBER)' -vframes 1 -f image2 OUTPUT
using the above command by setting the framenumber to the last frame always returns a black frame.
if there are 50 frames (for example) the range is 1-50 — correct ? Frame 50 is black, frame 1 is ok, frame 0 returns an error...
2. WHILE READING THE LOG HOW TO SKIP ERRORS AND DETERMINE IF THE CONVERSION IS FINISHED ?
I’m able to upload one single video per time (per page) and i can read the current progress from the ffmpeg generated output log until i don’t close the page. more control/multiple conversions would be nice.
i’m reading the last line of the log with a custom tail function but as this is a log that also includes errors i don’t always get a nice line containing the desidered values. btw to check if the progress is complete i check if the last line CONTAINS the WORD
frame
....How can i find out when the conversion progress is finished ?
maybe a way to delete the log with ffmpeg command ??And skip/log the errors ??
i’m using server sent events to read the log...
here is the php code<?php
setlocale(LC_CTYPE, "en_US.UTF-8");
function tailCustom($filepath,$lines=1,$adaptive=true){
// a custom function to get the last line of a textfile.
}
function send($data){
echo "id: ".time().PHP_EOL;
echo "data: ".$data.PHP_EOL;
echo PHP_EOL;
ob_flush();
flush();
}
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
while(true){
send(tailCustom($_GET['log'].".log"));
sleep(1);
}
?>And here the SSE js
function startSSE(fn){
sse=new EventSource("ffmpegProgress.php?log="+encodeURIComponent(fn));
sse.addEventListener('message',conversionProgress,false);
}
function conversionProgress(e){
if(e.data.substr(0,6)=='frame='){
inProgress=true;
var x=e.data.match(/frame=\s*(.*?)\s*fps=\s*(.*?)\s*q=\s*(.*?)\s*size=\s*(.*?)\s*time=\s*(.*?)\s*bitrate=\s*(.*?)\s*$/);
x.shift();x={frame:x[0]*1,fps:x[1]*1,q:x[2],size:x[3],time:x[4],bitrate:x[5]};
var elapsedTime = ((new Date().getTime()) - startTime);
var chunksPerTime = timeString2ms(x.time) / elapsedTime;
var estimatedTotalTime = duration / chunksPerTime;
var timeLeftInSeconds = Math.abs(elapsedTime-(estimatedTotalTime*1000));
var withOneDecimalPlace = Math.round(timeLeftInSeconds * 10) / 10;
conversion.innerHTML='Time Left: '+ms2TimeString(timeLeftInSeconds).split('.')[0]+'<br />'+
'Time Left2: '+(ms2TimeString(((frames-x.frame)/x.fps)*1000)+(timeString2ms(x.time)/(duration*1000)*100|0)).split('.')[0]+'<br />'+
'Estimated Total: '+ms2TimeString(estimatedTotalTime*1000).split('.')[0]+'<br />'+
'Elapsed Time: '+ms2TimeString(elapsedTime).split('.')[0];
}else{
if(inProgress){
sse.removeEventListener('message',conversionProgress,false);
sse.close();
sse=null;
conversion.textContent='Finished in '+ms2TimeString((new Date().getTime()) - startTime).split('.')[0];
//delete log/old file??
inProgress=false;
}
}
}EDIT
HERE IS A SAMPLE OUTPUT after detecting h264 codec in a m2ts with ac3 audio
As most devices can already read h264 i just need to convert the audio in aac and copy the same audio AC3 as second track. and put everything inside a mp4 container. So that i have a Android/chrome/ios & more browsers compatible file.
$opt="-map 0:0 -map 0:1 -map 0:1 -c:v copy -c:a:0 libfdk_aac -metadata:s:a:0 language=ita -b:a 128k -ar 48000 -ac 2 -c:a:1 copy -metadata:s:a:1 language=ita -movflags +faststart";
$i="in.m2ts";
$o="out.mp4";
$t="title";
$y="2014";
$progress="nameoftheLOG.log";
$cmd="ffmpeg -y -i ".escapeshellarg($i)." -metadata title=".$t." -metadata date=".$y." ".$opt." ".$o." null >/dev/null 2>".$progress." &";if you have any questions about the code or want to see more code just ask...
-
Adding h264 frames to mp4 file
5 mars 2024, par DinamoI have raw h264 video frames




Stream #0:0 : Video : h264 (Main), yuvj420p(pc, bt709, progressive),
1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc




and raw audio frames :




Stream #0:0 : Audio : pcm_s16le, 16000 Hz, 1 channels, s16, 256 kb/s




I also have a list of timestamps in microseconds of each frame


600 0xd96533 (audio)
601 0xd9e1dd (audio)
602 0xda4f52 (audio)
603 0xda5a63 (video)
604 0xdacc4b (audio)
605 0xdb39a3 (audio)
606 0xdb5ee9 (video)
607 0xdbb6d8 (audio)
608 0xdc23fe (audio)
609 0xdcb255 (audio)
610 0xdd0e69 (audio)
611 0xdd8b96 (audio)
612 0xdd67d0 (video)
613 0xddf8bd (audio)



note that the timestamp difference between two audio frames is 0.032s or 0.028s (average 0.03s ?)


and the timestamp difference between two video frames is mutiply of 0.06666s (0.0666,0.1333,0.2)


this data was captured from a camera that is capturing at max 15fps according to the spec.


I want to merge them into one mp4 file.


raw video frame info


[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=N/A
pkt_pts_time=N/A
-> pkt_dts=N/A
-> pkt_dts_time=N/A
best_effort_timestamp=N/A
best_effort_timestamp_time=N/A
-> pkt_duration=48000
-> pkt_duration_time=0.040000
pkt_pos=1476573
pkt_size=57677
width=1280
height=720
pix_fmt=yuvj420p
sample_aspect_ratio=N/A
pict_type=I
coded_picture_number=189
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=pc
color_space=bt709
color_primaries=bt709
color_transfer=bt709
chroma_location=left
[/FRAME]
[FRAME]
media_type=video
stream_index=0
key_frame=0
pkt_pts=N/A
pkt_pts_time=N/A
-> pkt_dts=N/A
-> pkt_dts_time=N/A
best_effort_timestamp=N/A
best_effort_timestamp_time=N/A
-> pkt_duration=48000
-> pkt_duration_time=0.040000
pkt_pos=1534250
pkt_size=3928
width=1280
height=720
pix_fmt=yuvj420p
sample_aspect_ratio=N/A
pict_type=P
coded_picture_number=190
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=pc
color_space=bt709
color_primaries=bt709
color_transfer=bt709
chroma_location=left
[/FRAME]



The result frames should have values similar to this :


video frames


[FRAME]
media_type=video
stream_index=0
key_frame=0
pkt_pts=N/A
pkt_pts_time=N/A
-> pkt_dts=500
-> pkt_dts_time=16.666667
best_effort_timestamp=500
best_effort_timestamp_time=16.666667
-> pkt_duration=1
-> pkt_duration_time=0.033333
pkt_pos=1772182
pkt_size=3070
width=1280
height=720
pix_fmt=yuvj420p
sample_aspect_ratio=N/A
pict_type=P
coded_picture_number=191
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=pc
color_space=bt709
color_primaries=bt709
color_transfer=bt709
chroma_location=left
[/FRAME]



pkt_duration_time
is always 0.033333,pkt_dts
maybe even or odd not both (per stream) and alsopkt_dts
almost always jumps by 2, but sometimes by 4

audio frames


[FRAME]
media_type=audio
stream_index=1
key_frame=1
pkt_pts=0
pkt_pts_time=0.000000
pkt_dts=0
pkt_dts_time=0.000000
best_effort_timestamp=0
best_effort_timestamp_time=0.000000
pkt_duration=480
pkt_duration_time=0.030000
pkt_pos=608
pkt_size=960
sample_fmt=s16
nb_samples=480
channels=1
channel_layout=unknown
[/FRAME]
[FRAME]
media_type=audio
stream_index=1
key_frame=1
pkt_pts=480
pkt_pts_time=0.030000
pkt_dts=480
pkt_dts_time=0.030000
best_effort_timestamp=480
best_effort_timestamp_time=0.030000
pkt_duration=480
pkt_duration_time=0.030000
pkt_pos=1654
pkt_size=960
sample_fmt=s16
nb_samples=480
channels=1
channel_layout=unknown
[/FRAME]
[FRAME]
media_type=audio
stream_index=1
key_frame=1
pkt_pts=960
pkt_pts_time=0.060000
pkt_dts=960
pkt_dts_time=0.060000
best_effort_timestamp=960
best_effort_timestamp_time=0.060000
pkt_duration=480
pkt_duration_time=0.030000
pkt_pos=2726
pkt_size=960
sample_fmt=s16
nb_samples=480
channels=1
channel_layout=unknown
[/FRAME]



those are the sequences


//Audio
frame_len=480
pkt_duration_time=0.030000
pkt_pts=frame_len*frame_index
pkt_pts_time=pkt_duration_time*frame_index
pkt_pos=LAST_FRAME_PTS + ~1000 //or timestamp_us/x ?
//Video
pkt_duration_time=0.033333
pkt_dts=(2 or 4)*frame_index
pkt_dts_time=LAST_FRAME_DTS+pkt_duration_time



Here is my current code for adding a video frame :


#include <libavformat></libavformat>avformat.h>
AVFormatContext *format_context;
AVStream *out_stream;

void init_out_stream(){
 out_stream->id = 0;
 out_stream->time_base = (AVRational){1, 30}; //<-------------
 out_stream->codec->codec_id = AV_CODEC_ID_H264;
 out_stream->codec->width = 1280;
 out_stream->codec->height = 720;
 out_stream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
}
int WriteH264VideoSample(unsigned char *sample, unsigned int sample_size, int iskeyframe, unsigned long long int timestamp_us){

 AVPacket packet = { 0 };
 av_init_packet(&packet);

 packet.stream_index = 0;
 packet.data = sample;
 packet.size = sample_size;
 packet.pos = -1;

 timestamp = timestamp_us / 1000; //to ms
 /*pts = last pts + timebase unit (1/30 or 33ms) difference 
 between last and current timestamps*/
 pkt.pts = last_pts + (timestamp - last_timestamp) / 33; 
 last_pts = pkt.pts;
 pkt.dts = pkt.pts;
 last_timestamp = timestamp;
 packet.duration = 0;

 av_packet_rescale_ts(&packet, (AVRational){1, 25}, out_stream->time_base); //<-------------

 if (iskeyframe) {
 packet.flags |= AV_PKT_FLAG_KEY;
 }

 if (av_interleaved_write_frame(format_context, &packet) < 0) {
 printf("Fail to write frame\n");
 return 0;
 }

 //file_duration += duration;

 return 1;
}


int main(){
 avformat_alloc_output_context2(&format_context, 0, "avi", 0);
 out_stream = avformat_new_stream(format_context, 0);
 init_out_stream();

 return 0;
}



However the
pts
i use doesn't sync correctly, with my code sometimes thepts
jumps by 3 and sometimes by 2 each frame however the synced result should jump by 2 or 4. (all even or all odd (per stream))

for the audio i tried


AVPacket packet = { 0 };
av_init_packet(&packet);

packet.stream_index = 1;
packet.data = sample;
pkt.size = 960;
packet.pos = -1;

/* 32000/2 = 16000; 16000/33.33333 = ~480 */
/* 28000/2 = 14000; 14000/33.33333 = ~420 ??*/
timestamp = timestamp_us / 2;
pkt.pts = last_audio_pts + round(timestamp/33.333333333333);
pkt.dts = pkt.pts;
last_audio_pts = pkt.pts;

pkt.duration = 0;

av_packet_rescale_ts(&packet, (AVRational){1, 25}, (AVRational){1, 30});



In this case every frame has the correct info but
pkt_duration
is 240 instead of 480 andpkt_pts_time
jumps by 0.06s instead of 0.03s

What is wrong with my calculation ?
Thanks.


-
Using ffmpeg to generate multiple resolutions with the exact same keyframe positions
2 novembre 2014, par bacon overlordThere are a bunch of resources on how to use ffmpeg to convert X to Y and so forth but I can’t seem to be able to generate different resolutions of the same file with the same keyframe and frame positions.
The keyframe positions are important because they allow the player to jump from one bitrate to another.
These videos are intended for Flash.
I keep on getting results like this from the validation tool.
failed on frame 1670
[FrameInfo 1670, type 9, timecode 23565, seekable 1670]
[FrameInfo 1670, type 9, timecode 23565, seekable 1525]Even worse, sometimes it takes to re-ordering the frames
failed on frame 1
[FrameInfo 1, type 9, timecode 0, seekable 1]
[FrameInfo 1, type 8, timecode 0, seekable -1]When trying to validate the sample videos that are installed with Adobe Flash Media Server they are ok
Comparing files
0: G:\VOD\sample1_150kbps.flv
1: G:\VOD\sample1_500kbps.flv
2: G:\VOD\sample1_700kbps.flv
3: G:\VOD\sample1_1500kbps.flv
Index, Keyframes, and Timecodes are Validated across all filesSample
ffmpeg
command I run at different resolutions. Adobe Media Encoder is also producing video with different keyframe positions so I don’t know whats going on here.ffmpeg -i source.mp4 -vf scale=1270:720 -c:a copy output.flv
ffmpeg 720p
ffmpeg -i .\big_buck_bunny_1080p_surround.avi -vf scale=1280:720 -vcodec libx264 -profile:v main -acodec libvo_aacenc -b:a 128k -ac 2 big_buck_bunny_720.flv
ffmpeg 480p
ffmpeg -i .\big_buck_bunny_1080p_surround.avi -vf scale=854:480 -vcodec libx264 -profile:v main -acodec libvo_aacenc -b:a 128k -ac 2 big_buck_bunny_480.flv
ffmpeg console output
ffmpeg version N-59433-g4aa9c91 Copyright (c) 2000-2013 the FFmpeg developers
built on Dec 29 2013 22:01:53 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfi
g --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopenco
re-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-li
bvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 59.100 / 52. 59.100
libavcodec 55. 47.100 / 55. 47.100
libavformat 55. 22.100 / 55. 22.100
libavdevice 55. 5.102 / 55. 5.102
libavfilter 4. 0.103 / 4. 0.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, avi, from '.\big_buck_bunny_1080p_surround.avi':
Metadata:
encoder : AVI-Mux GUI 1.17.7, Aug 8 2006 20:59:17
JUNK :
Duration: 00:09:56.46, start: 0.000000, bitrate: 12455 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 24 tbr, 24 tb
n, 24 tbc
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
File 'big_buck_bunny_720.flv' already exists. Overwrite ? [y/N] Y
[libx264 @ 029deec0] using SAR=1/1
[libx264 @ 029deec0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 029deec0] profile Main, level 3.1
[libx264 @ 029deec0] 264 - core 140 r2377 1ca7bb9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.or
g/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 m
e_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_thr
eads=2 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=24 scenecut=40 intra_refresh=0 rc_lookahead=40 r
c=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, flv, to 'big_buck_bunny_720.flv':
Metadata:
JUNK :
encoder : Lavf55.22.100
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 1k tbn, 2
4 tbc
Stream #0:1: Audio: aac (libvo_aacenc) ([10][0][0][0] / 0x000A), 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 -> libx264)
Stream #0:1 -> #0:1 (ac3 -> libvo_aacenc)
Press [q] to stop, [?] for help
frame=14315 fps= 73 q=-1.0 Lsize= 120952kB time=00:09:56.49 bitrate=1661.1kbits/s
video:110887kB audio:9321kB subtitle:0 global headers:0kB muxing overhead 0.619082%
[libx264 @ 029deec0] frame I:151 Avg QP:17.09 size:115286
[libx264 @ 029deec0] frame P:5374 Avg QP:21.41 size: 14154
[libx264 @ 029deec0] frame B:8790 Avg QP:25.91 size: 2284
[libx264 @ 029deec0] consecutive B-frames: 11.5% 15.5% 13.3% 59.7%
[libx264 @ 029deec0] mb I I16..4: 24.0% 0.0% 76.0%
[libx264 @ 029deec0] mb P I16..4: 4.0% 0.0% 3.5% P16..4: 29.3% 11.1% 7.1% 0.0% 0.0% skip:45.1%
[libx264 @ 029deec0] mb B I16..4: 0.2% 0.0% 0.4% B16..8: 22.4% 1.7% 0.4% direct: 0.8% skip:74.1% L0:37.5% L1:5
8.0% BI: 4.5%
[libx264 @ 029deec0] coded y,uvDC,uvAC intra: 51.5% 64.4% 37.6% inter: 7.3% 10.1% 1.3%
[libx264 @ 029deec0] i16 v,h,dc,p: 40% 23% 9% 28%
[libx264 @ 029deec0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 18% 15% 7% 8% 10% 7% 7% 6%
[libx264 @ 029deec0] i8c dc,h,v,p: 51% 21% 17% 10%
[libx264 @ 029deec0] Weighted P-Frames: Y:5.9% UV:3.6%
[libx264 @ 029deec0] ref P L0: 62.4% 16.9% 15.2% 5.3% 0.1%
[libx264 @ 029deec0] ref B L0: 89.3% 9.1% 1.7%
[libx264 @ 029deec0] ref B L1: 94.3% 5.7%
[libx264 @ 029deec0] kb/s:1522.96Validation Results
Comparing files
0: G:\VOD\big_buck_bunny_480.flv
1: G:\VOD\big_buck_bunny_720.flv
>> Comparison failed on frame 13181
0: [FrameInfo 13181, type 9, timecode 185958, seekable 12794]
1: [FrameInfo 13181, type 9, timecode 185958, seekable 13181]