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 [[email protected]] on behalf of 
[email protected] [[email protected]]
Sent: Friday, November 15, 2013 3:00 AM
To: [email protected]
Subject: libav-api Digest, Vol 33, Issue 5

Send libav-api mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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 <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [libav-api] Time Code in an MOV
Message-ID:
        
<7af7c2579aa7444781e7f3ac4e55f96c1b7ad...@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 <[email protected]>
To: [email protected]
Subject: Re: [libav-api] Time Code in an MOV
Message-ID: <[email protected]>
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
[email protected]
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.


_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to