
Recherche avancée
Médias (1)
-
Publier une image simplement
13 avril 2011, par ,
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (93)
-
Gestion générale des documents
13 mai 2011, parMédiaSPIP ne modifie jamais le document original mis en ligne.
Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...) -
Use, discuss, criticize
13 avril 2011, parTalk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
A discussion list is available for all exchanges between users. -
Les images
15 mai 2013
Sur d’autres sites (15267)
-
How can I extract PGS/SUP subtitles from mkv container via libav
24 août 2024, par EliaTrying to write a C code that does the equivalent of the following ffmpeg command :


ffmpeg -i video.mkv -map 0:"$STREAM_INDEX" -c:s copy subtitles.sup



I have managed to read the media container, locate the subtitle streams, and filter the relevant one based on stream metadata. However I only succeeded in getting the bitmap data, without the full PGS header and sections.


Tried dumping
packet->data
to a file hoping it includes full sections, but the data doesn't start with the expected PGS magic header 0x5047.

Also usingavcodec_decode_subtitle2
doesn't seem to be useful as it only gives bitmap data without the full PGS header and sections.

What steps are supposed to happen after finding the relevant subtitle stream that allows extracting it as raw data that exactly matches the output of the ffmpeg command above ?


Some sample code :


while(av_read_frame(container_ctx, packet) == 0) {
 if(packet->stream_index != i) {
 continue;
 }

 // Try 1 - dump packet data to file
 fwrite(packet->data, 1, packet->size, fout);

 // Try 2 - decode subtitles
 int bytes_read = 0, success = 0;
 AVSubtitle sub;

 if ((bytes_read = avcodec_decode_subtitle2(codec_context, &sub, &success, packet)) < 0) {
 fprintf(stderr, "Failed to decode subtitles %s", av_err2str(bytes_read));
 goto end;
 }
 fprintf(stdout, "Success! Status:%d - BytesRead:%d NumRects:%d\n", success, bytes_read, sub.num_rects);

 if (success) {
 // Only managed to extract bitmap data here via sub.rects
 }

 av_packet_unref(packet);
 }



-
c++, ffmpeg tanscoding : time_base differs depending on the container
1er mai 2022, par prostractionI transcode video (mkv and mp4). When mkv transcoded to mkv, output is fine (output video fps and duration are same as input), but if mkv transcoded to mp4, output fps is less than input 2 times and duration of output video is more than input 2 times.


I transcode only video, audio writing as decoded packet from input file.


Video stream and context created like this :


out_stream = avformat_new_stream(ofmt_ctx, NULL);
avcodec_parameters_copy(out_stream->codecpar, in_codecpar);
out_stream->codecpar->codec_tag = 0;
codec_encode = avcodec_find_encoder(out_stream->codecpar->codec_id);
context_encode = avcodec_alloc_context3(codec_encode);
context_encode->width = width;
context_encode->height = height;
context_encode->pix_fmt = codec_encode->pix_fmts[0];
context_encode->time_base = av_inv_q(in_stream->r_frame_rate);
out_stream->time_base = context_encode->time_base;
out_stream->r_frame_rate = in_stream->r_frame_rate;



Transcoding (simplified) :


int64_t i = 0; 
 while (true) {
 av_read_frame(ifmt_ctx, pkt);
 in_stream = ifmt_ctx->streams[pkt->stream_index];
 pkt->stream_index = stream_mapping[pkt->stream_index];
 pCodecCtx = ifmt_ctx->streams[pkt->stream_index]->codec;
 pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
 error = avcodec_open2(pCodecCtx, pCodec, nullptr);
 if (pkt->stream_index == AVMEDIA_TYPE_VIDEO) {
 ....
 avcodec_decode_video2(pCodecCtx, frame, &frameFinished, pkt);
 ....
 // manipulate with frame
 ....
 frame->pts = i;
 avcodec_send_frame(context_encode, frame);
 while ((ret = avcodec_receive_packet(context_encode, pkt_encode)) >= 0) {
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 break;
 av_packet_rescale_ts(pkt_encode, context_encode->time_base, out_stream->time_base);
 av_interleaved_write_frame(ofmt_ctx, pkt_encode);
 av_packet_unref(pkt_encode);
 }
 i++;
 }
 else {
 av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
 av_interleaved_write_frame(ofmt_ctx, pkt);
 }
 av_packet_unref(pkt);
 }



Mediainfo of output mkv transcoded video (mkv -> mkv) :


- 

- Frame rate : 23.976 (24000/1001) FPS




Mediainfo of output mp4 transcoded video (mkv -> mp4) :


- 

- Frame rate : 11.988 (12000/1001) FPS
- Original frame rate : 23.976 (24000/1001) FPS






When video context created, time_base values are (mkv -> mp4 and mkv -> mkv) :


FPS input: (24000/1001)
FPS output: (24000/1001)
context_decode->time_base (1001 / 48000)
context_encode->time_base (1001 / 24000)
in_stream->time_base (1 / 1000)
in_stream->codec->time_base (1001 / 48000)
out_stream->time_base (1001 / 24000)
out_stream->codec->time_base (0 / 1)



When video frame is writing, time_base values are (mkv -> mp4) :


context_encode->time_base (1001 / 24000)
out_stream->time_base (1 / 48000)



But if mkv->mkv :


context_encode->time_base (1001 / 24000) 
out_stream->time_base (1 / 1000)



ffmpeg av_dump :


Input #0, matroska,webm, from '24fps2.mkv':
 - Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
 - Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (default)

Output #0, mp4, to 'temp_read.mp4':
 - Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 tbr, 23.98 tbn
 - Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp



But if I manually set time_base to be equal to FPS/2 of input video :


AVRational temp;
temp.num = 500;
temp.den = 24001;
context_encode->time_base = temp;
out_stream->time_base = context_encode->time_base;
out_stream->r_frame_rate = in_stream->r_frame_rate;



When video stream and context created, time_base values are (mkv -> mp4) :


context_encode->time_base (500 / 24001)
out_stream->time_base (500 / 24001)



When video frame is writing, time_base values are (mkv -> mp4) :


context_encode->time_base (500 / 24001)
out_stream->time_base (1 / 48000)



And video FPS and duration is correct :


- 

- Frame rate : 23.976 (24000/1001) FPS




What is wrong with time_base and av_packet_rescale in this case and how it could be fixed ?


-
What is different between h.265/HEVC in a container(mp4, mkv....) and h.265/HEVC Annex B raw file ?
22 juillet 2018, par Adam EstelWhat is different between h.264/HEVC in a container (mp4, mkv....) and h.265/HEVC Annex B raw file ? I mean about codec, pixel formats and why can’t hevc Annex B contain audio stream ?
I researched google for a while but I couldn’t understand it fully yet.