From: aybe aybe <aybe.one-at-hotmail.com@ffmpeg.org> To: "ffmpeg-devel@ffmpeg.org" <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 1/2] avformat/psxstr: infer video FPS using sector LBA Date: Tue, 16 Jan 2024 14:36:24 +0000 Message-ID: <PAVPR08MB9795D2C5FEDFD31CBD640AFF9A732@PAVPR08MB9795.eurprd08.prod.outlook.com> (raw) Signed-off-by: aybe <aybe@users.noreply.github.com> --- libavformat/psxstr.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c index 306a690f52..c718fb6daf 100644 --- a/libavformat/psxstr.c +++ b/libavformat/psxstr.c @@ -65,6 +65,9 @@ typedef struct StrDemuxContext { /* a STR file can contain up to 32 channels of data */ StrChannel channels[32]; + + /* the index for the first frame (sector, LBA units)*/ + int64_t first_frame_index; } StrDemuxContext; static const uint8_t sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00}; @@ -150,18 +153,51 @@ static int str_read_header(AVFormatContext *s) str->channels[i].audio_stream_index= -1; } + str->first_frame_index = 0; + s->ctx_flags |= AVFMTCTX_NOHEADER; return 0; } +static uint8_t bcd_to_dec(uint8_t bcd) +{ + uint8_t dec = (bcd & 0xF) + (((bcd >> 4) & 0xF) * 10); + + return dec; +} + +static int32_t msf_to_lba(uint8_t m, uint8_t s, uint8_t f) +{ + int32_t lba = 0; /* int because it can be negative! */ + + m = bcd_to_dec(m); + s = bcd_to_dec(s); + f = bcd_to_dec(f); + + lba = (((m * 60 + s) * 75) + f) - 150; + + return lba; +} + +static int32_t str_get_frame_lba(uint8_t sector[2352]) +{ + uint8_t m = sector[0xC]; + uint8_t s = sector[0xD]; + uint8_t f = sector[0xE]; + + int32_t lba = msf_to_lba(m, s, f); + + return lba; +} + static int str_read_packet(AVFormatContext *s, AVPacket *ret_pkt) { AVIOContext *pb = s->pb; StrDemuxContext *str = s->priv_data; unsigned char sector[RAW_CD_SECTOR_SIZE]; - int channel, ret; + int channel, ret, frame_lba; AVPacket *pkt; AVStream *st; @@ -200,10 +236,12 @@ static int str_read_packet(AVFormatContext *s, st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - avpriv_set_pts_info(st, 64, 1, 15); + avpriv_set_pts_info(st, 64, 1, 150); /* 150 sectors at 2x speed */ str->channels[channel].video_stream_index = st->index; + str->first_frame_index = str_get_frame_lba(sector); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MDEC; st->codecpar->codec_tag = 0; /* no fourcc */ @@ -223,6 +261,8 @@ static int str_read_packet(AVFormatContext *s, return ret; memset(pkt->data, 0, sector_count*VIDEO_DATA_CHUNK_SIZE); + frame_lba = str_get_frame_lba(sector); + pkt->pts = frame_lba - str->first_frame_index; pkt->pos= avio_tell(pb) - RAW_CD_SECTOR_SIZE; pkt->stream_index = str->channels[channel].video_stream_index; -- 2.41.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2024-01-16 14:36 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=PAVPR08MB9795D2C5FEDFD31CBD640AFF9A732@PAVPR08MB9795.eurprd08.prod.outlook.com \ --to=aybe.one-at-hotmail.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git