[libav-api] TimeCode in an MOV file

Michael Kannard Michael.Kannard at encorehollywood.com
Fri Nov 15 23:40:03 CET 2013


So I have been able to add a time code track using LibAV to my MOV file, but it's not really behaving.
The first frame comes up with a time code, but after that, quicktime displays N/A for every frame.

I'm wondering if there is something else I need to set.

AVStream * addTimeCodeStream(AVFormatContext * formatContext)
{

 AVStream * stream;
 AVCodecContext * codecContext;
 codecContext = avcodec_alloc_context3(NULL);
 codecContext->codec_type = AVMEDIA_TYPE_DATA;
 codecContext->codec_id = AV_CODEC_ID_FFMETADATA;
 codecContext->codec_tag = shiftFourCc("tmcd");
 codecContext->thread_count = 1;
 codecContext->flags = CODEC_FLAG_GLOBAL_HEADER;
 codecContext->time_base.den = 23976;
 codecContext->time_base.num = 1000;
 
 stream = avformat_new_stream(formatContext, NULL);
 stream->codec = codecContext;
 
 return stream;

}

timeCodeStream = addTimeCodeStream(formatContext);
 // write the header, this will create the file.
 int headerWrite = avformat_write_header(formatContext, NULL);
 // write the time code
 AVPacket pkt;
 av_new_packet(&pkt, 4);
 int frameStart = 0;
 AV_WB32(pkt.data, frameStart);
 pkt.stream_index = timeCodeStream->index;
 pkt.duration = timeCodeStream->codec->time_base.num;
 pkt.flags = AV_PKT_FLAG_KEY;
 int writeTimeCode = av_write_frame(formatContext, &pkt);
 av_free_packet(&pkt);



Thanks again.


________________________________________
From: libav-api [libav-api-bounces at libav.org] on behalf of libav-api-request at libav.org [libav-api-request at libav.org]
Sent: Friday, November 15, 2013 3:00 AM
To: libav-api at libav.org
Subject: libav-api Digest, Vol 33, Issue 5

Send libav-api mailing list submissions to
        libav-api at libav.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.libav.org/mailman/listinfo/libav-api
or, via email, send a message with subject or body 'help' to
        libav-api-request at libav.org

You can reach the person managing the list at
        libav-api-owner at libav.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of libav-api digest..."


Today's Topics:

   1. Time Code in an MOV (Michael Kannard)
   2. Re: Time Code in an MOV (Luca Barbato)


----------------------------------------------------------------------

Message: 1
Date: Thu, 14 Nov 2013 23:10:52 +0000
From: Michael Kannard <Michael.Kannard at encorehollywood.com>
To: "libav-api at libav.org" <libav-api at libav.org>
Subject: [libav-api] Time Code in an MOV
Message-ID:
        <7AF7C2579AA7444781E7F3AC4E55F96C1B7AD15D at BL2PRD0810MB373.namprd08.prod.outlook.com>

Content-Type: text/plain; charset="iso-8859-1"

Hello, I am new to LibAV.



I am writing an MOV file, and having problems getting time code embedded in the file.

I am currently using the windows binaries.

Everything with the file comes out great, but no time code is available in quick time.



I've seen some code posted that adds a dictionary item of "timecode" to the metadata of the video stream, so I've added it here, but with no success.



Thanks to anyone who has some ideas.



AVStream * addVideoStream(AVFormatContext * formatContext, int width, int height, const char * videoCodec, const char * videoCodecProfile, const char * timeCode)

{

    AVStream * stream;

    AVCodec * codec;

    AVCodecContext * codecContext;

    codec = avcodec_find_encoder(AV_CODEC_ID_PRORES);

    codecContext = avcodec_alloc_context3(codec);

    codecContext->flags = CODEC_FLAG_GLOBAL_HEADER;

    stream = avformat_new_stream(formatContext, codec);

    stream->codec = codecContext;



    int set = av_dict_set(&stream->metadata, "timecode", timeCode, 0);



    codecContext->codec_id = AV_CODEC_ID_PRORES;

    codecContext->channels = 0;

    codecContext->width = width;

    codecContext->height = height;

    codecContext->time_base.den = 23976;

    codecContext->time_base.num = 1000;

    codecContext->codec_tag = getFourCc(videoCodec, videoCodecProfile);

    codecContext->pix_fmt = codec->pix_fmts[0];

    return stream;

}


This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email and any attachments is strictly prohibited. If you receive this email in error, please immediately notify the sender by return email and permanently delete the original, any copy and any printout thereof. The integrity and security of e-mail cannot be guaranteed.



------------------------------

Message: 2
Date: Fri, 15 Nov 2013 00:39:07 +0100
From: Luca Barbato <lu_zero at gentoo.org>
To: libav-api at libav.org
Subject: Re: [libav-api] Time Code in an MOV
Message-ID: <52855F1B.9030008 at gentoo.org>
Content-Type: text/plain; charset=UTF-8

On 15/11/13 00:10, Michael Kannard wrote:
> Hello, I am new to LibAV.
>
>
>
> I am writing an MOV file, and having problems getting time code
> embedded in the file.
>
> I am currently using the windows binaries.
>
> Everything with the file comes out great, but no time code is
> available in quick time.
>
>
>
> I've seen some code posted that adds a dictionary item of "timecode"
> to the metadata of the video stream, so I've added it here, but with
> no success.

Timecode is considered a data stream thus saved and copied accordingly.

Probably could make sense to decode it and use it as metadata.

lu


------------------------------

Subject: Digest Footer

_______________________________________________
libav-api mailing list
libav-api at libav.org
https://lists.libav.org/mailman/listinfo/libav-api

------------------------------

End of libav-api Digest, Vol 33, Issue 5
****************************************
This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email and any attachments is strictly prohibited. If you receive this email in error, please immediately notify the sender by return email and permanently delete the original, any copy and any printout thereof. The integrity and security of e-mail cannot be guaranteed.




More information about the libav-api mailing list