|
186 | 186 | [id id])) |
187 | 187 | (match* (type mode) |
188 | 188 | [('video 'init) |
| 189 | + ;; Writing output |
189 | 190 | (set-avcodec-context-codec-id! ctx id) |
190 | 191 | (set-avcodec-context-bit-rate! ctx 400000) |
191 | 192 | (set-avcodec-context-width! ctx 1280);1920) |
|
198 | 199 | (when (eq? id 'mpeg2video) |
199 | 200 | (set-avcodec-context-max-b-frames! ctx 2)) |
200 | 201 | (when (eq? id 'mpeg1video) |
201 | | - (set-avcodec-context-mb-decision! ctx 2))] |
| 202 | + (set-avcodec-context-mb-decision! ctx 2)) |
| 203 | + |
| 204 | + ;; Displaying output |
| 205 | + (set! num-bytes |
| 206 | + (av-image-get-buffer-size'rgb24 |
| 207 | + (avcodec-context-width ctx) |
| 208 | + (avcodec-context-height ctx) |
| 209 | + 32)) |
| 210 | + (set! buff (av-malloc num-bytes _uint8)) |
| 211 | + (av-image-fill-arrays (av-frame-data frame-rgb) |
| 212 | + (av-frame-linesize frame-rgb) |
| 213 | + (array-ptr buff) |
| 214 | + 'rgb24 |
| 215 | + (avcodec-context-width ctx) |
| 216 | + (avcodec-context-height ctx) |
| 217 | + 1) |
| 218 | + (set! sws |
| 219 | + (sws-getContext (avcodec-context-width ctx) |
| 220 | + (avcodec-context-height ctx) |
| 221 | + (avcodec-context-pix-fmt ctx) |
| 222 | + (avcodec-context-width ctx) |
| 223 | + (avcodec-context-height ctx) |
| 224 | + 'rgb24 |
| 225 | + SWS-BILINEAR |
| 226 | + #f #f #f)) |
| 227 | + (set! f (new frame% |
| 228 | + [label "Movie"] |
| 229 | + [width (avcodec-context-width ctx)] |
| 230 | + [height (avcodec-context-height ctx)])) |
| 231 | + (set! c (new video-canvas% |
| 232 | + [width (avcodec-context-width ctx)] |
| 233 | + [height (avcodec-context-height ctx)] |
| 234 | + [parent f])) |
| 235 | + (send f show #t)] |
202 | 236 | [('audio 'init) |
203 | 237 | (set-avcodec-context-sample-fmt! |
204 | 238 | ctx (if (avcodec-sample-fmts codec) |
|
234 | 268 | ctx (av-get-channel-layout-nb-channels (avcodec-context-channel-layout ctx))) |
235 | 269 | (set-avstream-time-base! stream (/ 1 (avcodec-context-sample-rate ctx)))] |
236 | 270 | [('video 'write) |
| 271 | + ;(define codec-context ctx) |
| 272 | + (define old-obj (queue-callback-data-codec-obj (codec-obj-callback-data obj))) |
| 273 | + (define codec-context (codec-obj-codec-context old-obj)) |
| 274 | + (define packet data) |
| 275 | + ;; Display output |
| 276 | + (with-handlers ([exn:ffmpeg:again? void] |
| 277 | + [exn:ffmpeg:eof? void]) |
| 278 | + (avcodec-send-packet codec-context packet) |
| 279 | + (avcodec-receive-frame codec-context frame) |
| 280 | + (sws-scale sws |
| 281 | + (array-ptr (av-frame-data frame)) |
| 282 | + (array-ptr (av-frame-linesize frame)) |
| 283 | + 0 |
| 284 | + (avcodec-context-height codec-context) |
| 285 | + (array-ptr (av-frame-data frame-rgb)) |
| 286 | + (array-ptr (av-frame-linesize frame-rgb))) |
| 287 | + (define linesize (array-ref (av-frame-linesize frame-rgb) 0)) |
| 288 | + (send c draw-frame |
| 289 | + (λ () |
| 290 | + (for ([i (in-range (avcodec-context-height codec-context))]) |
| 291 | + (glTexSubImage2D |
| 292 | + GL_TEXTURE_2D |
| 293 | + 0 |
| 294 | + 0 |
| 295 | + i |
| 296 | + (avcodec-context-width codec-context) |
| 297 | + 1 |
| 298 | + GL_RGB |
| 299 | + GL_UNSIGNED_BYTE |
| 300 | + (ptr-add (array-ref (av-frame-data frame-rgb) 0) |
| 301 | + (* i linesize))))))) |
| 302 | + ;; Write output |
237 | 303 | data] |
238 | 304 | #; |
239 | 305 | [('audio 'write) |
|
243 | 309 |
|
244 | 310 | (define in-bundle (file->stream-bundle "/Users/leif/demo2.mp4")) |
245 | 311 | (demux-stream in-bundle |
| 312 | + #:close-context? #f |
246 | 313 | #:by-index-callback (queue-stream)) |
247 | 314 | (define out-bundle (bundle-for-file "/Users/leif/test.mp4" |
248 | 315 | in-bundle)) |
|
0 commit comments