Views
No views yet
1conda create -n timechatcap python=3.12
2conda activate timechatcap
3pip install torch torchvision
4pip install transformers==4.57.1
5pip install accelerate
6pip install flash-attn --no-build-isolation
7# It's highly recommended to use `[decord]` feature for faster video loading.
8pip install qwen-omni-utils[decord] -UNote: To annotate high-quality timestamps and captions, limit video input to around 1 minute. Please segment longer videos into around 60-second clips before processing.
1import torch
2from transformers import Qwen2_5OmniForConditionalGeneration, Qwen2_5OmniProcessor
3from qwen_omni_utils import process_mm_info
4
5# 1. Configuration
6MODEL_ID = "yaolily/TimeChat-Captioner-GRPO-7B"
7VIDEO_PATH = "example_video.mp4" # <--- Replace with your video path
8
9MAX_PIXELS = 297920
10VIDEO_MAX_PIXELS = 297920
11
12
13print(f"🚀 Processing video: {VIDEO_PATH}")
14
15# 2. Load Model & Processor
16print("⏳ Loading model...")
17model = Qwen2_5OmniForConditionalGeneration.from_pretrained(
18 MODEL_ID,
19 torch_dtype=torch.bfloat16,
20 device_map="cuda",
21 attn_implementation="flash_attention_2"
22)
23processor = Qwen2_5OmniProcessor.from_pretrained(MODEL_ID)
24model.disable_talker()
25
26# 3. Construct Conversation
27# The prompt encourages detailed, time-aware audio-visual description.
28conversation = [
29 {
30 "role": "user",
31 "content": [
32 {
33 "type": "text",
34 "text": "Thoroughly describe everything in the video, capturing every detail. Include as much information from the audio as possible, and ensure that the descriptions of both audio and video are well-coordinated."
35 },
36 {
37 "type": "video",
38 "video": VIDEO_PATH,
39 "max_pixels": MAX_PIXELS,
40 "max_frames": 160,
41 "fps": 2.0,
42 "video_max_pixels": VIDEO_MAX_PIXELS
43 }
44 ],
45 },
46]
47
48# 4. Process Inputs
49print("⚙️ Processing inputs...")
50text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
51
52audios, images, videos = process_mm_info(conversation, use_audio_in_video=True)
53
54inputs = processor(
55 text=text,
56 audio=audios,
57 images=images,
58 videos=videos,
59 return_tensors="pt",
60 padding=True,
61 use_audio_in_video=True
62)
63inputs = inputs.to(model.device).to(model.dtype)
64
65# 5. Generate Description
66print("✨ Generating description...")
67with torch.inference_mode():
68 text_ids = model.generate(
69 **inputs,
70 use_audio_in_video=True,
71 return_audio=False,
72 thinker_max_new_tokens=9216,
73 talker_max_tokens=9216
74 )
75
76response = processor.decode(text_ids[0][inputs.input_ids[0].size(0):], skip_special_tokens=True)
77
78print("
79" + "="*50)
80print("🎬 VIDEO DESCRIPTION:")
81print("="*50)
82print(response)
83print("="*50)1@misc{yao2026timechatcaptioner,
2 title={TimeChat-Captioner: Scripting Multi-Scene Videos with Time-Aware and Structural Audio-Visual Captions},
3 author={Linli Yao and Yuancheng Wei and Yaojie Zhang and Lei Li and Xinlong Chen and Feifan Song and Ziyue Wang and Kun Ouyang and Yuanxin Liu and Lingpeng Kong and Qi Liu and Pengfei Wan and Kun Gai and Yuanxing Zhang and Xu Sun},
4 year={2026},
5 eprint={2602.08711},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2602.08711}
9}